libcouchbase 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.gitmodules +3 -0
- data/.rspec +1 -0
- data/.travis.yml +35 -0
- data/Gemfile +4 -0
- data/LICENSE +24 -0
- data/README.md +389 -0
- data/Rakefile +75 -0
- data/ext/README.md +6 -0
- data/ext/Rakefile +20 -0
- data/ext/libcouchbase/.gitignore +130 -0
- data/ext/libcouchbase/.travis.yml +19 -0
- data/ext/libcouchbase/CMakeLists.txt +429 -0
- data/ext/libcouchbase/CONTRIBUTING.md +124 -0
- data/ext/libcouchbase/LICENSE +202 -0
- data/ext/libcouchbase/README.markdown +163 -0
- data/ext/libcouchbase/RELEASE_NOTES.markdown +2691 -0
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +27 -0
- data/ext/libcouchbase/cmake/Modules/CopyPDB.cmake +42 -0
- data/ext/libcouchbase/cmake/Modules/DistScript.cmake +17 -0
- data/ext/libcouchbase/cmake/Modules/DownloadLcbDep.cmake +20 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseHdrHistogram.cmake +15 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibev.cmake +73 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibevent.cmake +52 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibuv.cmake +56 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseSnappy.cmake +11 -0
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +29 -0
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +133 -0
- data/ext/libcouchbase/cmake/Modules/GetPlatformCCInfo.cmake +45 -0
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +70 -0
- data/ext/libcouchbase/cmake/config-cmake.h.in +60 -0
- data/ext/libcouchbase/cmake/configure +357 -0
- data/ext/libcouchbase/cmake/defs.mk.in +8 -0
- data/ext/libcouchbase/cmake/dtrace-instr-link.pl +38 -0
- data/ext/libcouchbase/cmake/source_files.cmake +73 -0
- data/ext/libcouchbase/configure.pl +1 -0
- data/ext/libcouchbase/contrib/cJSON/cJSON.c +624 -0
- data/ext/libcouchbase/contrib/cJSON/cJSON.h +158 -0
- data/ext/libcouchbase/contrib/cbsasl/CMakeLists.txt +9 -0
- data/ext/libcouchbase/contrib/cbsasl/COPYING +202 -0
- data/ext/libcouchbase/contrib/cbsasl/include/cbsasl/cbsasl.h +217 -0
- data/ext/libcouchbase/contrib/cbsasl/src/client.c +205 -0
- data/ext/libcouchbase/contrib/cbsasl/src/common.c +46 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.c +67 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.h +33 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.c +296 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.h +45 -0
- data/ext/libcouchbase/contrib/cbsasl/src/hash.c +573 -0
- data/ext/libcouchbase/contrib/cbsasl/src/hash.h +15 -0
- data/ext/libcouchbase/contrib/cbsasl/src/util.h +31 -0
- data/ext/libcouchbase/contrib/cliopts/CMakeLists.txt +2 -0
- data/ext/libcouchbase/contrib/cliopts/cliopts.c +747 -0
- data/ext/libcouchbase/contrib/cliopts/cliopts.h +493 -0
- data/ext/libcouchbase/contrib/genhash/genhash.c +372 -0
- data/ext/libcouchbase/contrib/genhash/genhash.h +235 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/CHANGES +157 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/CMakeLists.txt +252 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/CONTRIBUTORS +37 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/LICENSE +28 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/MINIFY.sh +15 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/README +435 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/cmake/internal_utils.cmake +227 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-death-test.h +294 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-message.h +250 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h +1421 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h.pump +487 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-printers.h +855 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-spi.h +232 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-test-part.h +179 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-typed-test.h +259 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest.h +2291 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_pred_impl.h +358 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_prod.h +58 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-death-test-internal.h +319 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-filepath.h +206 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-internal.h +1158 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-linked_ptr.h +233 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h +5143 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h.pump +301 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util.h +619 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-port.h +1947 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-string.h +167 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h +1012 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h.pump +339 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h +3331 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h.pump +297 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-all.cc +48 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-death-test.cc +1344 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-filepath.cc +382 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-internal-inl.h +1218 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-port.cc +805 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-printers.cc +363 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-test-part.cc +110 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-typed-test.cc +110 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest.cc +5015 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest_main.cc +38 -0
- data/ext/libcouchbase/contrib/http_parser/LICENSE-MIT +23 -0
- data/ext/libcouchbase/contrib/http_parser/README.md +178 -0
- data/ext/libcouchbase/contrib/http_parser/http_parser.c +2060 -0
- data/ext/libcouchbase/contrib/http_parser/http_parser.h +321 -0
- data/ext/libcouchbase/contrib/jsonsl/LICENSE +20 -0
- data/ext/libcouchbase/contrib/jsonsl/jsonsl.c +1452 -0
- data/ext/libcouchbase/contrib/jsonsl/jsonsl.h +971 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/CMakeLists.txt +6 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/LICENSE +55 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp-forwards.h +255 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +4892 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.h +1961 -0
- data/ext/libcouchbase/contrib/snappy/CMakeLists.txt +8 -0
- data/ext/libcouchbase/contrib/snappy/COPYING +28 -0
- data/ext/libcouchbase/contrib/snappy/snappy-c.cc +90 -0
- data/ext/libcouchbase/contrib/snappy/snappy-c.h +138 -0
- data/ext/libcouchbase/contrib/snappy/snappy-internal.h +150 -0
- data/ext/libcouchbase/contrib/snappy/snappy-lcb-msvc.h +5 -0
- data/ext/libcouchbase/contrib/snappy/snappy-sinksource.cc +71 -0
- data/ext/libcouchbase/contrib/snappy/snappy-sinksource.h +137 -0
- data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.cc +42 -0
- data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.h +491 -0
- data/ext/libcouchbase/contrib/snappy/snappy-stubs-public.h +98 -0
- data/ext/libcouchbase/contrib/snappy/snappy.cc +1307 -0
- data/ext/libcouchbase/contrib/snappy/snappy.h +184 -0
- data/ext/libcouchbase/contrib/win32-defs/iocpdefs.h +133 -0
- data/ext/libcouchbase/contrib/win32-defs/mingwdefs.h +4396 -0
- data/ext/libcouchbase/contrib/win32-defs/win_stdint.h +258 -0
- data/ext/libcouchbase/example/CMakeLists.txt +37 -0
- data/ext/libcouchbase/example/README.markdown +47 -0
- data/ext/libcouchbase/example/db/db.c +167 -0
- data/ext/libcouchbase/example/db/vb.c +227 -0
- data/ext/libcouchbase/example/instancepool/main.cc +102 -0
- data/ext/libcouchbase/example/instancepool/pool.cc +102 -0
- data/ext/libcouchbase/example/instancepool/pool.h +69 -0
- data/ext/libcouchbase/example/libeventdirect/main.c +148 -0
- data/ext/libcouchbase/example/mcc/mcc.cc +246 -0
- data/ext/libcouchbase/example/minimal/minimal.c +130 -0
- data/ext/libcouchbase/example/observe/observe.c +146 -0
- data/ext/libcouchbase/example/subdoc/subdoc-multi.cc +132 -0
- data/ext/libcouchbase/example/subdoc/subdoc-simple.cc +191 -0
- data/ext/libcouchbase/example/tick/tick.c +119 -0
- data/ext/libcouchbase/example/views/views-example.cc +83 -0
- data/ext/libcouchbase/include/libcouchbase/_cxxwrap.h +150 -0
- data/ext/libcouchbase/include/libcouchbase/api-legacy.h +1689 -0
- data/ext/libcouchbase/include/libcouchbase/api3.h +2 -0
- data/ext/libcouchbase/include/libcouchbase/assert.h +44 -0
- data/ext/libcouchbase/include/libcouchbase/cbft.h +109 -0
- data/ext/libcouchbase/include/libcouchbase/cntl-private.h +356 -0
- data/ext/libcouchbase/include/libcouchbase/cntl.h +937 -0
- data/ext/libcouchbase/include/libcouchbase/configuration.h.in +23 -0
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +3677 -0
- data/ext/libcouchbase/include/libcouchbase/deprecated.h +300 -0
- data/ext/libcouchbase/include/libcouchbase/error.h +595 -0
- data/ext/libcouchbase/include/libcouchbase/http.h +1 -0
- data/ext/libcouchbase/include/libcouchbase/iops.h +1050 -0
- data/ext/libcouchbase/include/libcouchbase/ixmgmt.h +263 -0
- data/ext/libcouchbase/include/libcouchbase/kvbuf.h +132 -0
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +364 -0
- data/ext/libcouchbase/include/libcouchbase/pktfwd.h +270 -0
- data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +367 -0
- data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr-inl.c +76 -0
- data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr.h +199 -0
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +312 -0
- data/ext/libcouchbase/include/libcouchbase/sysdefs.h +98 -0
- data/ext/libcouchbase/include/libcouchbase/vbucket.h +643 -0
- data/ext/libcouchbase/include/libcouchbase/views.h +298 -0
- data/ext/libcouchbase/include/libcouchbase/visibility.h +65 -0
- data/ext/libcouchbase/include/memcached/COPYING +30 -0
- data/ext/libcouchbase/include/memcached/README +10 -0
- data/ext/libcouchbase/include/memcached/protocol_binary.h +1916 -0
- data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
- data/ext/libcouchbase/packaging/README +7 -0
- data/ext/libcouchbase/packaging/abicheck/.gitignore +4 -0
- data/ext/libcouchbase/packaging/abicheck/Makefile +17 -0
- data/ext/libcouchbase/packaging/abicheck/README.md +27 -0
- data/ext/libcouchbase/packaging/abicheck/template.xml +3 -0
- data/ext/libcouchbase/packaging/deb/compat +1 -0
- data/ext/libcouchbase/packaging/deb/control +73 -0
- data/ext/libcouchbase/packaging/deb/copyright +10 -0
- data/ext/libcouchbase/packaging/deb/libcouchbase-dev.docs +3 -0
- data/ext/libcouchbase/packaging/deb/package.mk +31 -0
- data/ext/libcouchbase/packaging/deb/rules +46 -0
- data/ext/libcouchbase/packaging/deb/source/format +1 -0
- data/ext/libcouchbase/packaging/distinfo/README +1 -0
- data/ext/libcouchbase/packaging/distinfo/distinfo.cmake.in +4 -0
- data/ext/libcouchbase/packaging/dllversion.rc.in +39 -0
- data/ext/libcouchbase/packaging/libcouchbase.pc.in +10 -0
- data/ext/libcouchbase/packaging/nuget/libcouchbase.autopkg +76 -0
- data/ext/libcouchbase/packaging/parse-git-describe.pl +166 -0
- data/ext/libcouchbase/packaging/rpm/libcouchbase.spec.in +108 -0
- data/ext/libcouchbase/packaging/rpm/package.mk +40 -0
- data/ext/libcouchbase/plugins/io/iocp/CMakeLists.txt +9 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_iops.c +466 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_iops.h +217 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_loop.c +295 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_timer.c +79 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_util.c +229 -0
- data/ext/libcouchbase/plugins/io/libev/CMakeLists.txt +29 -0
- data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +65 -0
- data/ext/libcouchbase/plugins/io/libev/plugin-libev.c +289 -0
- data/ext/libcouchbase/plugins/io/libevent/CMakeLists.txt +29 -0
- data/ext/libcouchbase/plugins/io/libevent/libevent_io_opts.h +67 -0
- data/ext/libcouchbase/plugins/io/libevent/plugin-libevent.c +292 -0
- data/ext/libcouchbase/plugins/io/libuv/CMakeLists.txt +42 -0
- data/ext/libcouchbase/plugins/io/libuv/libuv_compat.h +212 -0
- data/ext/libcouchbase/plugins/io/libuv/libuv_io_opts.h +118 -0
- data/ext/libcouchbase/plugins/io/libuv/plugin-internal.h +148 -0
- data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +648 -0
- data/ext/libcouchbase/plugins/io/select/CMakeLists.txt +11 -0
- data/ext/libcouchbase/plugins/io/select/plugin-select.c +448 -0
- data/ext/libcouchbase/plugins/io/select/select_io_opts.h +39 -0
- data/ext/libcouchbase/src/README.md +103 -0
- data/ext/libcouchbase/src/aspend.h +106 -0
- data/ext/libcouchbase/src/auth.cc +74 -0
- data/ext/libcouchbase/src/auth.h +54 -0
- data/ext/libcouchbase/src/bootstrap.c +269 -0
- data/ext/libcouchbase/src/bootstrap.h +129 -0
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.c +495 -0
- data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +82 -0
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +681 -0
- data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
- data/ext/libcouchbase/src/callbacks.c +378 -0
- data/ext/libcouchbase/src/cbft.cc +210 -0
- data/ext/libcouchbase/src/cntl.cc +847 -0
- data/ext/libcouchbase/src/config_static.h +159 -0
- data/ext/libcouchbase/src/connspec.cc +462 -0
- data/ext/libcouchbase/src/connspec.h +105 -0
- data/ext/libcouchbase/src/ctx-log-inl.h +27 -0
- data/ext/libcouchbase/src/dump.c +98 -0
- data/ext/libcouchbase/src/getconfig.c +100 -0
- data/ext/libcouchbase/src/gethrtime.c +109 -0
- data/ext/libcouchbase/src/handler.c +922 -0
- data/ext/libcouchbase/src/hashset.c +164 -0
- data/ext/libcouchbase/src/hashset.h +86 -0
- data/ext/libcouchbase/src/hashtable.c +75 -0
- data/ext/libcouchbase/src/hdr_timings.c +92 -0
- data/ext/libcouchbase/src/hostlist.cc +301 -0
- data/ext/libcouchbase/src/hostlist.h +171 -0
- data/ext/libcouchbase/src/http/http-priv.h +307 -0
- data/ext/libcouchbase/src/http/http.cc +633 -0
- data/ext/libcouchbase/src/http/http.h +34 -0
- data/ext/libcouchbase/src/http/http_io.cc +307 -0
- data/ext/libcouchbase/src/instance.cc +722 -0
- data/ext/libcouchbase/src/internal.h +244 -0
- data/ext/libcouchbase/src/iofactory.c +575 -0
- data/ext/libcouchbase/src/jsparse/parser.cc +519 -0
- data/ext/libcouchbase/src/jsparse/parser.h +173 -0
- data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
- data/ext/libcouchbase/src/lcbht/lcbht.h +199 -0
- data/ext/libcouchbase/src/lcbio/connect.c +557 -0
- data/ext/libcouchbase/src/lcbio/connect.h +364 -0
- data/ext/libcouchbase/src/lcbio/ctx.c +611 -0
- data/ext/libcouchbase/src/lcbio/ctx.h +405 -0
- data/ext/libcouchbase/src/lcbio/iotable.c +290 -0
- data/ext/libcouchbase/src/lcbio/iotable.h +84 -0
- data/ext/libcouchbase/src/lcbio/ioutils.c +350 -0
- data/ext/libcouchbase/src/lcbio/ioutils.h +203 -0
- data/ext/libcouchbase/src/lcbio/lcbio.h +51 -0
- data/ext/libcouchbase/src/lcbio/manager.c +584 -0
- data/ext/libcouchbase/src/lcbio/manager.h +156 -0
- data/ext/libcouchbase/src/lcbio/protoctx.c +84 -0
- data/ext/libcouchbase/src/lcbio/rw-inl.h +115 -0
- data/ext/libcouchbase/src/lcbio/ssl.h +149 -0
- data/ext/libcouchbase/src/lcbio/timer-ng.h +179 -0
- data/ext/libcouchbase/src/lcbio/timer.c +132 -0
- data/ext/libcouchbase/src/legacy.c +430 -0
- data/ext/libcouchbase/src/list.c +144 -0
- data/ext/libcouchbase/src/list.h +127 -0
- data/ext/libcouchbase/src/logging.c +244 -0
- data/ext/libcouchbase/src/logging.h +86 -0
- data/ext/libcouchbase/src/mc/compress.c +90 -0
- data/ext/libcouchbase/src/mc/compress.h +61 -0
- data/ext/libcouchbase/src/mc/forward.c +186 -0
- data/ext/libcouchbase/src/mc/forward.h +90 -0
- data/ext/libcouchbase/src/mc/iovcursor-inl.h +279 -0
- data/ext/libcouchbase/src/mc/iovcursor.h +66 -0
- data/ext/libcouchbase/src/mc/mcreq-flush-inl.h +111 -0
- data/ext/libcouchbase/src/mc/mcreq.c +954 -0
- data/ext/libcouchbase/src/mc/mcreq.h +977 -0
- data/ext/libcouchbase/src/mcserver/mcserver.c +784 -0
- data/ext/libcouchbase/src/mcserver/mcserver.h +121 -0
- data/ext/libcouchbase/src/mcserver/negotiate.c +656 -0
- data/ext/libcouchbase/src/mcserver/negotiate.h +119 -0
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +860 -0
- data/ext/libcouchbase/src/n1ql/n1ql-internal.h +22 -0
- data/ext/libcouchbase/src/n1ql/n1ql.cc +729 -0
- data/ext/libcouchbase/src/n1ql/params.cc +215 -0
- data/ext/libcouchbase/src/netbuf/netbuf-defs.h +89 -0
- data/ext/libcouchbase/src/netbuf/netbuf-mblock.h +235 -0
- data/ext/libcouchbase/src/netbuf/netbuf.c +929 -0
- data/ext/libcouchbase/src/netbuf/netbuf.h +452 -0
- data/ext/libcouchbase/src/newconfig.c +385 -0
- data/ext/libcouchbase/src/nodeinfo.cc +194 -0
- data/ext/libcouchbase/src/operations/cbflush.c +71 -0
- data/ext/libcouchbase/src/operations/counter.c +116 -0
- data/ext/libcouchbase/src/operations/durability-cas.c +224 -0
- data/ext/libcouchbase/src/operations/durability-seqno.c +157 -0
- data/ext/libcouchbase/src/operations/durability.c +668 -0
- data/ext/libcouchbase/src/operations/durability_internal.h +199 -0
- data/ext/libcouchbase/src/operations/get.c +409 -0
- data/ext/libcouchbase/src/operations/observe-seqno.c +96 -0
- data/ext/libcouchbase/src/operations/observe.c +340 -0
- data/ext/libcouchbase/src/operations/pktfwd.c +86 -0
- data/ext/libcouchbase/src/operations/remove.c +83 -0
- data/ext/libcouchbase/src/operations/stats.c +461 -0
- data/ext/libcouchbase/src/operations/store.c +360 -0
- data/ext/libcouchbase/src/operations/subdoc.cc +510 -0
- data/ext/libcouchbase/src/operations/touch.c +81 -0
- data/ext/libcouchbase/src/packetutils.c +60 -0
- data/ext/libcouchbase/src/packetutils.h +147 -0
- data/ext/libcouchbase/src/probes.d +211 -0
- data/ext/libcouchbase/src/rdb/bigalloc.c +225 -0
- data/ext/libcouchbase/src/rdb/bigalloc.h +73 -0
- data/ext/libcouchbase/src/rdb/chunkalloc.c +174 -0
- data/ext/libcouchbase/src/rdb/libcalloc.c +94 -0
- data/ext/libcouchbase/src/rdb/rope.c +419 -0
- data/ext/libcouchbase/src/rdb/rope.h +488 -0
- data/ext/libcouchbase/src/retrychk.c +113 -0
- data/ext/libcouchbase/src/retryq.c +424 -0
- data/ext/libcouchbase/src/retryq.h +157 -0
- data/ext/libcouchbase/src/ringbuffer.c +442 -0
- data/ext/libcouchbase/src/ringbuffer.h +100 -0
- data/ext/libcouchbase/src/settings.c +95 -0
- data/ext/libcouchbase/src/settings.h +188 -0
- data/ext/libcouchbase/src/simplestring.c +211 -0
- data/ext/libcouchbase/src/simplestring.h +228 -0
- data/ext/libcouchbase/src/sllist-inl.h +197 -0
- data/ext/libcouchbase/src/sllist.h +76 -0
- data/ext/libcouchbase/src/ssl/CMakeLists.txt +23 -0
- data/ext/libcouchbase/src/ssl/ssl_c.c +415 -0
- data/ext/libcouchbase/src/ssl/ssl_common.c +454 -0
- data/ext/libcouchbase/src/ssl/ssl_e.c +408 -0
- data/ext/libcouchbase/src/ssl/ssl_iot_common.h +180 -0
- data/ext/libcouchbase/src/ssobuf.h +82 -0
- data/ext/libcouchbase/src/strcodecs/base64.c +123 -0
- data/ext/libcouchbase/src/strcodecs/strcodecs.h +285 -0
- data/ext/libcouchbase/src/timings.c +208 -0
- data/ext/libcouchbase/src/trace.h +105 -0
- data/ext/libcouchbase/src/utilities.c +171 -0
- data/ext/libcouchbase/src/vbucket/CMakeLists.txt +2 -0
- data/ext/libcouchbase/src/vbucket/aliases.h +35 -0
- data/ext/libcouchbase/src/vbucket/crc32.h +83 -0
- data/ext/libcouchbase/src/vbucket/hash.h +30 -0
- data/ext/libcouchbase/src/vbucket/json-inl.h +112 -0
- data/ext/libcouchbase/src/vbucket/ketama.c +66 -0
- data/ext/libcouchbase/src/vbucket/rfc1321/global.h +32 -0
- data/ext/libcouchbase/src/vbucket/rfc1321/md5.h +35 -0
- data/ext/libcouchbase/src/vbucket/rfc1321/md5c-inl.h +335 -0
- data/ext/libcouchbase/src/vbucket/vbucket.c +1543 -0
- data/ext/libcouchbase/src/views/docreq.c +194 -0
- data/ext/libcouchbase/src/views/docreq.h +83 -0
- data/ext/libcouchbase/src/views/viewreq.c +358 -0
- data/ext/libcouchbase/src/views/viewreq.h +36 -0
- data/ext/libcouchbase/src/wait.c +161 -0
- data/ext/libcouchbase/tests/CMakeLists.txt +140 -0
- data/ext/libcouchbase/tests/basic/t_base64.cc +81 -0
- data/ext/libcouchbase/tests/basic/t_ccbc103.cc +95 -0
- data/ext/libcouchbase/tests/basic/t_connstr.cc +404 -0
- data/ext/libcouchbase/tests/basic/t_creds.cc +32 -0
- data/ext/libcouchbase/tests/basic/t_ctlcodes.cc +92 -0
- data/ext/libcouchbase/tests/basic/t_hashset.cc +262 -0
- data/ext/libcouchbase/tests/basic/t_host.cc +198 -0
- data/ext/libcouchbase/tests/basic/t_jsparse.cc +137 -0
- data/ext/libcouchbase/tests/basic/t_jsparse.h +589 -0
- data/ext/libcouchbase/tests/basic/t_list.cc +155 -0
- data/ext/libcouchbase/tests/basic/t_logger.cc +65 -0
- data/ext/libcouchbase/tests/basic/t_misc.cc +24 -0
- data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +18 -0
- data/ext/libcouchbase/tests/basic/t_netbuf.cc +446 -0
- data/ext/libcouchbase/tests/basic/t_packet.cc +222 -0
- data/ext/libcouchbase/tests/basic/t_ringbuffer.cc +278 -0
- data/ext/libcouchbase/tests/basic/t_slist.cc +429 -0
- data/ext/libcouchbase/tests/basic/t_strerror.cc +64 -0
- data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
- data/ext/libcouchbase/tests/basic/t_urlencode.cc +132 -0
- data/ext/libcouchbase/tests/check-all.cc +608 -0
- data/ext/libcouchbase/tests/htparse/t_basic.cc +193 -0
- data/ext/libcouchbase/tests/ioserver/connection.cc +166 -0
- data/ext/libcouchbase/tests/ioserver/future.cc +50 -0
- data/ext/libcouchbase/tests/ioserver/ioserver.cc +104 -0
- data/ext/libcouchbase/tests/ioserver/ioserver.h +478 -0
- data/ext/libcouchbase/tests/ioserver/socket.cc +88 -0
- data/ext/libcouchbase/tests/ioserver/ssl_connection.cc +145 -0
- data/ext/libcouchbase/tests/ioserver/threads-pthreads.cc +119 -0
- data/ext/libcouchbase/tests/ioserver/threads-win32.cc +117 -0
- data/ext/libcouchbase/tests/ioserver/threads.h +66 -0
- data/ext/libcouchbase/tests/iotests/iotests.h +15 -0
- data/ext/libcouchbase/tests/iotests/mock-environment.cc +524 -0
- data/ext/libcouchbase/tests/iotests/mock-environment.h +385 -0
- data/ext/libcouchbase/tests/iotests/mock-unit-test.cc +67 -0
- data/ext/libcouchbase/tests/iotests/mock-unit-test.h +61 -0
- data/ext/libcouchbase/tests/iotests/serverparams.h +76 -0
- data/ext/libcouchbase/tests/iotests/t_arithmetic.cc +143 -0
- data/ext/libcouchbase/tests/iotests/t_behavior.cc +226 -0
- data/ext/libcouchbase/tests/iotests/t_configcache.cc +117 -0
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +241 -0
- data/ext/libcouchbase/tests/iotests/t_durability.cc +1059 -0
- data/ext/libcouchbase/tests/iotests/t_forward.cc +110 -0
- data/ext/libcouchbase/tests/iotests/t_get.cc +512 -0
- data/ext/libcouchbase/tests/iotests/t_http.cc +438 -0
- data/ext/libcouchbase/tests/iotests/t_iops.cc +175 -0
- data/ext/libcouchbase/tests/iotests/t_lock.cc +275 -0
- data/ext/libcouchbase/tests/iotests/t_misc.cc +713 -0
- data/ext/libcouchbase/tests/iotests/t_mutate.cc +609 -0
- data/ext/libcouchbase/tests/iotests/t_n1ql.cc +270 -0
- data/ext/libcouchbase/tests/iotests/t_netfail.cc +654 -0
- data/ext/libcouchbase/tests/iotests/t_obseqno.cc +157 -0
- data/ext/libcouchbase/tests/iotests/t_regression.cc +321 -0
- data/ext/libcouchbase/tests/iotests/t_sched.cc +88 -0
- data/ext/libcouchbase/tests/iotests/t_serverops.cc +230 -0
- data/ext/libcouchbase/tests/iotests/t_smoke.cc +528 -0
- data/ext/libcouchbase/tests/iotests/t_subdoc.cc +822 -0
- data/ext/libcouchbase/tests/iotests/t_syncmode.cc +64 -0
- data/ext/libcouchbase/tests/iotests/t_views.cc +405 -0
- data/ext/libcouchbase/tests/iotests/testutil.cc +250 -0
- data/ext/libcouchbase/tests/iotests/testutil.h +163 -0
- data/ext/libcouchbase/tests/mc/mctest.h +119 -0
- data/ext/libcouchbase/tests/mc/pktmaker.h +101 -0
- data/ext/libcouchbase/tests/mc/t_alloc.cc +269 -0
- data/ext/libcouchbase/tests/mc/t_context.cc +100 -0
- data/ext/libcouchbase/tests/mc/t_flush.cc +185 -0
- data/ext/libcouchbase/tests/mc/t_forward.cc +239 -0
- data/ext/libcouchbase/tests/mc/t_ioflush.cc +102 -0
- data/ext/libcouchbase/tests/mc/t_iovcursor.cc +173 -0
- data/ext/libcouchbase/tests/mocksupport/procutil.c +305 -0
- data/ext/libcouchbase/tests/mocksupport/procutil.h +89 -0
- data/ext/libcouchbase/tests/mocksupport/server.c +391 -0
- data/ext/libcouchbase/tests/mocksupport/server.h +72 -0
- data/ext/libcouchbase/tests/mocksupport/timeout.c +69 -0
- data/ext/libcouchbase/tests/nonio_tests.cc +23 -0
- data/ext/libcouchbase/tests/rdb/rdbtest.h +133 -0
- data/ext/libcouchbase/tests/rdb/t_basic.cc +128 -0
- data/ext/libcouchbase/tests/rdb/t_bigalloc.cc +93 -0
- data/ext/libcouchbase/tests/rdb/t_refs.cc +112 -0
- data/ext/libcouchbase/tests/socktests/socktest.cc +347 -0
- data/ext/libcouchbase/tests/socktests/socktest.h +448 -0
- data/ext/libcouchbase/tests/socktests/t_basic.cc +143 -0
- data/ext/libcouchbase/tests/socktests/t_ctx.cc +73 -0
- data/ext/libcouchbase/tests/socktests/t_manager.cc +179 -0
- data/ext/libcouchbase/tests/socktests/t_putex.cc +256 -0
- data/ext/libcouchbase/tests/socktests/t_read.cc +187 -0
- data/ext/libcouchbase/tests/socktests/t_reentrant.cc +143 -0
- data/ext/libcouchbase/tests/socktests/t_ssl.cc +80 -0
- data/ext/libcouchbase/tests/socktests/t_write.cc +95 -0
- data/ext/libcouchbase/tests/start_mock.bat +15 -0
- data/ext/libcouchbase/tests/start_mock.sh +42 -0
- data/ext/libcouchbase/tests/unit_tests.cc +43 -0
- data/ext/libcouchbase/tests/vbucket/confdata/bad.json +101 -0
- data/ext/libcouchbase/tests/vbucket/confdata/full_25.json +363 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_25.json +90 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_30.json +1 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_45.json +1 -0
- data/ext/libcouchbase/tests/vbucket/confdata/terse_25.json +291 -0
- data/ext/libcouchbase/tests/vbucket/confdata/terse_30.json +1 -0
- data/ext/libcouchbase/tests/vbucket/t_config.cc +341 -0
- data/ext/libcouchbase/tools/CMakeLists.txt +51 -0
- data/ext/libcouchbase/tools/cbc-handlers.h +462 -0
- data/ext/libcouchbase/tools/cbc-n1qlback.cc +439 -0
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +822 -0
- data/ext/libcouchbase/tools/cbc.cc +1541 -0
- data/ext/libcouchbase/tools/common/histogram.cc +43 -0
- data/ext/libcouchbase/tools/common/histogram.h +23 -0
- data/ext/libcouchbase/tools/common/my_inttypes.h +22 -0
- data/ext/libcouchbase/tools/common/options.cc +420 -0
- data/ext/libcouchbase/tools/common/options.h +81 -0
- data/ext/libcouchbase/tools/docgen/docgen.h +469 -0
- data/ext/libcouchbase/tools/docgen/loc.h +210 -0
- data/ext/libcouchbase/tools/docgen/placeholders.h +211 -0
- data/ext/libcouchbase/tools/docgen/seqgen.h +94 -0
- data/lib/libcouchbase.rb +36 -0
- data/lib/libcouchbase/bucket.rb +819 -0
- data/lib/libcouchbase/callbacks.rb +72 -0
- data/lib/libcouchbase/connection.rb +790 -0
- data/lib/libcouchbase/design_docs.rb +86 -0
- data/lib/libcouchbase/error.rb +68 -0
- data/lib/libcouchbase/ext/libcouchbase.rb +1135 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdbase.rb +23 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdcounter.rb +36 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdendure.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdfts.rb +24 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdget.rb +30 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdgetreplica.rb +49 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdhttp.rb +58 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdn1ql.rb +40 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdobseqno.rb +33 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdobserve.rb +30 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdstore.rb +40 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdstoredur.rb +45 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdsubdoc.rb +49 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdverbosity.rb +29 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdviewquery.rb +61 -0
- data/lib/libcouchbase/ext/libcouchbase/contigbuf.rb +14 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st.rb +15 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st0.rb +23 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st1.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st2.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st3.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/crst_u.rb +20 -0
- data/lib/libcouchbase/ext/libcouchbase/durability_opts_st_v.rb +11 -0
- data/lib/libcouchbase/ext/libcouchbase/durability_opts_t.rb +14 -0
- data/lib/libcouchbase/ext/libcouchbase/durabilityopt_sv0.rb +63 -0
- data/lib/libcouchbase/ext/libcouchbase/enums.rb +991 -0
- data/lib/libcouchbase/ext/libcouchbase/fragbuf.rb +18 -0
- data/lib/libcouchbase/ext/libcouchbase/ftshandle.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/histogram.rb +34 -0
- data/lib/libcouchbase/ext/libcouchbase/http_request_t.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/keybuf.rb +20 -0
- data/lib/libcouchbase/ext/libcouchbase/multicmd_ctx.rb +30 -0
- data/lib/libcouchbase/ext/libcouchbase/mutation_token.rb +17 -0
- data/lib/libcouchbase/ext/libcouchbase/n1qlhandle.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/n1qlparams.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/respbase.rb +29 -0
- data/lib/libcouchbase/ext/libcouchbase/respcounter.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/respendure.rb +49 -0
- data/lib/libcouchbase/ext/libcouchbase/respfts.rb +40 -0
- data/lib/libcouchbase/ext/libcouchbase/respget.rb +44 -0
- data/lib/libcouchbase/ext/libcouchbase/resphttp.rb +48 -0
- data/lib/libcouchbase/ext/libcouchbase/respmcversion.rb +38 -0
- data/lib/libcouchbase/ext/libcouchbase/respn1ql.rb +41 -0
- data/lib/libcouchbase/ext/libcouchbase/respobseqno.rb +52 -0
- data/lib/libcouchbase/ext/libcouchbase/respobserve.rb +41 -0
- data/lib/libcouchbase/ext/libcouchbase/respserverbase.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/respstats.rb +38 -0
- data/lib/libcouchbase/ext/libcouchbase/respstore.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/respstoredur.rb +38 -0
- data/lib/libcouchbase/ext/libcouchbase/respsubdoc.rb +35 -0
- data/lib/libcouchbase/ext/libcouchbase/respviewquery.rb +67 -0
- data/lib/libcouchbase/ext/libcouchbase/sdentry.rb +22 -0
- data/lib/libcouchbase/ext/libcouchbase/sdspec.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/t.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/valbuf.rb +22 -0
- data/lib/libcouchbase/ext/libcouchbase/valbuf_u_buf.rb +14 -0
- data/lib/libcouchbase/ext/libcouchbase/viewhandle.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase_iocp.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase_libuv.rb +18 -0
- data/lib/libcouchbase/ext/tasks.rb +87 -0
- data/lib/libcouchbase/n1ql.rb +73 -0
- data/lib/libcouchbase/query_full_text.rb +147 -0
- data/lib/libcouchbase/query_n1ql.rb +121 -0
- data/lib/libcouchbase/query_view.rb +129 -0
- data/lib/libcouchbase/results_fiber.rb +262 -0
- data/lib/libcouchbase/results_native.rb +211 -0
- data/lib/libcouchbase/version.rb +5 -0
- data/libcouchbase.gemspec +61 -0
- data/spec/bucket_spec.rb +270 -0
- data/spec/connection_spec.rb +277 -0
- data/spec/design_docs_spec.rb +23 -0
- data/spec/error_spec.rb +26 -0
- data/spec/fts_spec.rb +129 -0
- data/spec/n1ql_spec.rb +201 -0
- data/spec/results_libuv_spec.rb +229 -0
- data/spec/results_native_spec.rb +259 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/design.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/data-0000.cbb +0 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/failover.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/meta.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/seqno.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/snapshot_markers.json +1 -0
- data/spec/view_spec.rb +195 -0
- metadata +775 -0
@@ -0,0 +1,1541 @@
|
|
1
|
+
#include "common/my_inttypes.h"
|
2
|
+
#include <map>
|
3
|
+
#include <sstream>
|
4
|
+
#include <iostream>
|
5
|
+
#include <fstream>
|
6
|
+
#include <algorithm>
|
7
|
+
#include <libcouchbase/vbucket.h>
|
8
|
+
#include <libcouchbase/views.h>
|
9
|
+
#include <libcouchbase/n1ql.h>
|
10
|
+
#include <stddef.h>
|
11
|
+
#include "common/options.h"
|
12
|
+
#include "common/histogram.h"
|
13
|
+
#include "cbc-handlers.h"
|
14
|
+
#include "connspec.h"
|
15
|
+
using namespace cbc;
|
16
|
+
|
17
|
+
using std::string;
|
18
|
+
using std::map;
|
19
|
+
using std::vector;
|
20
|
+
using std::stringstream;
|
21
|
+
|
22
|
+
string getRespKey(const lcb_RESPBASE* resp)
|
23
|
+
{
|
24
|
+
if (!resp->nkey) {
|
25
|
+
return "";
|
26
|
+
}
|
27
|
+
|
28
|
+
return string((const char *)resp->key, resp->nkey);
|
29
|
+
}
|
30
|
+
|
31
|
+
static void
|
32
|
+
printKeyError(string& key, lcb_error_t err, const char *additional = NULL)
|
33
|
+
{
|
34
|
+
fprintf(stderr, "%-20s %s (0x%x)\n", key.c_str(), lcb_strerror(NULL, err), err);
|
35
|
+
if (additional) {
|
36
|
+
fprintf(stderr, "%-20s%s\n", "", additional);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
static void
|
41
|
+
printKeyCasStatus(string& key, int cbtype, const lcb_RESPBASE *resp,
|
42
|
+
const char *message = NULL)
|
43
|
+
{
|
44
|
+
fprintf(stderr, "%-20s", key.c_str());
|
45
|
+
if (message != NULL) {
|
46
|
+
fprintf(stderr, "%s ", message);
|
47
|
+
}
|
48
|
+
fprintf(stderr, "CAS=0x%" PRIx64 "\n", resp->cas);
|
49
|
+
const lcb_MUTATION_TOKEN *st = lcb_resp_get_mutation_token(cbtype, resp);
|
50
|
+
if (st != NULL) {
|
51
|
+
fprintf(stderr, "%-20sSYNCTOKEN=%u,%" PRIu64 ",%" PRIu64 "\n",
|
52
|
+
"", st->vbid_, st->uuid_, st->seqno_);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
extern "C" {
|
57
|
+
static void
|
58
|
+
get_callback(lcb_t, lcb_CALLBACKTYPE, const lcb_RESPGET *resp)
|
59
|
+
{
|
60
|
+
string key = getRespKey((const lcb_RESPBASE *)resp);
|
61
|
+
if (resp->rc == LCB_SUCCESS) {
|
62
|
+
fprintf(stderr, "%-20s CAS=0x%" PRIx64 ", Flags=0x%x. Size=%lu\n",
|
63
|
+
key.c_str(), resp->cas, resp->itmflags, (unsigned long)resp->nvalue);
|
64
|
+
fflush(stderr);
|
65
|
+
fwrite(resp->value, 1, resp->nvalue, stdout);
|
66
|
+
fflush(stdout);
|
67
|
+
fprintf(stderr, "\n");
|
68
|
+
} else {
|
69
|
+
printKeyError(key, resp->rc);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
static void
|
74
|
+
store_callback(lcb_t, lcb_CALLBACKTYPE cbtype, const lcb_RESPBASE *resp)
|
75
|
+
{
|
76
|
+
string key = getRespKey((const lcb_RESPBASE*)resp);
|
77
|
+
|
78
|
+
if (cbtype == LCB_CALLBACK_STOREDUR) {
|
79
|
+
// Storage with durability
|
80
|
+
const lcb_RESPSTOREDUR *dresp =
|
81
|
+
reinterpret_cast<const lcb_RESPSTOREDUR *>(resp);
|
82
|
+
char buf[4096];
|
83
|
+
if (resp->rc == LCB_SUCCESS) {
|
84
|
+
sprintf(buf, "Stored. Persisted(%u). Replicated(%u)",
|
85
|
+
dresp->dur_resp->npersisted, dresp->dur_resp->nreplicated);
|
86
|
+
printKeyCasStatus(key, cbtype, resp, buf);
|
87
|
+
} else {
|
88
|
+
if (dresp->store_ok) {
|
89
|
+
sprintf(buf, "Store OK, but durability failed. Persisted(%u). Replicated(%u)",
|
90
|
+
dresp->dur_resp->npersisted, dresp->dur_resp->nreplicated);
|
91
|
+
} else {
|
92
|
+
sprintf(buf, "%s", "Store failed");
|
93
|
+
}
|
94
|
+
printKeyError(key, resp->rc, buf);
|
95
|
+
}
|
96
|
+
} else {
|
97
|
+
if (resp->rc == LCB_SUCCESS) {
|
98
|
+
printKeyCasStatus(key, cbtype, resp, "Stored.");
|
99
|
+
} else {
|
100
|
+
printKeyError(key, resp->rc);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
static void
|
106
|
+
common_callback(lcb_t, int type, const lcb_RESPBASE *resp)
|
107
|
+
{
|
108
|
+
string key = getRespKey(resp);
|
109
|
+
if (resp->rc != LCB_SUCCESS) {
|
110
|
+
printKeyError(key, resp->rc);
|
111
|
+
return;
|
112
|
+
}
|
113
|
+
switch (type) {
|
114
|
+
case LCB_CALLBACK_UNLOCK:
|
115
|
+
fprintf(stderr, "%-20s Unlocked\n", key.c_str());
|
116
|
+
break;
|
117
|
+
case LCB_CALLBACK_REMOVE:
|
118
|
+
printKeyCasStatus(key, type, resp, "Deleted.");
|
119
|
+
break;
|
120
|
+
case LCB_CALLBACK_TOUCH:
|
121
|
+
printKeyCasStatus(key, type, resp, "Touched.");
|
122
|
+
break;
|
123
|
+
default:
|
124
|
+
abort(); // didn't request it
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
static void
|
129
|
+
observe_callback(lcb_t, lcb_CALLBACKTYPE, const lcb_RESPOBSERVE *resp)
|
130
|
+
{
|
131
|
+
if (resp->nkey == 0) {
|
132
|
+
return;
|
133
|
+
}
|
134
|
+
|
135
|
+
string key = getRespKey((const lcb_RESPBASE *)resp);
|
136
|
+
if (resp->rc == LCB_SUCCESS) {
|
137
|
+
fprintf(stderr,
|
138
|
+
"%-20s [%s] Status=0x%x, CAS=0x%" PRIx64 "\n", key.c_str(),
|
139
|
+
resp->ismaster ? "Master" : "Replica",
|
140
|
+
resp->status, resp->cas);
|
141
|
+
} else {
|
142
|
+
printKeyError(key, resp->rc);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
static void
|
147
|
+
obseqno_callback(lcb_t, lcb_CALLBACKTYPE, const lcb_RESPOBSEQNO *resp)
|
148
|
+
{
|
149
|
+
int ix = resp->server_index;
|
150
|
+
if (resp->rc != LCB_SUCCESS) {
|
151
|
+
fprintf(stderr,
|
152
|
+
"[%d] ERROR 0x%X (%s)\n", ix, resp->rc, lcb_strerror(NULL, resp->rc));
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
lcb_U64 uuid, seq_disk, seq_mem;
|
156
|
+
if (resp->old_uuid) {
|
157
|
+
seq_disk = seq_mem = resp->old_seqno;
|
158
|
+
uuid = resp->old_uuid;
|
159
|
+
} else {
|
160
|
+
uuid = resp->cur_uuid;
|
161
|
+
seq_disk = resp->persisted_seqno;
|
162
|
+
seq_mem = resp->mem_seqno;
|
163
|
+
}
|
164
|
+
fprintf(stderr, "[%d] UUID=0x%" PRIx64 ", Cache=%" PRIu64 ", Disk=%" PRIu64,
|
165
|
+
ix, uuid, seq_mem, seq_disk);
|
166
|
+
if (resp->old_uuid) {
|
167
|
+
fprintf(stderr, "\n");
|
168
|
+
fprintf(stderr, " FAILOVER. New: UUID=%" PRIx64 ", Cache=%" PRIu64 ", Disk=%" PRIu64,
|
169
|
+
resp->cur_uuid, resp->mem_seqno, resp->persisted_seqno);
|
170
|
+
}
|
171
|
+
fprintf(stderr, "\n");
|
172
|
+
}
|
173
|
+
|
174
|
+
static void
|
175
|
+
stats_callback(lcb_t, lcb_CALLBACKTYPE, const lcb_RESPSTATS *resp)
|
176
|
+
{
|
177
|
+
if (resp->rc != LCB_SUCCESS) {
|
178
|
+
fprintf(stderr, "Got error %s (%d) in stats\n", lcb_strerror(NULL, resp->rc), resp->rc);
|
179
|
+
return;
|
180
|
+
}
|
181
|
+
if (resp->server == NULL || resp->key == NULL) {
|
182
|
+
return;
|
183
|
+
}
|
184
|
+
|
185
|
+
string server = resp->server;
|
186
|
+
string key = getRespKey((const lcb_RESPBASE *)resp);
|
187
|
+
string value;
|
188
|
+
if (resp->nvalue > 0) {
|
189
|
+
value.assign((const char *)resp->value, resp->nvalue);
|
190
|
+
}
|
191
|
+
fprintf(stdout, "%s\t%s", server.c_str(), key.c_str());
|
192
|
+
if (!value.empty()) {
|
193
|
+
if (*static_cast<bool*>(resp->cookie) && key == "key_flags") {
|
194
|
+
// Is keystats
|
195
|
+
// Flip the bits so the display formats correctly
|
196
|
+
unsigned flags_u = 0;
|
197
|
+
sscanf(value.c_str(), "%u", &flags_u);
|
198
|
+
flags_u = htonl(flags_u);
|
199
|
+
fprintf(stdout, "\t%u (cbc: converted via htonl)", flags_u);
|
200
|
+
} else {
|
201
|
+
fprintf(stdout, "\t%s", value.c_str());
|
202
|
+
}
|
203
|
+
}
|
204
|
+
fprintf(stdout, "\n");
|
205
|
+
}
|
206
|
+
|
207
|
+
static void
|
208
|
+
common_server_callback(lcb_t, int cbtype, const lcb_RESPSERVERBASE *sbase)
|
209
|
+
{
|
210
|
+
const char *msg;
|
211
|
+
if (cbtype == LCB_CALLBACK_VERBOSITY) {
|
212
|
+
msg = "Set verbosity";
|
213
|
+
} else if (cbtype == LCB_CALLBACK_FLUSH) {
|
214
|
+
msg = "Flush";
|
215
|
+
} else {
|
216
|
+
msg = "";
|
217
|
+
}
|
218
|
+
if (!sbase->server) {
|
219
|
+
return;
|
220
|
+
}
|
221
|
+
if (sbase->rc != LCB_SUCCESS) {
|
222
|
+
fprintf(stderr, "%s failed for server %s: %s\n", msg, sbase->server,
|
223
|
+
lcb_strerror(NULL, sbase->rc));
|
224
|
+
} else {
|
225
|
+
fprintf(stderr, "%s: %s\n", msg, sbase->server);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
static void
|
230
|
+
arithmetic_callback(lcb_t, lcb_CALLBACKTYPE type, const lcb_RESPCOUNTER *resp)
|
231
|
+
{
|
232
|
+
string key = getRespKey((const lcb_RESPBASE *)resp);
|
233
|
+
if (resp->rc != LCB_SUCCESS) {
|
234
|
+
printKeyError(key, resp->rc);
|
235
|
+
} else {
|
236
|
+
char buf[4096] = { 0 };
|
237
|
+
sprintf(buf, "Current value is %" PRIu64 ".", resp->value);
|
238
|
+
printKeyCasStatus(key, type, (const lcb_RESPBASE *)resp, buf);
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
static void
|
243
|
+
http_callback(lcb_t, int, const lcb_RESPHTTP *resp)
|
244
|
+
{
|
245
|
+
HttpReceiver *ctx = (HttpReceiver *)resp->cookie;
|
246
|
+
ctx->maybeInvokeStatus(resp);
|
247
|
+
if (resp->nbody) {
|
248
|
+
ctx->onChunk((const char*)resp->body, resp->nbody);
|
249
|
+
}
|
250
|
+
if (resp->rflags & LCB_RESP_F_FINAL) {
|
251
|
+
ctx->onDone();
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
static void
|
256
|
+
view_callback(lcb_t, int, const lcb_RESPVIEWQUERY *resp)
|
257
|
+
{
|
258
|
+
if (resp->rflags & LCB_RESP_F_FINAL) {
|
259
|
+
fprintf(stderr, "View query complete!\n");
|
260
|
+
}
|
261
|
+
|
262
|
+
if (resp->rc != LCB_SUCCESS) {
|
263
|
+
fprintf(stderr, "View query failed: 0x%x (%s)\n",
|
264
|
+
resp->rc, lcb_strerror(NULL, resp->rc));
|
265
|
+
|
266
|
+
if (resp->rc == LCB_HTTP_ERROR) {
|
267
|
+
if (resp->htresp != NULL) {
|
268
|
+
HttpReceiver ctx;
|
269
|
+
ctx.maybeInvokeStatus(resp->htresp);
|
270
|
+
if (resp->htresp->nbody) {
|
271
|
+
fprintf(stderr, "%.*s", (int)resp->htresp->nbody,
|
272
|
+
static_cast<const char *>(resp->htresp->body));
|
273
|
+
}
|
274
|
+
}
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
if (resp->rflags & LCB_RESP_F_FINAL) {
|
279
|
+
if (resp->value) {
|
280
|
+
fprintf(stderr, "Non-row data: %.*s\n",
|
281
|
+
(int)resp->nvalue, resp->value);
|
282
|
+
}
|
283
|
+
return;
|
284
|
+
}
|
285
|
+
|
286
|
+
printf("KEY: %.*s\n", (int)resp->nkey, static_cast<const char*>(resp->key));
|
287
|
+
printf(" VALUE: %.*s\n", (int)resp->nvalue, resp->value);
|
288
|
+
printf(" DOCID: %.*s\n", (int)resp->ndocid, resp->docid);
|
289
|
+
if (resp->docresp) {
|
290
|
+
get_callback(NULL, LCB_CALLBACK_GET, resp->docresp);
|
291
|
+
}
|
292
|
+
if (resp->geometry) {
|
293
|
+
printf(" GEO: %.*s\n", (int)resp->ngeometry, resp->geometry);
|
294
|
+
}
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
|
299
|
+
Handler::Handler(const char *name) : parser(name), instance(NULL)
|
300
|
+
{
|
301
|
+
if (name != NULL) {
|
302
|
+
cmdname = name;
|
303
|
+
}
|
304
|
+
}
|
305
|
+
|
306
|
+
Handler::~Handler()
|
307
|
+
{
|
308
|
+
if (params.shouldDump()) {
|
309
|
+
lcb_dump(instance, stderr, LCB_DUMP_ALL);
|
310
|
+
}
|
311
|
+
if (instance) {
|
312
|
+
lcb_destroy(instance);
|
313
|
+
}
|
314
|
+
}
|
315
|
+
|
316
|
+
void
|
317
|
+
Handler::execute(int argc, char **argv)
|
318
|
+
{
|
319
|
+
addOptions();
|
320
|
+
parser.default_settings.argstring = usagestr();
|
321
|
+
parser.default_settings.shortdesc = description();
|
322
|
+
parser.parse(argc, argv, true);
|
323
|
+
run();
|
324
|
+
if (instance != NULL && params.useTimings()) {
|
325
|
+
fprintf(stderr, "Output command timings as requested (--timings)\n");
|
326
|
+
hg.write();
|
327
|
+
}
|
328
|
+
}
|
329
|
+
|
330
|
+
void
|
331
|
+
Handler::addOptions()
|
332
|
+
{
|
333
|
+
params.addToParser(parser);
|
334
|
+
}
|
335
|
+
|
336
|
+
void
|
337
|
+
Handler::run()
|
338
|
+
{
|
339
|
+
lcb_create_st cropts;
|
340
|
+
memset(&cropts, 0, sizeof cropts);
|
341
|
+
params.fillCropts(cropts);
|
342
|
+
lcb_error_t err;
|
343
|
+
err = lcb_create(&instance, &cropts);
|
344
|
+
if (err != LCB_SUCCESS) {
|
345
|
+
throw LcbError(err);
|
346
|
+
}
|
347
|
+
params.doCtls(instance);
|
348
|
+
err = lcb_connect(instance);
|
349
|
+
if (err != LCB_SUCCESS) {
|
350
|
+
throw LcbError(err);
|
351
|
+
}
|
352
|
+
lcb_wait(instance);
|
353
|
+
err = lcb_get_bootstrap_status(instance);
|
354
|
+
if (err != LCB_SUCCESS) {
|
355
|
+
throw LcbError(err);
|
356
|
+
}
|
357
|
+
|
358
|
+
if (params.useTimings()) {
|
359
|
+
hg.install(instance, stdout);
|
360
|
+
}
|
361
|
+
}
|
362
|
+
|
363
|
+
const string&
|
364
|
+
Handler::getLoneArg(bool required)
|
365
|
+
{
|
366
|
+
static string empty("");
|
367
|
+
|
368
|
+
const vector<string>& args = parser.getRestArgs();
|
369
|
+
if (args.empty() || args.size() != 1) {
|
370
|
+
if (required) {
|
371
|
+
throw std::runtime_error("Command requires single argument");
|
372
|
+
}
|
373
|
+
return empty;
|
374
|
+
}
|
375
|
+
return args[0];
|
376
|
+
}
|
377
|
+
|
378
|
+
void
|
379
|
+
GetHandler::addOptions()
|
380
|
+
{
|
381
|
+
Handler::addOptions();
|
382
|
+
o_exptime.abbrev('e');
|
383
|
+
if (isLock()) {
|
384
|
+
o_exptime.description("Time the lock should be held for");
|
385
|
+
} else {
|
386
|
+
o_exptime.description("Update the expiration time for the item");
|
387
|
+
o_replica.abbrev('r');
|
388
|
+
o_replica.description("Read from replica. Possible values are 'first': read from first available replica. 'all': read from all replicas, and <N>, where 0 < N < nreplicas");
|
389
|
+
parser.addOption(o_replica);
|
390
|
+
}
|
391
|
+
parser.addOption(o_exptime);
|
392
|
+
}
|
393
|
+
|
394
|
+
void
|
395
|
+
GetHandler::run()
|
396
|
+
{
|
397
|
+
Handler::run();
|
398
|
+
lcb_install_callback3(instance, LCB_CALLBACK_GET, (lcb_RESPCALLBACK)get_callback);
|
399
|
+
lcb_install_callback3(instance, LCB_CALLBACK_GETREPLICA, (lcb_RESPCALLBACK)get_callback);
|
400
|
+
const vector<string>& keys = parser.getRestArgs();
|
401
|
+
lcb_error_t err;
|
402
|
+
|
403
|
+
lcb_sched_enter(instance);
|
404
|
+
for (size_t ii = 0; ii < keys.size(); ++ii) {
|
405
|
+
lcb_CMDGET cmd = { 0 };
|
406
|
+
const string& key = keys[ii];
|
407
|
+
LCB_KREQ_SIMPLE(&cmd.key, key.c_str(), key.size());
|
408
|
+
if (o_exptime.passed()) {
|
409
|
+
cmd.exptime = o_exptime.result();
|
410
|
+
}
|
411
|
+
if (isLock()) {
|
412
|
+
cmd.lock = 1;
|
413
|
+
}
|
414
|
+
|
415
|
+
err = lcb_get3(instance, this, &cmd);
|
416
|
+
if (err != LCB_SUCCESS) {
|
417
|
+
throw LcbError(err);
|
418
|
+
}
|
419
|
+
}
|
420
|
+
lcb_sched_leave(instance);
|
421
|
+
lcb_wait(instance);
|
422
|
+
}
|
423
|
+
|
424
|
+
void
|
425
|
+
TouchHandler::addOptions()
|
426
|
+
{
|
427
|
+
Handler::addOptions();
|
428
|
+
parser.addOption(o_exptime);
|
429
|
+
}
|
430
|
+
|
431
|
+
void
|
432
|
+
TouchHandler::run()
|
433
|
+
{
|
434
|
+
Handler::run();
|
435
|
+
lcb_install_callback3(instance, LCB_CALLBACK_TOUCH, (lcb_RESPCALLBACK)common_callback);
|
436
|
+
const vector<string>& keys = parser.getRestArgs();
|
437
|
+
lcb_error_t err;
|
438
|
+
lcb_sched_enter(instance);
|
439
|
+
for (size_t ii = 0; ii < keys.size(); ++ii) {
|
440
|
+
lcb_CMDTOUCH cmd = { 0 };
|
441
|
+
const string& key = keys[ii];
|
442
|
+
LCB_CMD_SET_KEY(&cmd, key.c_str(), key.size());
|
443
|
+
cmd.exptime = o_exptime.result();
|
444
|
+
err = lcb_touch3(instance, this, &cmd);
|
445
|
+
if (err != LCB_SUCCESS) {
|
446
|
+
throw LcbError(err);
|
447
|
+
}
|
448
|
+
}
|
449
|
+
lcb_sched_leave(instance);
|
450
|
+
lcb_wait(instance);
|
451
|
+
}
|
452
|
+
|
453
|
+
void
|
454
|
+
SetHandler::addOptions()
|
455
|
+
{
|
456
|
+
Handler::addOptions();
|
457
|
+
parser.addOption(o_mode);
|
458
|
+
parser.addOption(o_flags);
|
459
|
+
parser.addOption(o_exp);
|
460
|
+
parser.addOption(o_add);
|
461
|
+
parser.addOption(o_persist);
|
462
|
+
parser.addOption(o_replicate);
|
463
|
+
if (!hasFileList()) {
|
464
|
+
parser.addOption(o_value);
|
465
|
+
}
|
466
|
+
// This may be enabled again if datatype support is re-added
|
467
|
+
// parser.addOption(o_json);
|
468
|
+
}
|
469
|
+
|
470
|
+
lcb_storage_t
|
471
|
+
SetHandler::mode()
|
472
|
+
{
|
473
|
+
if (o_add.passed()) {
|
474
|
+
return LCB_ADD;
|
475
|
+
}
|
476
|
+
|
477
|
+
string s = o_mode.const_result();
|
478
|
+
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
479
|
+
if (s == "upsert") {
|
480
|
+
return LCB_SET;
|
481
|
+
} else if (s == "replace") {
|
482
|
+
return LCB_REPLACE;
|
483
|
+
} else if (s == "insert") {
|
484
|
+
return LCB_ADD;
|
485
|
+
} else if (s == "append") {
|
486
|
+
return LCB_APPEND;
|
487
|
+
} else if (s == "prepend") {
|
488
|
+
return LCB_PREPEND;
|
489
|
+
} else {
|
490
|
+
throw BadArg(string("Mode must be one of upsert, insert, replace. Got ") + s);
|
491
|
+
return LCB_SET;
|
492
|
+
}
|
493
|
+
}
|
494
|
+
|
495
|
+
void
|
496
|
+
SetHandler::storeItem(const string& key, const char *value, size_t nvalue)
|
497
|
+
{
|
498
|
+
lcb_error_t err;
|
499
|
+
lcb_CMDSTOREDUR cmd = { 0 };
|
500
|
+
LCB_CMD_SET_KEY(&cmd, key.c_str(), key.size());
|
501
|
+
cmd.value.vtype = LCB_KV_COPY;
|
502
|
+
cmd.value.u_buf.contig.bytes = value;
|
503
|
+
cmd.value.u_buf.contig.nbytes = nvalue;
|
504
|
+
cmd.operation = mode();
|
505
|
+
|
506
|
+
if (o_json.result()) {
|
507
|
+
cmd.datatype = LCB_VALUE_F_JSON;
|
508
|
+
}
|
509
|
+
if (o_exp.passed()) {
|
510
|
+
cmd.exptime = o_exp.result();
|
511
|
+
}
|
512
|
+
if (o_flags.passed()) {
|
513
|
+
cmd.flags = o_flags.result();
|
514
|
+
}
|
515
|
+
if (o_persist.passed() || o_replicate.passed()) {
|
516
|
+
cmd.persist_to = o_persist.result();
|
517
|
+
cmd.replicate_to = o_replicate.result();
|
518
|
+
err = lcb_storedur3(instance, NULL, &cmd);
|
519
|
+
} else {
|
520
|
+
err = lcb_store3(instance, NULL, reinterpret_cast<lcb_CMDSTORE*>(&cmd));
|
521
|
+
}
|
522
|
+
if (err != LCB_SUCCESS) {
|
523
|
+
throw LcbError(err);
|
524
|
+
}
|
525
|
+
}
|
526
|
+
|
527
|
+
void
|
528
|
+
SetHandler::storeItem(const string& key, FILE *input)
|
529
|
+
{
|
530
|
+
char tmpbuf[4096];
|
531
|
+
vector<char> vbuf;
|
532
|
+
size_t nr;
|
533
|
+
while ((nr = fread(tmpbuf, 1, sizeof tmpbuf, input))) {
|
534
|
+
vbuf.insert(vbuf.end(), tmpbuf, &tmpbuf[nr]);
|
535
|
+
}
|
536
|
+
storeItem(key, &vbuf[0], vbuf.size());
|
537
|
+
}
|
538
|
+
|
539
|
+
void
|
540
|
+
SetHandler::run()
|
541
|
+
{
|
542
|
+
Handler::run();
|
543
|
+
lcb_install_callback3(instance, LCB_CALLBACK_STORE, (lcb_RESPCALLBACK)store_callback);
|
544
|
+
lcb_install_callback3(instance, LCB_CALLBACK_STOREDUR, (lcb_RESPCALLBACK)store_callback);
|
545
|
+
const vector<string>& keys = parser.getRestArgs();
|
546
|
+
|
547
|
+
lcb_sched_enter(instance);
|
548
|
+
|
549
|
+
if (hasFileList()) {
|
550
|
+
for (size_t ii = 0; ii < keys.size(); ii++) {
|
551
|
+
const string& key = keys[ii];
|
552
|
+
FILE *fp = fopen(key.c_str(), "rb");
|
553
|
+
if (fp == NULL) {
|
554
|
+
perror(key.c_str());
|
555
|
+
continue;
|
556
|
+
}
|
557
|
+
storeItem(key, fp);
|
558
|
+
fclose(fp);
|
559
|
+
}
|
560
|
+
} else if (keys.size() > 1 || keys.empty()) {
|
561
|
+
throw BadArg("create must be passed a single key");
|
562
|
+
} else {
|
563
|
+
const string& key = keys[0];
|
564
|
+
if (o_value.passed()) {
|
565
|
+
const string& value = o_value.const_result();
|
566
|
+
storeItem(key, value.c_str(), value.size());
|
567
|
+
} else {
|
568
|
+
storeItem(key, stdin);
|
569
|
+
}
|
570
|
+
}
|
571
|
+
|
572
|
+
lcb_sched_leave(instance);
|
573
|
+
lcb_wait(instance);
|
574
|
+
}
|
575
|
+
|
576
|
+
void
|
577
|
+
HashHandler::run()
|
578
|
+
{
|
579
|
+
Handler::run();
|
580
|
+
|
581
|
+
lcbvb_CONFIG *vbc;
|
582
|
+
lcb_error_t err;
|
583
|
+
err = lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_VBCONFIG, &vbc);
|
584
|
+
if (err != LCB_SUCCESS) {
|
585
|
+
throw LcbError(err);
|
586
|
+
}
|
587
|
+
|
588
|
+
const vector<string>& args = parser.getRestArgs();
|
589
|
+
for (size_t ii = 0; ii < args.size(); ii++) {
|
590
|
+
const string& key = args[ii];
|
591
|
+
const void *vkey = (const void *)key.c_str();
|
592
|
+
int vbid, srvix;
|
593
|
+
lcbvb_map_key(vbc, vkey, key.size(), &vbid, &srvix);
|
594
|
+
fprintf(stderr, "%s: [vBucket=%d, Index=%d]", key.c_str(), vbid, srvix);
|
595
|
+
if (srvix != -1) {
|
596
|
+
fprintf(stderr, " Server: %s",
|
597
|
+
lcbvb_get_hostport(vbc, srvix, LCBVB_SVCTYPE_DATA, LCBVB_SVCMODE_PLAIN));
|
598
|
+
const char *vapi = lcbvb_get_capibase(vbc, srvix, LCBVB_SVCMODE_PLAIN);
|
599
|
+
if (vapi) {
|
600
|
+
fprintf(stderr, ", CouchAPI: %s", vapi);
|
601
|
+
}
|
602
|
+
}
|
603
|
+
fprintf(stderr, "\n");
|
604
|
+
|
605
|
+
for (size_t jj = 0; jj < lcbvb_get_nreplicas(vbc); jj++) {
|
606
|
+
int rix = lcbvb_vbreplica(vbc, vbid, jj);
|
607
|
+
const char *rname = NULL;
|
608
|
+
if (rix >= 0) {
|
609
|
+
rname = lcbvb_get_hostport(vbc, rix, LCBVB_SVCTYPE_DATA, LCBVB_SVCMODE_PLAIN);
|
610
|
+
}
|
611
|
+
if (rname == NULL) {
|
612
|
+
rname = "N/A";
|
613
|
+
}
|
614
|
+
fprintf(stderr, "Replica #%d: Index=%d, Host=%s\n", (int)jj, rix, rname);
|
615
|
+
}
|
616
|
+
}
|
617
|
+
}
|
618
|
+
|
619
|
+
void
|
620
|
+
ObserveHandler::run()
|
621
|
+
{
|
622
|
+
Handler::run();
|
623
|
+
lcb_install_callback3(instance, LCB_CALLBACK_OBSERVE, (lcb_RESPCALLBACK)observe_callback);
|
624
|
+
const vector<string>& keys = parser.getRestArgs();
|
625
|
+
lcb_MULTICMD_CTX *mctx = lcb_observe3_ctxnew(instance);
|
626
|
+
if (mctx == NULL) {
|
627
|
+
throw std::bad_alloc();
|
628
|
+
}
|
629
|
+
|
630
|
+
lcb_error_t err;
|
631
|
+
for (size_t ii = 0; ii < keys.size(); ii++) {
|
632
|
+
lcb_CMDOBSERVE cmd = { 0 };
|
633
|
+
LCB_KREQ_SIMPLE(&cmd.key, keys[ii].c_str(), keys[ii].size());
|
634
|
+
err = mctx->addcmd(mctx, (lcb_CMDBASE*)&cmd);
|
635
|
+
if (err != LCB_SUCCESS) {
|
636
|
+
throw LcbError(err);
|
637
|
+
}
|
638
|
+
}
|
639
|
+
|
640
|
+
lcb_sched_enter(instance);
|
641
|
+
err = mctx->done(mctx, NULL);
|
642
|
+
if (err == LCB_SUCCESS) {
|
643
|
+
lcb_sched_leave(instance);
|
644
|
+
lcb_wait(instance);
|
645
|
+
} else {
|
646
|
+
lcb_sched_fail(instance);
|
647
|
+
throw LcbError(err);
|
648
|
+
}
|
649
|
+
}
|
650
|
+
|
651
|
+
void
|
652
|
+
ObserveSeqnoHandler::run()
|
653
|
+
{
|
654
|
+
Handler::run();
|
655
|
+
lcb_install_callback3(instance, LCB_CALLBACK_OBSEQNO, (lcb_RESPCALLBACK)obseqno_callback);
|
656
|
+
const vector<string>& infos = parser.getRestArgs();
|
657
|
+
lcb_CMDOBSEQNO cmd = { 0 };
|
658
|
+
lcbvb_CONFIG *vbc;
|
659
|
+
lcb_error_t rc;
|
660
|
+
|
661
|
+
rc = lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_VBCONFIG, &vbc);
|
662
|
+
if (rc != LCB_SUCCESS) {
|
663
|
+
throw LcbError(rc);
|
664
|
+
}
|
665
|
+
|
666
|
+
lcb_sched_enter(instance);
|
667
|
+
|
668
|
+
for (size_t ii = 0; ii < infos.size(); ++ii) {
|
669
|
+
const string& cur = infos[ii];
|
670
|
+
unsigned vbid;
|
671
|
+
unsigned long long uuid;
|
672
|
+
int rv = sscanf(cur.c_str(), "%u,%llu", &vbid, &uuid);
|
673
|
+
if (rv != 2) {
|
674
|
+
throw BadArg("Must pass sequences of base10 vbid and base16 uuids");
|
675
|
+
}
|
676
|
+
cmd.uuid = uuid;
|
677
|
+
cmd.vbid = vbid;
|
678
|
+
for (size_t jj = 0; jj < lcbvb_get_nreplicas(vbc) + 1; ++jj) {
|
679
|
+
int ix = lcbvb_vbserver(vbc, vbid, jj);
|
680
|
+
if (ix < 0) {
|
681
|
+
fprintf(stderr, "Server %d unavailable (skipping)\n", ix);
|
682
|
+
}
|
683
|
+
cmd.server_index = ix;
|
684
|
+
rc = lcb_observe_seqno3(instance, NULL, &cmd);
|
685
|
+
if (rc != LCB_SUCCESS) {
|
686
|
+
throw LcbError(rc);
|
687
|
+
}
|
688
|
+
}
|
689
|
+
}
|
690
|
+
lcb_sched_leave(instance);
|
691
|
+
lcb_wait(instance);
|
692
|
+
}
|
693
|
+
|
694
|
+
void
|
695
|
+
UnlockHandler::run()
|
696
|
+
{
|
697
|
+
Handler::run();
|
698
|
+
lcb_install_callback3(instance, LCB_CALLBACK_UNLOCK, common_callback);
|
699
|
+
const vector<string>& args = parser.getRestArgs();
|
700
|
+
|
701
|
+
if (args.size() % 2) {
|
702
|
+
throw BadArg("Expect key-cas pairs. Argument list must be even");
|
703
|
+
}
|
704
|
+
|
705
|
+
lcb_sched_enter(instance);
|
706
|
+
for (size_t ii = 0; ii < args.size(); ii += 2) {
|
707
|
+
const string& key = args[ii];
|
708
|
+
lcb_CAS cas;
|
709
|
+
int rv;
|
710
|
+
rv = sscanf(args[ii+1].c_str(), "0x%" PRIx64, &cas);
|
711
|
+
if (rv != 1) {
|
712
|
+
throw BadArg("CAS must be formatted as a hex string beginning with '0x'");
|
713
|
+
}
|
714
|
+
|
715
|
+
lcb_CMDUNLOCK cmd;
|
716
|
+
memset(&cmd, 0, sizeof cmd);
|
717
|
+
LCB_KREQ_SIMPLE(&cmd.key, key.c_str(), key.size());
|
718
|
+
cmd.cas = cas;
|
719
|
+
lcb_error_t err = lcb_unlock3(instance, NULL, &cmd);
|
720
|
+
if (err != LCB_SUCCESS) {
|
721
|
+
throw LcbError(err);
|
722
|
+
}
|
723
|
+
}
|
724
|
+
lcb_sched_leave(instance);
|
725
|
+
lcb_wait(instance);
|
726
|
+
}
|
727
|
+
|
728
|
+
static const char *
|
729
|
+
iops_to_string(lcb_io_ops_type_t type)
|
730
|
+
{
|
731
|
+
switch (type) {
|
732
|
+
case LCB_IO_OPS_LIBEV: return "libev";
|
733
|
+
case LCB_IO_OPS_LIBEVENT: return "libevent";
|
734
|
+
case LCB_IO_OPS_LIBUV: return "libuv";
|
735
|
+
case LCB_IO_OPS_SELECT: return "select";
|
736
|
+
case LCB_IO_OPS_WINIOCP: return "iocp";
|
737
|
+
case LCB_IO_OPS_INVALID: return "user-defined";
|
738
|
+
default: return "invalid";
|
739
|
+
}
|
740
|
+
}
|
741
|
+
|
742
|
+
void
|
743
|
+
VersionHandler::run()
|
744
|
+
{
|
745
|
+
const char *changeset;
|
746
|
+
lcb_error_t err;
|
747
|
+
err = lcb_cntl(NULL, LCB_CNTL_GET, LCB_CNTL_CHANGESET, (void*)&changeset);
|
748
|
+
if (err != LCB_SUCCESS) {
|
749
|
+
changeset = "UNKNOWN";
|
750
|
+
}
|
751
|
+
fprintf(stderr, "cbc:\n");
|
752
|
+
fprintf(stderr, " Runtime: Version=%s, Changeset=%s\n",
|
753
|
+
lcb_get_version(NULL), changeset);
|
754
|
+
fprintf(stderr, " Headers: Version=%s, Changeset=%s\n",
|
755
|
+
LCB_VERSION_STRING, LCB_VERSION_CHANGESET);
|
756
|
+
|
757
|
+
struct lcb_cntl_iops_info_st info;
|
758
|
+
memset(&info, 0, sizeof info);
|
759
|
+
err = lcb_cntl(NULL, LCB_CNTL_GET, LCB_CNTL_IOPS_DEFAULT_TYPES, &info);
|
760
|
+
if (err == LCB_SUCCESS) {
|
761
|
+
fprintf(stderr, " IO: Default=%s, Current=%s\n",
|
762
|
+
iops_to_string(info.v.v0.os_default), iops_to_string(info.v.v0.effective));
|
763
|
+
}
|
764
|
+
printf(" SSL: .. %s\n",
|
765
|
+
lcb_supports_feature(LCB_SUPPORTS_SSL) ? "SUPPORTED" : "NOT SUPPORTED");
|
766
|
+
}
|
767
|
+
|
768
|
+
void
|
769
|
+
RemoveHandler::run()
|
770
|
+
{
|
771
|
+
Handler::run();
|
772
|
+
const vector<string> &keys = parser.getRestArgs();
|
773
|
+
lcb_sched_enter(instance);
|
774
|
+
lcb_install_callback3(instance, LCB_CALLBACK_REMOVE, common_callback);
|
775
|
+
for (size_t ii = 0; ii < keys.size(); ++ii) {
|
776
|
+
lcb_CMDREMOVE cmd;
|
777
|
+
const string& key = keys[ii];
|
778
|
+
memset(&cmd, 0, sizeof cmd);
|
779
|
+
LCB_KREQ_SIMPLE(&cmd.key, key.c_str(), key.size());
|
780
|
+
lcb_error_t err = lcb_remove3(instance, NULL, &cmd);
|
781
|
+
if (err != LCB_SUCCESS) {
|
782
|
+
throw LcbError(err);
|
783
|
+
}
|
784
|
+
}
|
785
|
+
lcb_sched_leave(instance);
|
786
|
+
lcb_wait(instance);
|
787
|
+
}
|
788
|
+
|
789
|
+
void
|
790
|
+
StatsHandler::run()
|
791
|
+
{
|
792
|
+
Handler::run();
|
793
|
+
lcb_install_callback3(instance, LCB_CALLBACK_STATS, (lcb_RESPCALLBACK)stats_callback);
|
794
|
+
vector<string> keys = parser.getRestArgs();
|
795
|
+
if (keys.empty()) {
|
796
|
+
keys.push_back("");
|
797
|
+
}
|
798
|
+
lcb_sched_enter(instance);
|
799
|
+
for (size_t ii = 0; ii < keys.size(); ii++) {
|
800
|
+
lcb_CMDSTATS cmd = { 0 };
|
801
|
+
const string& key = keys[ii];
|
802
|
+
if (!key.empty()) {
|
803
|
+
LCB_KREQ_SIMPLE(&cmd.key, key.c_str(), key.size());
|
804
|
+
if (o_keystats.result()) {
|
805
|
+
cmd.cmdflags = LCB_CMDSTATS_F_KV;
|
806
|
+
}
|
807
|
+
}
|
808
|
+
bool is_keystats = o_keystats.result();
|
809
|
+
lcb_error_t err = lcb_stats3(instance, &is_keystats, &cmd);
|
810
|
+
if (err != LCB_SUCCESS) {
|
811
|
+
throw LcbError(err);
|
812
|
+
}
|
813
|
+
}
|
814
|
+
lcb_sched_leave(instance);
|
815
|
+
lcb_wait(instance);
|
816
|
+
}
|
817
|
+
|
818
|
+
void
|
819
|
+
VerbosityHandler::run()
|
820
|
+
{
|
821
|
+
Handler::run();
|
822
|
+
|
823
|
+
const string& slevel = getRequiredArg();
|
824
|
+
lcb_verbosity_level_t level;
|
825
|
+
if (slevel == "detail") {
|
826
|
+
level = LCB_VERBOSITY_DETAIL;
|
827
|
+
} else if (slevel == "debug") {
|
828
|
+
level = LCB_VERBOSITY_DEBUG;
|
829
|
+
} else if (slevel == "info") {
|
830
|
+
level = LCB_VERBOSITY_INFO;
|
831
|
+
} else if (slevel == "warning") {
|
832
|
+
level = LCB_VERBOSITY_WARNING;
|
833
|
+
} else {
|
834
|
+
throw BadArg("Verbosity level must be {detail,debug,info,warning}");
|
835
|
+
}
|
836
|
+
|
837
|
+
lcb_install_callback3(instance, LCB_CALLBACK_VERBOSITY, (lcb_RESPCALLBACK)common_server_callback);
|
838
|
+
lcb_CMDVERBOSITY cmd = { 0 };
|
839
|
+
cmd.level = level;
|
840
|
+
lcb_error_t err;
|
841
|
+
lcb_sched_enter(instance);
|
842
|
+
err = lcb_server_verbosity3(instance, NULL, &cmd);
|
843
|
+
if (err != LCB_SUCCESS) {
|
844
|
+
throw LcbError(err);
|
845
|
+
}
|
846
|
+
lcb_sched_leave(instance);
|
847
|
+
lcb_wait(instance);
|
848
|
+
}
|
849
|
+
|
850
|
+
void
|
851
|
+
McFlushHandler::run()
|
852
|
+
{
|
853
|
+
Handler::run();
|
854
|
+
|
855
|
+
lcb_CMDFLUSH cmd = { 0 };
|
856
|
+
lcb_error_t err;
|
857
|
+
lcb_install_callback3(instance, LCB_CALLBACK_FLUSH, (lcb_RESPCALLBACK)common_server_callback);
|
858
|
+
lcb_sched_enter(instance);
|
859
|
+
err = lcb_flush3(instance, NULL, &cmd);
|
860
|
+
if (err != LCB_SUCCESS) {
|
861
|
+
throw LcbError(err);
|
862
|
+
}
|
863
|
+
lcb_sched_leave(instance);
|
864
|
+
lcb_wait(instance);
|
865
|
+
}
|
866
|
+
|
867
|
+
|
868
|
+
extern "C" {
|
869
|
+
static void cbFlushCb(lcb_t, int, const lcb_RESPBASE *resp)
|
870
|
+
{
|
871
|
+
if (resp->rc == LCB_SUCCESS) {
|
872
|
+
fprintf(stderr, "Flush OK\n");
|
873
|
+
} else {
|
874
|
+
fprintf(stderr, "Flush failed: %s (0x%x)\n",
|
875
|
+
lcb_strerror(NULL, resp->rc), resp->rc);
|
876
|
+
}
|
877
|
+
}
|
878
|
+
}
|
879
|
+
void
|
880
|
+
BucketFlushHandler::run()
|
881
|
+
{
|
882
|
+
Handler::run();
|
883
|
+
lcb_CMDCBFLUSH cmd = { 0 };
|
884
|
+
lcb_error_t err;
|
885
|
+
lcb_install_callback3(instance, LCB_CALLBACK_CBFLUSH, cbFlushCb);
|
886
|
+
err = lcb_cbflush3(instance, NULL, &cmd);
|
887
|
+
if (err != LCB_SUCCESS) {
|
888
|
+
throw LcbError(err);
|
889
|
+
} else {
|
890
|
+
lcb_wait(instance);
|
891
|
+
}
|
892
|
+
}
|
893
|
+
|
894
|
+
void
|
895
|
+
ArithmeticHandler::run()
|
896
|
+
{
|
897
|
+
Handler::run();
|
898
|
+
|
899
|
+
const vector<string>& keys = parser.getRestArgs();
|
900
|
+
lcb_install_callback3(instance, LCB_CALLBACK_COUNTER, (lcb_RESPCALLBACK)arithmetic_callback);
|
901
|
+
lcb_sched_enter(instance);
|
902
|
+
for (size_t ii = 0; ii < keys.size(); ++ii) {
|
903
|
+
const string& key = keys[ii];
|
904
|
+
lcb_CMDCOUNTER cmd = { 0 };
|
905
|
+
LCB_KREQ_SIMPLE(&cmd.key, key.c_str(), key.size());
|
906
|
+
if (o_initial.passed()) {
|
907
|
+
cmd.create = 1;
|
908
|
+
cmd.initial = o_initial.result();
|
909
|
+
}
|
910
|
+
cmd.delta = getDelta();
|
911
|
+
cmd.exptime = o_expiry.result();
|
912
|
+
lcb_error_t err = lcb_counter3(instance, NULL, &cmd);
|
913
|
+
if (err != LCB_SUCCESS) {
|
914
|
+
throw LcbError(err);
|
915
|
+
}
|
916
|
+
}
|
917
|
+
lcb_sched_leave(instance);
|
918
|
+
lcb_wait(instance);
|
919
|
+
}
|
920
|
+
|
921
|
+
void
|
922
|
+
ViewsHandler::run()
|
923
|
+
{
|
924
|
+
Handler::run();
|
925
|
+
|
926
|
+
const string& s = getRequiredArg();
|
927
|
+
size_t pos = s.find('/');
|
928
|
+
if (pos == string::npos) {
|
929
|
+
throw BadArg("View must be in the format of design/view");
|
930
|
+
}
|
931
|
+
|
932
|
+
string ddoc = s.substr(0, pos);
|
933
|
+
string view = s.substr(pos+1);
|
934
|
+
string opts = o_params.result();
|
935
|
+
|
936
|
+
lcb_CMDVIEWQUERY cmd = { 0 };
|
937
|
+
lcb_view_query_initcmd(&cmd,
|
938
|
+
ddoc.c_str(), view.c_str(), opts.c_str(), view_callback);
|
939
|
+
if (o_spatial) {
|
940
|
+
cmd.cmdflags |= LCB_CMDVIEWQUERY_F_SPATIAL;
|
941
|
+
}
|
942
|
+
if (o_incdocs) {
|
943
|
+
cmd.cmdflags |= LCB_CMDVIEWQUERY_F_INCLUDE_DOCS;
|
944
|
+
}
|
945
|
+
|
946
|
+
lcb_error_t rc;
|
947
|
+
rc = lcb_view_query(instance, NULL, &cmd);
|
948
|
+
if (rc != LCB_SUCCESS) {
|
949
|
+
throw LcbError(rc);
|
950
|
+
}
|
951
|
+
lcb_wait(instance);
|
952
|
+
}
|
953
|
+
|
954
|
+
static void
|
955
|
+
splitKvParam(const string& src, string& key, string& value)
|
956
|
+
{
|
957
|
+
size_t pp = src.find('=');
|
958
|
+
if (pp == string::npos) {
|
959
|
+
throw BadArg("Param must be in the form of key=value");
|
960
|
+
}
|
961
|
+
|
962
|
+
key = src.substr(0, pp);
|
963
|
+
value = src.substr(pp+1);
|
964
|
+
}
|
965
|
+
|
966
|
+
extern "C" {
|
967
|
+
static void n1qlCallback(lcb_t, int, const lcb_RESPN1QL *resp)
|
968
|
+
{
|
969
|
+
if (resp->rflags & LCB_RESP_F_FINAL) {
|
970
|
+
fprintf(stderr, "** N1QL Response finished\n");
|
971
|
+
if (resp->rc != LCB_SUCCESS) {
|
972
|
+
fprintf(stderr, "N1QL query failed with library code 0x%x\n", resp->rc);
|
973
|
+
if (resp->htresp) {
|
974
|
+
fprintf(stderr, "Inner HTTP request failed with library code 0x%x and HTTP status %d\n",
|
975
|
+
resp->htresp->rc, resp->htresp->htstatus);
|
976
|
+
}
|
977
|
+
}
|
978
|
+
if (resp->row) {
|
979
|
+
printf("%.*s\n", (int)resp->nrow, resp->row);
|
980
|
+
}
|
981
|
+
} else {
|
982
|
+
printf("%.*s,\n", (int)resp->nrow, resp->row);
|
983
|
+
}
|
984
|
+
}
|
985
|
+
}
|
986
|
+
|
987
|
+
void
|
988
|
+
N1qlHandler::run()
|
989
|
+
{
|
990
|
+
Handler::run();
|
991
|
+
const string& qstr = getRequiredArg();
|
992
|
+
|
993
|
+
lcb_N1QLPARAMS *nparams = lcb_n1p_new();
|
994
|
+
lcb_error_t rc;
|
995
|
+
|
996
|
+
rc = lcb_n1p_setquery(nparams, qstr.c_str(), -1, LCB_N1P_QUERY_STATEMENT);
|
997
|
+
if (rc != LCB_SUCCESS) {
|
998
|
+
throw LcbError(rc);
|
999
|
+
}
|
1000
|
+
|
1001
|
+
const vector<string>& vv_args = o_args.const_result();
|
1002
|
+
for (size_t ii = 0; ii < vv_args.size(); ii++) {
|
1003
|
+
string key, value;
|
1004
|
+
splitKvParam(vv_args[ii], key, value);
|
1005
|
+
string ktmp = "$" + key;
|
1006
|
+
rc = lcb_n1p_namedparamz(nparams, ktmp.c_str(), value.c_str());
|
1007
|
+
if (rc != LCB_SUCCESS) {
|
1008
|
+
throw LcbError(rc);
|
1009
|
+
}
|
1010
|
+
}
|
1011
|
+
|
1012
|
+
const vector<string>& vv_opts = o_opts.const_result();
|
1013
|
+
for (size_t ii = 0; ii < vv_opts.size(); ii++) {
|
1014
|
+
string key, value;
|
1015
|
+
splitKvParam(vv_opts[ii], key, value);
|
1016
|
+
rc = lcb_n1p_setoptz(nparams, key.c_str(), value.c_str());
|
1017
|
+
if (rc != LCB_SUCCESS) {
|
1018
|
+
throw LcbError(rc);
|
1019
|
+
}
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
lcb_CMDN1QL cmd = { 0 };
|
1023
|
+
rc = lcb_n1p_mkcmd(nparams, &cmd);
|
1024
|
+
if (rc != LCB_SUCCESS) {
|
1025
|
+
throw LcbError(rc);
|
1026
|
+
}
|
1027
|
+
if (o_prepare.passed()) {
|
1028
|
+
cmd.cmdflags |= LCB_CMDN1QL_F_PREPCACHE;
|
1029
|
+
}
|
1030
|
+
fprintf(stderr, "Encoded query: %.*s\n", (int)cmd.nquery, cmd.query);
|
1031
|
+
cmd.callback = n1qlCallback;
|
1032
|
+
rc = lcb_n1ql_query(instance, NULL, &cmd);
|
1033
|
+
if (rc != LCB_SUCCESS) {
|
1034
|
+
throw LcbError(rc);
|
1035
|
+
}
|
1036
|
+
lcb_n1p_free(nparams);
|
1037
|
+
lcb_wait(instance);
|
1038
|
+
}
|
1039
|
+
|
1040
|
+
void
|
1041
|
+
HttpReceiver::install(lcb_t instance)
|
1042
|
+
{
|
1043
|
+
lcb_install_callback3(instance, LCB_CALLBACK_HTTP,
|
1044
|
+
(lcb_RESPCALLBACK)http_callback);
|
1045
|
+
}
|
1046
|
+
|
1047
|
+
void
|
1048
|
+
HttpReceiver::maybeInvokeStatus(const lcb_RESPHTTP *resp)
|
1049
|
+
{
|
1050
|
+
if (statusInvoked) {
|
1051
|
+
return;
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
statusInvoked = true;
|
1055
|
+
if (resp->headers) {
|
1056
|
+
for (const char * const *cur = resp->headers; *cur; cur += 2) {
|
1057
|
+
string key = cur[0];
|
1058
|
+
string value = cur[1];
|
1059
|
+
headers[key] = value;
|
1060
|
+
}
|
1061
|
+
}
|
1062
|
+
handleStatus(resp->rc, resp->htstatus);
|
1063
|
+
}
|
1064
|
+
|
1065
|
+
void
|
1066
|
+
HttpBaseHandler::run()
|
1067
|
+
{
|
1068
|
+
Handler::run();
|
1069
|
+
install(instance);
|
1070
|
+
lcb_http_cmd_st cmd;
|
1071
|
+
memset(&cmd, 0, sizeof cmd);
|
1072
|
+
string uri = getURI();
|
1073
|
+
const string& body = getBody();
|
1074
|
+
|
1075
|
+
cmd.v.v0.method = getMethod();
|
1076
|
+
cmd.v.v0.chunked = 1;
|
1077
|
+
cmd.v.v0.path = uri.c_str();
|
1078
|
+
cmd.v.v0.npath = uri.size();
|
1079
|
+
if (!body.empty()) {
|
1080
|
+
cmd.v.v0.body = body.c_str();
|
1081
|
+
cmd.v.v0.nbody = body.size();
|
1082
|
+
}
|
1083
|
+
string ctype = getContentType();
|
1084
|
+
if (!ctype.empty()) {
|
1085
|
+
cmd.v.v0.content_type = ctype.c_str();
|
1086
|
+
}
|
1087
|
+
|
1088
|
+
lcb_http_request_t dummy;
|
1089
|
+
lcb_error_t err;
|
1090
|
+
err = lcb_make_http_request(instance, (HttpReceiver*)this,
|
1091
|
+
isAdmin() ? LCB_HTTP_TYPE_MANAGEMENT : LCB_HTTP_TYPE_VIEW,
|
1092
|
+
&cmd, &dummy);
|
1093
|
+
if (err != LCB_SUCCESS) {
|
1094
|
+
throw LcbError(err);
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
lcb_wait(instance);
|
1098
|
+
}
|
1099
|
+
|
1100
|
+
lcb_http_method_t
|
1101
|
+
HttpBaseHandler::getMethod()
|
1102
|
+
{
|
1103
|
+
string smeth = o_method.result();
|
1104
|
+
if (smeth == "GET") {
|
1105
|
+
return LCB_HTTP_METHOD_GET;
|
1106
|
+
} else if (smeth == "POST") {
|
1107
|
+
return LCB_HTTP_METHOD_POST;
|
1108
|
+
} else if (smeth == "DELETE") {
|
1109
|
+
return LCB_HTTP_METHOD_DELETE;
|
1110
|
+
} else if (smeth == "PUT") {
|
1111
|
+
return LCB_HTTP_METHOD_PUT;
|
1112
|
+
} else {
|
1113
|
+
throw BadArg("Unrecognized method string");
|
1114
|
+
}
|
1115
|
+
}
|
1116
|
+
|
1117
|
+
const string&
|
1118
|
+
HttpBaseHandler::getBody()
|
1119
|
+
{
|
1120
|
+
if (!body_cached.empty()) {
|
1121
|
+
return body_cached;
|
1122
|
+
}
|
1123
|
+
lcb_http_method_t meth = getMethod();
|
1124
|
+
if (meth == LCB_HTTP_METHOD_GET || meth == LCB_HTTP_METHOD_DELETE) {
|
1125
|
+
return body_cached; // empty
|
1126
|
+
}
|
1127
|
+
|
1128
|
+
char buf[4096];
|
1129
|
+
size_t nr;
|
1130
|
+
while ( (nr = fread(buf, 1, sizeof buf, stdin)) != 0) {
|
1131
|
+
body_cached.append(buf, nr);
|
1132
|
+
}
|
1133
|
+
return body_cached;
|
1134
|
+
}
|
1135
|
+
|
1136
|
+
void
|
1137
|
+
HttpBaseHandler::handleStatus(lcb_error_t err, int code)
|
1138
|
+
{
|
1139
|
+
if (err != LCB_SUCCESS) {
|
1140
|
+
fprintf(stderr, "ERROR=0x%x (%s) ", err, lcb_strerror(NULL, err));
|
1141
|
+
}
|
1142
|
+
fprintf(stderr, "%d\n", code);
|
1143
|
+
map<string,string>::const_iterator ii = headers.begin();
|
1144
|
+
for (; ii != headers.end(); ii++) {
|
1145
|
+
fprintf(stderr, " %s: %s\n", ii->first.c_str(), ii->second.c_str());
|
1146
|
+
}
|
1147
|
+
}
|
1148
|
+
|
1149
|
+
string
|
1150
|
+
AdminHandler::getURI()
|
1151
|
+
{
|
1152
|
+
return getRequiredArg();
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
void
|
1156
|
+
AdminHandler::run()
|
1157
|
+
{
|
1158
|
+
fprintf(stderr, "Requesting %s\n", getURI().c_str());
|
1159
|
+
HttpBaseHandler::run();
|
1160
|
+
printf("%s", resbuf.c_str());
|
1161
|
+
}
|
1162
|
+
|
1163
|
+
void
|
1164
|
+
BucketCreateHandler::run()
|
1165
|
+
{
|
1166
|
+
const string& name = getRequiredArg();
|
1167
|
+
const string& btype = o_btype.const_result();
|
1168
|
+
stringstream ss;
|
1169
|
+
|
1170
|
+
if (btype == "couchbase" || btype == "membase") {
|
1171
|
+
isMemcached = false;
|
1172
|
+
} else if (btype == "memcached") {
|
1173
|
+
isMemcached = true;
|
1174
|
+
} else {
|
1175
|
+
throw BadArg("Unrecognized bucket type");
|
1176
|
+
}
|
1177
|
+
if (o_proxyport.passed() && o_bpass.passed()) {
|
1178
|
+
throw BadArg("Custom ASCII port is only available for auth-less buckets");
|
1179
|
+
}
|
1180
|
+
|
1181
|
+
ss << "name=" << name;
|
1182
|
+
ss << "&bucketType=" << btype;
|
1183
|
+
ss << "&ramQuotaMB=" << o_ramquota.result();
|
1184
|
+
if (o_proxyport.passed()) {
|
1185
|
+
ss << "&authType=none&proxyPort=" << o_proxyport.result();
|
1186
|
+
} else {
|
1187
|
+
ss << "&authType=sasl&saslPassword=" << o_bpass.result();
|
1188
|
+
}
|
1189
|
+
|
1190
|
+
ss << "&replicaNumber=" << o_replicas.result();
|
1191
|
+
body_s = ss.str();
|
1192
|
+
|
1193
|
+
AdminHandler::run();
|
1194
|
+
}
|
1195
|
+
|
1196
|
+
struct HostEnt {
|
1197
|
+
string protostr;
|
1198
|
+
string hostname;
|
1199
|
+
HostEnt(const std::string& host, const char *proto) {
|
1200
|
+
protostr = proto;
|
1201
|
+
hostname = host;
|
1202
|
+
}
|
1203
|
+
HostEnt(const std::string& host, const char* proto, int port) {
|
1204
|
+
protostr = proto;
|
1205
|
+
hostname = host;
|
1206
|
+
stringstream ss;
|
1207
|
+
ss << std::dec << port;
|
1208
|
+
hostname += ":";
|
1209
|
+
hostname += ss.str();
|
1210
|
+
}
|
1211
|
+
};
|
1212
|
+
|
1213
|
+
void
|
1214
|
+
ConnstrHandler::run()
|
1215
|
+
{
|
1216
|
+
const string& connstr_s = getRequiredArg();
|
1217
|
+
lcb_error_t err;
|
1218
|
+
const char *errmsg;
|
1219
|
+
lcb::Connspec spec;
|
1220
|
+
memset(&spec, 0, sizeof spec);
|
1221
|
+
err = spec.parse(connstr_s.c_str(), &errmsg);
|
1222
|
+
if (err != LCB_SUCCESS) {
|
1223
|
+
throw BadArg(errmsg);
|
1224
|
+
}
|
1225
|
+
|
1226
|
+
printf("Bucket: %s\n", spec.bucket().c_str());
|
1227
|
+
printf("Implicit port: %d\n", spec.default_port());
|
1228
|
+
string sslOpts;
|
1229
|
+
if (spec.sslopts() & LCB_SSL_ENABLED) {
|
1230
|
+
sslOpts = "ENABLED";
|
1231
|
+
if (spec.sslopts() & LCB_SSL_NOVERIFY) {
|
1232
|
+
sslOpts += "|NOVERIFY";
|
1233
|
+
}
|
1234
|
+
}
|
1235
|
+
printf("SSL: %s\n", sslOpts.c_str());
|
1236
|
+
|
1237
|
+
printf("Boostrap Protocols: ");
|
1238
|
+
string bsStr;
|
1239
|
+
if (spec.is_bs_cccp()) {
|
1240
|
+
bsStr += "CCCP, ";
|
1241
|
+
}
|
1242
|
+
if (spec.is_bs_http()) {
|
1243
|
+
bsStr += "HTTP, ";
|
1244
|
+
}
|
1245
|
+
if (bsStr.empty()) {
|
1246
|
+
bsStr = "CCCP,HTTP";
|
1247
|
+
} else {
|
1248
|
+
bsStr.erase(bsStr.size()-1, 1);
|
1249
|
+
}
|
1250
|
+
printf("%s\n", bsStr.c_str());
|
1251
|
+
printf("Hosts:\n");
|
1252
|
+
vector<HostEnt> hosts;
|
1253
|
+
|
1254
|
+
for (size_t ii = 0; ii < spec.hosts().size(); ++ii) {
|
1255
|
+
const lcb::Spechost *dh = &spec.hosts()[ii];
|
1256
|
+
lcb_U16 port = dh->port;
|
1257
|
+
if (!port) {
|
1258
|
+
port = spec.default_port();
|
1259
|
+
}
|
1260
|
+
|
1261
|
+
if (dh->type == LCB_CONFIG_MCD_PORT) {
|
1262
|
+
hosts.push_back(HostEnt(dh->hostname, "memcached", port));
|
1263
|
+
} else if (dh->type == LCB_CONFIG_MCD_SSL_PORT) {
|
1264
|
+
hosts.push_back(HostEnt(dh->hostname, "memcached+ssl", port));
|
1265
|
+
} else if (dh->type == LCB_CONFIG_HTTP_PORT) {
|
1266
|
+
hosts.push_back(HostEnt(dh->hostname, "restapi", port));
|
1267
|
+
} else if (dh->type == LCB_CONFIG_HTTP_SSL_PORT) {
|
1268
|
+
hosts.push_back(HostEnt(dh->hostname, "restapi+ssl", port));
|
1269
|
+
} else {
|
1270
|
+
if (spec.sslopts()) {
|
1271
|
+
hosts.push_back(HostEnt(dh->hostname, "memcached+ssl", LCB_CONFIG_MCD_SSL_PORT));
|
1272
|
+
hosts.push_back(HostEnt(dh->hostname, "restapi+ssl", LCB_CONFIG_HTTP_SSL_PORT));
|
1273
|
+
} else {
|
1274
|
+
hosts.push_back(HostEnt(dh->hostname, "memcached", LCB_CONFIG_MCD_PORT));
|
1275
|
+
hosts.push_back(HostEnt(dh->hostname, "restapi", LCB_CONFIG_HTTP_PORT));
|
1276
|
+
}
|
1277
|
+
}
|
1278
|
+
}
|
1279
|
+
for (size_t ii = 0; ii < hosts.size(); ii++) {
|
1280
|
+
HostEnt& ent = hosts[ii];
|
1281
|
+
string protostr = "[" + ent.protostr + "]";
|
1282
|
+
printf(" %-20s%s\n", protostr.c_str(), ent.hostname.c_str());
|
1283
|
+
}
|
1284
|
+
|
1285
|
+
printf("Options: \n");
|
1286
|
+
lcb::Connspec::Options::const_iterator it = spec.options().begin();
|
1287
|
+
for (; it != spec.options().end(); ++it) {
|
1288
|
+
printf(" %s=%s\n", it->first.c_str(), it->second.c_str());
|
1289
|
+
}
|
1290
|
+
}
|
1291
|
+
|
1292
|
+
void
|
1293
|
+
WriteConfigHandler::run()
|
1294
|
+
{
|
1295
|
+
lcb_create_st cropts;
|
1296
|
+
params.fillCropts(cropts);
|
1297
|
+
string outname = getLoneArg();
|
1298
|
+
if (outname.empty()) {
|
1299
|
+
outname = ConnParams::getConfigfileName();
|
1300
|
+
}
|
1301
|
+
// Generate the config
|
1302
|
+
params.writeConfig(outname);
|
1303
|
+
}
|
1304
|
+
|
1305
|
+
static map<string,Handler*> handlers;
|
1306
|
+
static map<string,Handler*> handlers_s;
|
1307
|
+
static const char* optionsOrder[] = {
|
1308
|
+
"help",
|
1309
|
+
"cat",
|
1310
|
+
"create",
|
1311
|
+
"touch",
|
1312
|
+
"observe",
|
1313
|
+
"observe-seqno",
|
1314
|
+
"incr",
|
1315
|
+
"decr",
|
1316
|
+
"mcflush",
|
1317
|
+
"hash",
|
1318
|
+
"lock",
|
1319
|
+
"unlock",
|
1320
|
+
"rm",
|
1321
|
+
"stats",
|
1322
|
+
// "verify,
|
1323
|
+
"version",
|
1324
|
+
"verbosity",
|
1325
|
+
"view",
|
1326
|
+
"n1ql",
|
1327
|
+
"admin",
|
1328
|
+
"bucket-create",
|
1329
|
+
"bucket-delete",
|
1330
|
+
"bucket-flush",
|
1331
|
+
"connstr",
|
1332
|
+
"write-config",
|
1333
|
+
"strerror",
|
1334
|
+
NULL
|
1335
|
+
};
|
1336
|
+
|
1337
|
+
class HelpHandler : public Handler {
|
1338
|
+
public:
|
1339
|
+
HelpHandler() : Handler("help") {}
|
1340
|
+
HANDLER_DESCRIPTION("Show help")
|
1341
|
+
protected:
|
1342
|
+
void run() {
|
1343
|
+
fprintf(stderr, "Usage: cbc <command> [options]\n");
|
1344
|
+
fprintf(stderr, "command may be:\n");
|
1345
|
+
for (const char ** cur = optionsOrder; *cur; cur++) {
|
1346
|
+
const Handler *handler = handlers[*cur];
|
1347
|
+
fprintf(stderr, " %-20s", *cur);
|
1348
|
+
fprintf(stderr, "%s\n", handler->description());
|
1349
|
+
}
|
1350
|
+
}
|
1351
|
+
};
|
1352
|
+
|
1353
|
+
class StrErrorHandler : public Handler {
|
1354
|
+
public:
|
1355
|
+
StrErrorHandler() : Handler("strerror") {}
|
1356
|
+
HANDLER_DESCRIPTION("Decode library error code")
|
1357
|
+
HANDLER_USAGE("HEX OR DECIMAL CODE")
|
1358
|
+
protected:
|
1359
|
+
void handleOptions() { }
|
1360
|
+
void run() {
|
1361
|
+
std::string nn = getRequiredArg();
|
1362
|
+
// Try to parse it as a hexadecimal number
|
1363
|
+
unsigned errcode;
|
1364
|
+
int rv = sscanf(nn.c_str(), "0x%x", &errcode);
|
1365
|
+
if (rv != 1) {
|
1366
|
+
rv = sscanf(nn.c_str(), "%u", &errcode);
|
1367
|
+
if (rv != 1) {
|
1368
|
+
throw BadArg("Need decimal or hex code!");
|
1369
|
+
}
|
1370
|
+
}
|
1371
|
+
|
1372
|
+
#define X(cname, code, cat, desc) \
|
1373
|
+
if (code == errcode) { \
|
1374
|
+
fprintf(stderr, "%s\n", #cname); \
|
1375
|
+
fprintf(stderr, " Type: 0x%x\n", cat); \
|
1376
|
+
fprintf(stderr, " Description: %s\n", desc); \
|
1377
|
+
return; \
|
1378
|
+
} \
|
1379
|
+
|
1380
|
+
LCB_XERR(X)
|
1381
|
+
#undef X
|
1382
|
+
|
1383
|
+
fprintf(stderr, "-- Error code not found in header. Trying runtime..\n");
|
1384
|
+
fprintf(stderr, "0x%x: %s\n", errcode, lcb_strerror(NULL, (lcb_error_t)errcode));
|
1385
|
+
}
|
1386
|
+
};
|
1387
|
+
|
1388
|
+
static void
|
1389
|
+
setupHandlers()
|
1390
|
+
{
|
1391
|
+
handlers_s["get"] = new GetHandler();
|
1392
|
+
handlers_s["create"] = new SetHandler();
|
1393
|
+
handlers_s["hash"] = new HashHandler();
|
1394
|
+
handlers_s["help"] = new HelpHandler();
|
1395
|
+
handlers_s["lock"] = new GetHandler("lock");
|
1396
|
+
handlers_s["observe"] = new ObserveHandler();
|
1397
|
+
handlers_s["unlock"] = new UnlockHandler();
|
1398
|
+
handlers_s["version"] = new VersionHandler();
|
1399
|
+
handlers_s["rm"] = new RemoveHandler();
|
1400
|
+
handlers_s["cp"] = new SetHandler("cp");
|
1401
|
+
handlers_s["stats"] = new StatsHandler();
|
1402
|
+
handlers_s["verbosity"] = new VerbosityHandler();
|
1403
|
+
handlers_s["mcflush"] = new McFlushHandler();
|
1404
|
+
handlers_s["incr"] = new IncrHandler();
|
1405
|
+
handlers_s["decr"] = new DecrHandler();
|
1406
|
+
handlers_s["admin"] = new AdminHandler();
|
1407
|
+
handlers_s["bucket-create"] = new BucketCreateHandler();
|
1408
|
+
handlers_s["bucket-delete"] = new BucketDeleteHandler();
|
1409
|
+
handlers_s["bucket-flush"] = new BucketFlushHandler();
|
1410
|
+
handlers_s["view"] = new ViewsHandler();
|
1411
|
+
handlers_s["n1ql"] = new N1qlHandler();
|
1412
|
+
handlers_s["connstr"] = new ConnstrHandler();
|
1413
|
+
handlers_s["write-config"] = new WriteConfigHandler();
|
1414
|
+
handlers_s["strerror"] = new StrErrorHandler();
|
1415
|
+
handlers_s["observe-seqno"] = new ObserveSeqnoHandler();
|
1416
|
+
handlers_s["touch"] = new TouchHandler();
|
1417
|
+
|
1418
|
+
|
1419
|
+
|
1420
|
+
map<string,Handler*>::iterator ii;
|
1421
|
+
for (ii = handlers_s.begin(); ii != handlers_s.end(); ++ii) {
|
1422
|
+
handlers[ii->first] = ii->second;
|
1423
|
+
}
|
1424
|
+
|
1425
|
+
handlers["cat"] = handlers["get"];
|
1426
|
+
}
|
1427
|
+
|
1428
|
+
#if _POSIX_VERSION >= 200112L
|
1429
|
+
#include <libgen.h>
|
1430
|
+
#define HAVE_BASENAME
|
1431
|
+
#endif
|
1432
|
+
|
1433
|
+
static void
|
1434
|
+
parseCommandname(string& cmdname, int&, char**& argv)
|
1435
|
+
{
|
1436
|
+
#ifdef HAVE_BASENAME
|
1437
|
+
cmdname = basename(argv[0]);
|
1438
|
+
size_t dashpos;
|
1439
|
+
|
1440
|
+
if (cmdname.find("cbc") != 0) {
|
1441
|
+
cmdname.clear();
|
1442
|
+
// Doesn't start with cbc
|
1443
|
+
return;
|
1444
|
+
}
|
1445
|
+
|
1446
|
+
if ((dashpos = cmdname.find('-')) != string::npos &&
|
1447
|
+
cmdname.find("cbc") != string::npos &&
|
1448
|
+
dashpos+1 < cmdname.size()) {
|
1449
|
+
|
1450
|
+
// Get the actual command name
|
1451
|
+
cmdname = cmdname.substr(dashpos+1);
|
1452
|
+
return;
|
1453
|
+
}
|
1454
|
+
#else
|
1455
|
+
(void)argv;
|
1456
|
+
#endif
|
1457
|
+
cmdname.clear();
|
1458
|
+
}
|
1459
|
+
|
1460
|
+
static void
|
1461
|
+
wrapExternalBinary(int argc, char **argv, const std::string& name)
|
1462
|
+
{
|
1463
|
+
#ifdef _POSIX_VERSION
|
1464
|
+
vector<char *> args;
|
1465
|
+
string exePath(argv[0]);
|
1466
|
+
size_t cbc_pos = exePath.find("cbc");
|
1467
|
+
|
1468
|
+
if (cbc_pos == string::npos) {
|
1469
|
+
throw BadArg("Couldn't invoke " + name);
|
1470
|
+
}
|
1471
|
+
|
1472
|
+
exePath.replace(cbc_pos, 3, name);
|
1473
|
+
args.push_back((char*)exePath.c_str());
|
1474
|
+
|
1475
|
+
// { "cbc", "name" }
|
1476
|
+
argv += 2; argc -= 2;
|
1477
|
+
for (int ii = 0; ii < argc; ii++) {
|
1478
|
+
args.push_back(argv[ii]);
|
1479
|
+
}
|
1480
|
+
args.push_back((char*)NULL);
|
1481
|
+
execvp(exePath.c_str(), &args[0]);
|
1482
|
+
perror(exePath.c_str());
|
1483
|
+
throw BadArg("Couldn't execute " + name + " !");
|
1484
|
+
#else
|
1485
|
+
throw BadArg("Can't wrap around " + name + " on non-POSIX environments");
|
1486
|
+
#endif
|
1487
|
+
}
|
1488
|
+
|
1489
|
+
int main(int argc, char **argv)
|
1490
|
+
{
|
1491
|
+
|
1492
|
+
// Wrap external binaries immediately
|
1493
|
+
if (argc >= 2) {
|
1494
|
+
if (strcmp(argv[1], "pillowfight") == 0) {
|
1495
|
+
wrapExternalBinary(argc, argv, "cbc-pillowfight");
|
1496
|
+
} else if (strcmp(argv[1], "n1qlback") == 0) {
|
1497
|
+
wrapExternalBinary(argc, argv, "cbc-n1qlback");
|
1498
|
+
}
|
1499
|
+
}
|
1500
|
+
|
1501
|
+
setupHandlers();
|
1502
|
+
string cmdname;
|
1503
|
+
parseCommandname(cmdname, argc, argv);
|
1504
|
+
|
1505
|
+
if (cmdname.empty()) {
|
1506
|
+
if (argc < 2) {
|
1507
|
+
fprintf(stderr, "Must provide an option name\n");
|
1508
|
+
try {
|
1509
|
+
HelpHandler().execute(argc, argv);
|
1510
|
+
} catch (std::exception& exc) {
|
1511
|
+
std::cerr << exc.what() << std::endl;
|
1512
|
+
}
|
1513
|
+
exit(EXIT_FAILURE);
|
1514
|
+
} else {
|
1515
|
+
cmdname = argv[1];
|
1516
|
+
argv++;
|
1517
|
+
argc--;
|
1518
|
+
}
|
1519
|
+
}
|
1520
|
+
|
1521
|
+
Handler *handler = handlers[cmdname];
|
1522
|
+
if (handler == NULL) {
|
1523
|
+
fprintf(stderr, "Unknown command %s\n", cmdname.c_str());
|
1524
|
+
HelpHandler().execute(argc, argv);
|
1525
|
+
exit(EXIT_FAILURE);
|
1526
|
+
}
|
1527
|
+
|
1528
|
+
try {
|
1529
|
+
handler->execute(argc, argv);
|
1530
|
+
|
1531
|
+
} catch (std::exception& err) {
|
1532
|
+
fprintf(stderr, "%s\n", err.what());
|
1533
|
+
exit(EXIT_FAILURE);
|
1534
|
+
}
|
1535
|
+
|
1536
|
+
map<string,Handler*>::iterator iter = handlers_s.begin();
|
1537
|
+
for (; iter != handlers_s.end(); iter++) {
|
1538
|
+
delete iter->second;
|
1539
|
+
}
|
1540
|
+
exit(EXIT_SUCCESS);
|
1541
|
+
}
|