libcouchbase 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +1 -1
  4. data/ext/libcouchbase/CMakeLists.txt +8 -6
  5. data/ext/libcouchbase/README.markdown +2 -2
  6. data/ext/libcouchbase/RELEASE_NOTES.markdown +0 -86
  7. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +0 -11
  8. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +0 -2
  9. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +1 -2
  10. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  11. data/ext/libcouchbase/cmake/config-cmake.h.in +0 -2
  12. data/ext/libcouchbase/cmake/defs.mk.in +2 -0
  13. data/ext/libcouchbase/cmake/source_files.cmake +5 -21
  14. data/ext/libcouchbase/include/libcouchbase/auth.h +0 -10
  15. data/ext/libcouchbase/include/libcouchbase/cntl.h +1 -27
  16. data/ext/libcouchbase/include/libcouchbase/error.h +1 -15
  17. data/ext/libcouchbase/include/libcouchbase/n1ql.h +1 -13
  18. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
  19. data/ext/libcouchbase/include/libcouchbase/subdoc.h +0 -9
  20. data/ext/libcouchbase/include/libcouchbase/views.h +1 -7
  21. data/ext/libcouchbase/include/libcouchbase/visibility.h +0 -1
  22. data/ext/libcouchbase/include/memcached/protocol_binary.h +1131 -29
  23. data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
  24. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  25. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +2 -3
  26. data/ext/libcouchbase/src/README.md +2 -0
  27. data/ext/libcouchbase/src/auth-priv.h +0 -1
  28. data/ext/libcouchbase/src/auth.cc +4 -10
  29. data/ext/libcouchbase/src/bootstrap.c +269 -0
  30. data/ext/libcouchbase/src/bootstrap.h +39 -50
  31. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +117 -84
  32. data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
  33. data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
  34. data/ext/libcouchbase/src/bucketconfig/bc_http.h +25 -50
  35. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
  36. data/ext/libcouchbase/src/bucketconfig/clconfig.h +386 -407
  37. data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
  38. data/ext/libcouchbase/src/cbft.cc +27 -22
  39. data/ext/libcouchbase/src/cntl.cc +19 -30
  40. data/ext/libcouchbase/src/connspec.cc +1 -48
  41. data/ext/libcouchbase/src/connspec.h +0 -27
  42. data/ext/libcouchbase/src/dump.cc +2 -2
  43. data/ext/libcouchbase/src/getconfig.cc +33 -7
  44. data/ext/libcouchbase/src/handler.cc +2 -0
  45. data/ext/libcouchbase/src/hostlist.cc +36 -0
  46. data/ext/libcouchbase/src/hostlist.h +62 -41
  47. data/ext/libcouchbase/src/http/http-priv.h +112 -125
  48. data/ext/libcouchbase/src/http/http.cc +30 -15
  49. data/ext/libcouchbase/src/http/http.h +34 -1
  50. data/ext/libcouchbase/src/http/http_io.cc +26 -22
  51. data/ext/libcouchbase/src/instance.cc +23 -94
  52. data/ext/libcouchbase/src/internal.h +26 -52
  53. data/ext/libcouchbase/src/jsparse/parser.cc +202 -146
  54. data/ext/libcouchbase/src/jsparse/parser.h +98 -91
  55. data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
  56. data/ext/libcouchbase/src/lcbht/lcbht.h +163 -174
  57. data/ext/libcouchbase/src/lcbio/connect.c +557 -0
  58. data/ext/libcouchbase/src/lcbio/connect.h +2 -9
  59. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  60. data/ext/libcouchbase/src/lcbio/iotable.h +16 -61
  61. data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
  62. data/ext/libcouchbase/src/lcbio/manager.c +2 -2
  63. data/ext/libcouchbase/src/mc/mcreq.h +2 -9
  64. data/ext/libcouchbase/src/mcserver/mcserver.cc +34 -143
  65. data/ext/libcouchbase/src/mcserver/mcserver.h +12 -7
  66. data/ext/libcouchbase/src/mcserver/negotiate.cc +38 -132
  67. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
  68. data/ext/libcouchbase/src/n1ql/n1ql.cc +32 -56
  69. data/ext/libcouchbase/src/newconfig.cc +6 -6
  70. data/ext/libcouchbase/src/nodeinfo.cc +2 -2
  71. data/ext/libcouchbase/src/operations/{cbflush.cc → cbflush.c} +15 -7
  72. data/ext/libcouchbase/src/operations/{counter.cc → counter.c} +0 -0
  73. data/ext/libcouchbase/src/operations/durability.cc +26 -6
  74. data/ext/libcouchbase/src/operations/durability_internal.h +3 -6
  75. data/ext/libcouchbase/src/operations/{get.cc → get.c} +26 -24
  76. data/ext/libcouchbase/src/operations/{observe.cc → observe.c} +93 -68
  77. data/ext/libcouchbase/src/operations/{pktfwd.cc → pktfwd.c} +0 -0
  78. data/ext/libcouchbase/src/operations/{remove.cc → remove.c} +0 -0
  79. data/ext/libcouchbase/src/operations/stats.cc +8 -3
  80. data/ext/libcouchbase/src/operations/{store.cc → store.c} +32 -27
  81. data/ext/libcouchbase/src/operations/subdoc.cc +18 -38
  82. data/ext/libcouchbase/src/operations/{touch.cc → touch.c} +0 -0
  83. data/ext/libcouchbase/src/packetutils.c +37 -0
  84. data/ext/libcouchbase/src/packetutils.h +2 -2
  85. data/ext/libcouchbase/src/probes.d +1 -1
  86. data/ext/libcouchbase/src/{retrychk.cc → retrychk.c} +3 -2
  87. data/ext/libcouchbase/src/retryq.cc +4 -4
  88. data/ext/libcouchbase/src/settings.c +0 -3
  89. data/ext/libcouchbase/src/settings.h +0 -5
  90. data/ext/libcouchbase/src/simplestring.c +211 -0
  91. data/ext/libcouchbase/src/simplestring.h +228 -0
  92. data/ext/libcouchbase/src/ssl/ssl_c.c +0 -1
  93. data/ext/libcouchbase/src/ssl/ssl_common.c +0 -2
  94. data/ext/libcouchbase/src/ssl/ssl_e.c +1 -0
  95. data/ext/libcouchbase/src/ssobuf.h +82 -0
  96. data/ext/libcouchbase/src/trace.h +4 -4
  97. data/ext/libcouchbase/src/vbucket/vbucket.c +1 -0
  98. data/ext/libcouchbase/src/views/{docreq.cc → docreq.c} +54 -48
  99. data/ext/libcouchbase/src/views/docreq.h +30 -24
  100. data/ext/libcouchbase/src/views/viewreq.c +358 -0
  101. data/ext/libcouchbase/src/views/viewreq.h +13 -43
  102. data/ext/libcouchbase/tests/basic/t_connstr.cc +50 -89
  103. data/ext/libcouchbase/tests/basic/t_host.cc +75 -67
  104. data/ext/libcouchbase/tests/basic/t_jsparse.cc +78 -27
  105. data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
  106. data/ext/libcouchbase/tests/htparse/t_basic.cc +78 -58
  107. data/ext/libcouchbase/tests/iotests/mock-environment.h +1 -2
  108. data/ext/libcouchbase/tests/iotests/t_confmon.cc +114 -96
  109. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  110. data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
  111. data/lib/libcouchbase/ext/tasks.rb +6 -2
  112. data/lib/libcouchbase/query_view.rb +1 -1
  113. data/lib/libcouchbase/results_fiber.rb +6 -6
  114. data/lib/libcouchbase/version.rb +1 -1
  115. metadata +26 -26
  116. data/ext/libcouchbase/src/bootstrap.cc +0 -216
  117. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +0 -281
  118. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +0 -528
  119. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +0 -115
  120. data/ext/libcouchbase/src/bucketconfig/confmon.cc +0 -378
  121. data/ext/libcouchbase/src/dns-srv.cc +0 -142
  122. data/ext/libcouchbase/src/errmap.cc +0 -107
  123. data/ext/libcouchbase/src/errmap.h +0 -113
  124. data/ext/libcouchbase/src/lcbht/lcbht.cc +0 -177
  125. data/ext/libcouchbase/src/lcbio/connect.cc +0 -562
  126. data/ext/libcouchbase/src/lcbio/timer-cxx.h +0 -87
  127. data/ext/libcouchbase/src/mctx-helper.h +0 -51
  128. data/ext/libcouchbase/src/views/viewreq.cc +0 -318
  129. data/ext/libcouchbase/tests/iotests/t_errmap.cc +0 -97
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true, encoding: ASCII-8BIT
2
2
 
3
3
  module Libcouchbase
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libcouchbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-05 00:00:00.000000000 Z
11
+ date: 2017-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -342,6 +342,7 @@ files:
342
342
  - ext/libcouchbase/include/memcached/COPYING
343
343
  - ext/libcouchbase/include/memcached/README
344
344
  - ext/libcouchbase/include/memcached/protocol_binary.h
345
+ - ext/libcouchbase/include/memcached/vbucket.h
345
346
  - ext/libcouchbase/packaging/README
346
347
  - ext/libcouchbase/packaging/abicheck/.gitignore
347
348
  - ext/libcouchbase/packaging/abicheck/Makefile
@@ -386,15 +387,15 @@ files:
386
387
  - ext/libcouchbase/src/aspend.h
387
388
  - ext/libcouchbase/src/auth-priv.h
388
389
  - ext/libcouchbase/src/auth.cc
389
- - ext/libcouchbase/src/bootstrap.cc
390
+ - ext/libcouchbase/src/bootstrap.c
390
391
  - ext/libcouchbase/src/bootstrap.h
391
392
  - ext/libcouchbase/src/bucketconfig/bc_cccp.cc
392
- - ext/libcouchbase/src/bucketconfig/bc_file.cc
393
- - ext/libcouchbase/src/bucketconfig/bc_http.cc
393
+ - ext/libcouchbase/src/bucketconfig/bc_file.c
394
+ - ext/libcouchbase/src/bucketconfig/bc_http.c
394
395
  - ext/libcouchbase/src/bucketconfig/bc_http.h
395
- - ext/libcouchbase/src/bucketconfig/bc_mcraw.cc
396
+ - ext/libcouchbase/src/bucketconfig/bc_mcraw.c
396
397
  - ext/libcouchbase/src/bucketconfig/clconfig.h
397
- - ext/libcouchbase/src/bucketconfig/confmon.cc
398
+ - ext/libcouchbase/src/bucketconfig/confmon.c
398
399
  - ext/libcouchbase/src/callbacks.c
399
400
  - ext/libcouchbase/src/cbft.cc
400
401
  - ext/libcouchbase/src/cntl.cc
@@ -402,10 +403,7 @@ files:
402
403
  - ext/libcouchbase/src/connspec.cc
403
404
  - ext/libcouchbase/src/connspec.h
404
405
  - ext/libcouchbase/src/ctx-log-inl.h
405
- - ext/libcouchbase/src/dns-srv.cc
406
406
  - ext/libcouchbase/src/dump.cc
407
- - ext/libcouchbase/src/errmap.cc
408
- - ext/libcouchbase/src/errmap.h
409
407
  - ext/libcouchbase/src/getconfig.cc
410
408
  - ext/libcouchbase/src/gethrtime.c
411
409
  - ext/libcouchbase/src/handler.cc
@@ -422,9 +420,9 @@ files:
422
420
  - ext/libcouchbase/src/iofactory.c
423
421
  - ext/libcouchbase/src/jsparse/parser.cc
424
422
  - ext/libcouchbase/src/jsparse/parser.h
425
- - ext/libcouchbase/src/lcbht/lcbht.cc
423
+ - ext/libcouchbase/src/lcbht/lcbht.c
426
424
  - ext/libcouchbase/src/lcbht/lcbht.h
427
- - ext/libcouchbase/src/lcbio/connect.cc
425
+ - ext/libcouchbase/src/lcbio/connect.c
428
426
  - ext/libcouchbase/src/lcbio/connect.h
429
427
  - ext/libcouchbase/src/lcbio/ctx.c
430
428
  - ext/libcouchbase/src/lcbio/ctx.h
@@ -438,7 +436,6 @@ files:
438
436
  - ext/libcouchbase/src/lcbio/protoctx.c
439
437
  - ext/libcouchbase/src/lcbio/rw-inl.h
440
438
  - ext/libcouchbase/src/lcbio/ssl.h
441
- - ext/libcouchbase/src/lcbio/timer-cxx.h
442
439
  - ext/libcouchbase/src/lcbio/timer-ng.h
443
440
  - ext/libcouchbase/src/lcbio/timer.c
444
441
  - ext/libcouchbase/src/legacy.c
@@ -459,7 +456,6 @@ files:
459
456
  - ext/libcouchbase/src/mcserver/mcserver.h
460
457
  - ext/libcouchbase/src/mcserver/negotiate.cc
461
458
  - ext/libcouchbase/src/mcserver/negotiate.h
462
- - ext/libcouchbase/src/mctx-helper.h
463
459
  - ext/libcouchbase/src/n1ql/ixmgmt.cc
464
460
  - ext/libcouchbase/src/n1ql/n1ql-internal.h
465
461
  - ext/libcouchbase/src/n1ql/n1ql.cc
@@ -470,21 +466,22 @@ files:
470
466
  - ext/libcouchbase/src/netbuf/netbuf.h
471
467
  - ext/libcouchbase/src/newconfig.cc
472
468
  - ext/libcouchbase/src/nodeinfo.cc
473
- - ext/libcouchbase/src/operations/cbflush.cc
474
- - ext/libcouchbase/src/operations/counter.cc
469
+ - ext/libcouchbase/src/operations/cbflush.c
470
+ - ext/libcouchbase/src/operations/counter.c
475
471
  - ext/libcouchbase/src/operations/durability-cas.cc
476
472
  - ext/libcouchbase/src/operations/durability-seqno.cc
477
473
  - ext/libcouchbase/src/operations/durability.cc
478
474
  - ext/libcouchbase/src/operations/durability_internal.h
479
- - ext/libcouchbase/src/operations/get.cc
475
+ - ext/libcouchbase/src/operations/get.c
480
476
  - ext/libcouchbase/src/operations/observe-seqno.cc
481
- - ext/libcouchbase/src/operations/observe.cc
482
- - ext/libcouchbase/src/operations/pktfwd.cc
483
- - ext/libcouchbase/src/operations/remove.cc
477
+ - ext/libcouchbase/src/operations/observe.c
478
+ - ext/libcouchbase/src/operations/pktfwd.c
479
+ - ext/libcouchbase/src/operations/remove.c
484
480
  - ext/libcouchbase/src/operations/stats.cc
485
- - ext/libcouchbase/src/operations/store.cc
481
+ - ext/libcouchbase/src/operations/store.c
486
482
  - ext/libcouchbase/src/operations/subdoc.cc
487
- - ext/libcouchbase/src/operations/touch.cc
483
+ - ext/libcouchbase/src/operations/touch.c
484
+ - ext/libcouchbase/src/packetutils.c
488
485
  - ext/libcouchbase/src/packetutils.h
489
486
  - ext/libcouchbase/src/probes.d
490
487
  - ext/libcouchbase/src/rdb/bigalloc.c
@@ -493,13 +490,15 @@ files:
493
490
  - ext/libcouchbase/src/rdb/libcalloc.c
494
491
  - ext/libcouchbase/src/rdb/rope.c
495
492
  - ext/libcouchbase/src/rdb/rope.h
496
- - ext/libcouchbase/src/retrychk.cc
493
+ - ext/libcouchbase/src/retrychk.c
497
494
  - ext/libcouchbase/src/retryq.cc
498
495
  - ext/libcouchbase/src/retryq.h
499
496
  - ext/libcouchbase/src/ringbuffer.c
500
497
  - ext/libcouchbase/src/ringbuffer.h
501
498
  - ext/libcouchbase/src/settings.c
502
499
  - ext/libcouchbase/src/settings.h
500
+ - ext/libcouchbase/src/simplestring.c
501
+ - ext/libcouchbase/src/simplestring.h
503
502
  - ext/libcouchbase/src/sllist-inl.h
504
503
  - ext/libcouchbase/src/sllist.h
505
504
  - ext/libcouchbase/src/ssl/CMakeLists.txt
@@ -507,6 +506,7 @@ files:
507
506
  - ext/libcouchbase/src/ssl/ssl_common.c
508
507
  - ext/libcouchbase/src/ssl/ssl_e.c
509
508
  - ext/libcouchbase/src/ssl/ssl_iot_common.h
509
+ - ext/libcouchbase/src/ssobuf.h
510
510
  - ext/libcouchbase/src/strcodecs/base64.c
511
511
  - ext/libcouchbase/src/strcodecs/strcodecs.h
512
512
  - ext/libcouchbase/src/timings.c
@@ -522,9 +522,9 @@ files:
522
522
  - ext/libcouchbase/src/vbucket/rfc1321/md5.h
523
523
  - ext/libcouchbase/src/vbucket/rfc1321/md5c-inl.h
524
524
  - ext/libcouchbase/src/vbucket/vbucket.c
525
- - ext/libcouchbase/src/views/docreq.cc
525
+ - ext/libcouchbase/src/views/docreq.c
526
526
  - ext/libcouchbase/src/views/docreq.h
527
- - ext/libcouchbase/src/views/viewreq.cc
527
+ - ext/libcouchbase/src/views/viewreq.c
528
528
  - ext/libcouchbase/src/views/viewreq.h
529
529
  - ext/libcouchbase/src/wait.cc
530
530
  - ext/libcouchbase/tests/CMakeLists.txt
@@ -545,6 +545,7 @@ files:
545
545
  - ext/libcouchbase/tests/basic/t_ringbuffer.cc
546
546
  - ext/libcouchbase/tests/basic/t_slist.cc
547
547
  - ext/libcouchbase/tests/basic/t_strerror.cc
548
+ - ext/libcouchbase/tests/basic/t_string.cc
548
549
  - ext/libcouchbase/tests/basic/t_urlencode.cc
549
550
  - ext/libcouchbase/tests/check-all.cc
550
551
  - ext/libcouchbase/tests/htparse/t_basic.cc
@@ -568,7 +569,6 @@ files:
568
569
  - ext/libcouchbase/tests/iotests/t_configcache.cc
569
570
  - ext/libcouchbase/tests/iotests/t_confmon.cc
570
571
  - ext/libcouchbase/tests/iotests/t_durability.cc
571
- - ext/libcouchbase/tests/iotests/t_errmap.cc
572
572
  - ext/libcouchbase/tests/iotests/t_forward.cc
573
573
  - ext/libcouchbase/tests/iotests/t_get.cc
574
574
  - ext/libcouchbase/tests/iotests/t_http.cc
@@ -1,216 +0,0 @@
1
- /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright 2014 Couchbase, Inc.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- #define LCB_BOOTSTRAP_DEFINE_STRUCT 1
19
- #include "internal.h"
20
-
21
-
22
- #define LOGARGS(instance, lvl) instance->settings, "bootstrap", LCB_LOG_##lvl, __FILE__, __LINE__
23
-
24
- using lcb::clconfig::EventType;
25
- using lcb::clconfig::ConfigInfo;
26
- using namespace lcb;
27
-
28
- /**
29
- * This function is where the configuration actually takes place. We ensure
30
- * in other functions that this is only ever called directly from an event
31
- * loop stack frame (or one of the small mini functions here) so that we
32
- * don't accidentally end up destroying resources underneath us.
33
- */
34
- void Bootstrap::config_callback(EventType event, ConfigInfo *info) {
35
- using namespace lcb::clconfig;
36
- lcb_t instance = parent;
37
-
38
- if (event != CLCONFIG_EVENT_GOT_NEW_CONFIG) {
39
- if (event == CLCONFIG_EVENT_PROVIDERS_CYCLED) {
40
- if (!LCBT_VBCONFIG(instance)) {
41
- initial_error(LCB_ERROR, "No more bootstrap providers remain");
42
- }
43
- }
44
- return;
45
- }
46
-
47
- instance->last_error = LCB_SUCCESS;
48
-
49
- /** Ensure we're not called directly twice again */
50
- if (state < S_INITIAL_TRIGGERED) {
51
- state = S_INITIAL_TRIGGERED;
52
- }
53
-
54
- tm.cancel();
55
-
56
- lcb_log(LOGARGS(instance, DEBUG), "Instance configured!");
57
-
58
- if (info->get_origin() != CLCONFIG_FILE) {
59
- /* Set the timestamp for the current config to control throttling,
60
- * but only if it's not an initial file-based config. See CCBC-482 */
61
- last_refresh = gethrtime();
62
- errcounter = 0;
63
- }
64
-
65
- if (info->get_origin() == CLCONFIG_CCCP) {
66
- /* Disable HTTP provider if we've received something via CCCP */
67
-
68
- if (instance->cur_configinfo == NULL ||
69
- instance->cur_configinfo->get_origin() != CLCONFIG_HTTP) {
70
- /* Never disable HTTP if it's still being used */
71
- instance->confmon->set_active(CLCONFIG_HTTP, false);
72
- }
73
- }
74
-
75
- if (instance->type != LCB_TYPE_CLUSTER) {
76
- lcb_update_vbconfig(instance, info);
77
- }
78
-
79
- if (state < S_BOOTSTRAPPED) {
80
- state = S_BOOTSTRAPPED;
81
- lcb_aspend_del(&instance->pendops, LCB_PENDTYPE_COUNTER, NULL);
82
-
83
- if (instance->type == LCB_TYPE_BUCKET &&
84
- LCBVB_DISTTYPE(LCBT_VBCONFIG(instance)) == LCBVB_DIST_KETAMA &&
85
- instance->cur_configinfo->get_origin() != CLCONFIG_MCRAW) {
86
-
87
- lcb_log(LOGARGS(instance, INFO), "Reverting to HTTP Config for memcached buckets");
88
- instance->settings->bc_http_stream_time = -1;
89
- instance->confmon->set_active(CLCONFIG_HTTP, true);
90
- instance->confmon->set_active(CLCONFIG_CCCP, false);
91
- }
92
- instance->callbacks.bootstrap(instance, LCB_SUCCESS);
93
- }
94
-
95
- lcb_maybe_breakout(instance);
96
- }
97
-
98
- void Bootstrap::clconfig_lsn(EventType e, ConfigInfo *i) {
99
- if (state == S_INITIAL_PRE) {
100
- config_callback(e, i);
101
- } else if (e == clconfig::CLCONFIG_EVENT_GOT_NEW_CONFIG) {
102
- lcb_log(LOGARGS(parent, INFO), "Got new config. Will refresh asynchronously");
103
- tm.signal();
104
- }
105
- }
106
-
107
- /**
108
- * This it the initial bootstrap timeout handler. This timeout pins down the
109
- * instance. It is only scheduled during the initial bootstrap and is only
110
- * triggered if the initial bootstrap fails to configure in time.
111
- */
112
- void Bootstrap::timer_dispatch() {
113
- if (state > S_INITIAL_PRE) {
114
- config_callback(clconfig::CLCONFIG_EVENT_GOT_NEW_CONFIG,
115
- parent->confmon->get_config());
116
- } else {
117
- // Not yet bootstrapped!
118
- initial_error(LCB_ETIMEDOUT, "Failed to bootstrap in time");
119
- }
120
- }
121
-
122
-
123
- void Bootstrap::initial_error(lcb_error_t err, const char *errinfo) {
124
- parent->last_error = parent->confmon->get_last_error();
125
- if (parent->last_error == LCB_SUCCESS) {
126
- parent->last_error = err;
127
- }
128
- parent->callbacks.error(parent, parent->last_error, errinfo);
129
- lcb_log(LOGARGS(parent, ERR), "Failed to bootstrap client=%p. Error=%s, Message=%s", (void *)parent, lcb_strerror_short(parent->last_error), errinfo);
130
- tm.cancel();
131
-
132
- parent->callbacks.bootstrap(parent, parent->last_error);
133
-
134
- lcb_aspend_del(&parent->pendops, LCB_PENDTYPE_COUNTER, NULL);
135
- lcb_maybe_breakout(parent);
136
- }
137
-
138
- Bootstrap::Bootstrap(lcb_t instance)
139
- : parent(instance),
140
- tm(parent->iotable, this),
141
- last_refresh(0),
142
- errcounter(0),
143
- state(S_INITIAL_PRE) {
144
- parent->confmon->add_listener(this);
145
- }
146
-
147
- lcb_error_t Bootstrap::bootstrap(unsigned options) {
148
- hrtime_t now = gethrtime();
149
- if (parent->confmon->is_refreshing()) {
150
- return LCB_SUCCESS;
151
- }
152
-
153
- if (options & BS_REFRESH_THROTTLE) {
154
- /* Refresh throttle requested. This is not true if options == ALWAYS */
155
- hrtime_t next_ts;
156
- unsigned errthresh = LCBT_SETTING(parent, weird_things_threshold);
157
-
158
- if (options & BS_REFRESH_INCRERR) {
159
- errcounter++;
160
- }
161
- next_ts = last_refresh;
162
- next_ts += LCB_US2NS(LCBT_SETTING(parent, weird_things_delay));
163
- if (now < next_ts && errcounter < errthresh) {
164
- lcb_log(LOGARGS(parent, INFO),
165
- "Not requesting a config refresh because of throttling parameters. Next refresh possible in %ums or %u errors. "
166
- "See LCB_CNTL_CONFDELAY_THRESH and LCB_CNTL_CONFERRTHRESH to modify the throttling settings",
167
- LCB_NS2US(next_ts-now)/1000, (unsigned)errthresh-errcounter);
168
- return LCB_SUCCESS;
169
- }
170
- }
171
-
172
- if (options == BS_REFRESH_INITIAL) {
173
- state = S_INITIAL_PRE;
174
- parent->confmon->prepare();
175
- tm.rearm(LCBT_SETTING(parent, config_timeout));
176
- lcb_aspend_add(&parent->pendops, LCB_PENDTYPE_COUNTER, NULL);
177
- }
178
-
179
- /* Reset the counters */
180
- errcounter = 0;
181
- if (options != BS_REFRESH_INITIAL) {
182
- last_refresh = now;
183
- }
184
- parent->confmon->start();
185
- return LCB_SUCCESS;
186
- }
187
-
188
- Bootstrap::~Bootstrap() {
189
- tm.release();
190
- parent->confmon->remove_listener(this);
191
- }
192
-
193
- LIBCOUCHBASE_API
194
- lcb_error_t
195
- lcb_get_bootstrap_status(lcb_t instance)
196
- {
197
- if (instance->cur_configinfo) {
198
- return LCB_SUCCESS;
199
- }
200
- if (instance->last_error != LCB_SUCCESS) {
201
- return instance->last_error;
202
- }
203
- if (instance->type == LCB_TYPE_CLUSTER) {
204
- if (lcb::clconfig::http_get_conn(instance->confmon) != NULL) {
205
- return LCB_SUCCESS;
206
- }
207
- }
208
- return LCB_ERROR;
209
- }
210
-
211
- LIBCOUCHBASE_API
212
- void
213
- lcb_refresh_config(lcb_t instance)
214
- {
215
- instance->bootstrap(BS_REFRESH_ALWAYS);
216
- }
@@ -1,281 +0,0 @@
1
- /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright 2013 Couchbase, Inc.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- #include "internal.h"
19
- #include "clconfig.h"
20
- #include <lcbio/lcbio.h>
21
- #include <lcbio/timer-ng.h>
22
- #include <lcbio/timer-cxx.h>
23
- #include <fstream>
24
- #include <iostream>
25
- #include <istream>
26
-
27
- #define CONFIG_CACHE_MAGIC "{{{fb85b563d0a8f65fa8d3d58f1b3a0708}}}"
28
-
29
- #define LOGARGS(pb, lvl) static_cast<Provider*>(pb)->parent->settings, "bc_file", LCB_LOG_##lvl, __FILE__, __LINE__
30
- #define LOGFMT "(cache=%s) "
31
- #define LOGID(fb) fb->filename.c_str()
32
-
33
- using namespace lcb::clconfig;
34
-
35
- struct FileProvider : Provider, Listener {
36
- FileProvider(Confmon* confmon);
37
- ~FileProvider();
38
-
39
- enum Status { CACHE_ERROR, NO_CHANGES, UPDATED };
40
- Status load_cache();
41
- void reload_cache();
42
- void maybe_remove_file() {
43
- if (!is_readonly && !filename.empty()) {
44
- remove(filename.c_str());
45
- }
46
- }
47
- void write_cache(lcbvb_CONFIG *vbc);
48
-
49
- /* Overrides */
50
- ConfigInfo *get_cached();
51
- lcb_error_t refresh();
52
- void dump(FILE *) const;
53
- void clconfig_lsn(EventType, ConfigInfo*);
54
-
55
- std::string filename;
56
- ConfigInfo *config;
57
- time_t last_mtime;
58
- int last_errno;
59
- bool is_readonly; /* Whether the config cache should _not_ overwrite the file */
60
- lcb::io::Timer<FileProvider, &FileProvider::reload_cache> timer;
61
- };
62
-
63
- FileProvider::Status FileProvider::load_cache()
64
- {
65
- if (filename.empty()) {
66
- return CACHE_ERROR;
67
- }
68
-
69
- std::ifstream ifs(filename.c_str(),
70
- std::ios::in | std::ios::binary | std::ios::ate);
71
-
72
- if (!ifs.is_open() || !ifs.good()) {
73
- int save_errno = last_errno = errno;
74
- lcb_log(LOGARGS(this, ERROR), LOGFMT "Couldn't open for reading: %s", LOGID(this), strerror(save_errno));
75
- return CACHE_ERROR;
76
- }
77
-
78
- struct stat st;
79
- if (stat(filename.c_str(), &st)) {
80
- last_errno = errno;
81
- return CACHE_ERROR;
82
- }
83
-
84
- if (last_mtime == st.st_mtime) {
85
- lcb_log(LOGARGS(this, WARN), LOGFMT "Modification time too old", LOGID(this));
86
- return NO_CHANGES;
87
- }
88
-
89
- size_t fsize = ifs.tellg();
90
- if (!fsize) {
91
- lcb_log(LOGARGS(this, WARN), LOGFMT "File '%s' is empty", LOGID(this), filename.c_str());
92
- return CACHE_ERROR;
93
- }
94
- ifs.seekg(0, std::ios::beg);
95
- std::vector<char> buf(fsize);
96
- ifs.read(&buf[0], fsize);
97
- buf.push_back(0); // NUL termination
98
-
99
- char *end = std::strstr(&buf[0], CONFIG_CACHE_MAGIC);
100
- if (end == NULL) {
101
- lcb_log(LOGARGS(this, ERROR), LOGFMT "Couldn't find magic", LOGID(this));
102
- maybe_remove_file();
103
- return CACHE_ERROR;
104
- }
105
- *end = '\0'; // Stop parsing at MAGIC
106
-
107
- lcbvb_CONFIG *vbc = lcbvb_create();
108
- if (vbc == NULL) {
109
- return CACHE_ERROR;
110
- }
111
-
112
- Status status = CACHE_ERROR;
113
-
114
- if (lcbvb_load_json(vbc, &buf[0]) != 0) {
115
- lcb_log(LOGARGS(this, ERROR), LOGFMT "Couldn't parse configuration", LOGID(this));
116
- lcb_log_badconfig(LOGARGS(this, ERROR), vbc, &buf[0]);
117
- maybe_remove_file();
118
- goto GT_DONE;
119
- }
120
-
121
- if (lcbvb_get_distmode(vbc) != LCBVB_DIST_VBUCKET) {
122
- lcb_log(LOGARGS(this, ERROR), LOGFMT "Not applying cached memcached config", LOGID(this));
123
- goto GT_DONE;
124
- }
125
-
126
- if (strcmp(vbc->bname, settings().bucket) != 0) {
127
- lcb_log(LOGARGS(this, ERROR), LOGFMT "Bucket name in file is different from the one requested", LOGID(this));
128
- goto GT_DONE;
129
- }
130
-
131
- if (config) {
132
- config->decref();
133
- }
134
-
135
- config = ConfigInfo::create(vbc, CLCONFIG_FILE);
136
- last_mtime = st.st_mtime;
137
-
138
- status = UPDATED;
139
- vbc = NULL;
140
-
141
- GT_DONE:
142
- if (vbc != NULL) {
143
- lcbvb_destroy(vbc);
144
- }
145
- return status;
146
- }
147
-
148
- void FileProvider::write_cache(lcbvb_CONFIG *cfg)
149
- {
150
- if (filename.empty() || is_readonly) {
151
- return;
152
- }
153
-
154
- std::ofstream ofs(filename.c_str(), std::ios::trunc);
155
- if (ofs.good()) {
156
- lcb_log(LOGARGS(this, INFO), LOGFMT "Writing configuration to file", LOGID(this));
157
- char *json = lcbvb_save_json(cfg);
158
- ofs << json;
159
- ofs << CONFIG_CACHE_MAGIC;
160
- free(json);
161
- } else {
162
- int save_errno = errno;
163
- lcb_log(LOGARGS(this, ERROR), LOGFMT "Couldn't open file for writing: %s", LOGID(this), strerror(save_errno));
164
- }
165
- }
166
-
167
- ConfigInfo* FileProvider::get_cached() {
168
- return filename.empty() ? NULL : config;
169
- }
170
-
171
- void FileProvider::reload_cache() {
172
- if (load_cache() == UPDATED) {
173
- parent->provider_got_config(this, config);
174
- } else {
175
- parent->provider_failed(this, LCB_ERROR);
176
- }
177
- }
178
-
179
- lcb_error_t FileProvider::refresh() {
180
- if (!timer.is_armed()) {
181
- timer.signal();
182
- }
183
- return LCB_SUCCESS;
184
- }
185
-
186
- FileProvider::~FileProvider() {
187
- timer.release();
188
- if (config) {
189
- config->decref();
190
- }
191
- }
192
-
193
- void FileProvider::clconfig_lsn(EventType event, ConfigInfo *info) {
194
- if (event != CLCONFIG_EVENT_GOT_NEW_CONFIG) {
195
- return;
196
- }
197
- if (!enabled) {
198
- return;
199
- }
200
-
201
- if (info->get_origin() == CLCONFIG_PHONY ||
202
- info->get_origin() == CLCONFIG_FILE) {
203
- lcb_log(LOGARGS(this, TRACE), "Not writing configuration originating from PHONY or FILE to cache");
204
- return;
205
- }
206
-
207
- write_cache(info->vbc);
208
- }
209
-
210
- void FileProvider::dump(FILE *fp) const {
211
- fprintf(fp, "## BEGIN FILE PROVIEDER DUMP ##\n");
212
- if (!filename.empty()) {
213
- fprintf(fp, "FILENAME: %s\n", filename.c_str());
214
- }
215
- fprintf(fp, "LAST SYSTEM ERRNO: %d\n", last_errno);
216
- fprintf(fp, "LAST MTIME: %lu\n", (unsigned long)last_mtime);
217
- fprintf(fp, "## END FILE PROVIDER DUMP ##\n");
218
-
219
- }
220
-
221
- FileProvider::FileProvider(Confmon *parent_)
222
- : Provider(parent_, CLCONFIG_FILE),
223
- config(NULL), last_mtime(0), last_errno(0), is_readonly(false),
224
- timer(parent_->iot, this) {
225
- parent->add_listener(this);
226
- }
227
-
228
- static std::string mkcachefile(const char *name, const char *bucket)
229
- {
230
- if (name != NULL) {
231
- return std::string(name);
232
- } else {
233
- std::string buffer(lcb_get_tmpdir());
234
- if (buffer.empty()) {
235
- buffer += ".";
236
- }
237
- buffer += "/";
238
- buffer += bucket;
239
- return buffer;
240
- }
241
- }
242
-
243
- bool lcb::clconfig::file_set_filename(Provider *p, const char *f, bool ro)
244
- {
245
- FileProvider *provider = static_cast<FileProvider*>(p);
246
- provider->enabled = 1;
247
- provider->filename = mkcachefile(f, p->parent->settings->bucket);
248
- provider->is_readonly = bool(ro);
249
-
250
- if (ro) {
251
- FILE *fp_tmp = fopen(provider->filename.c_str(), "r");
252
- if (!fp_tmp) {
253
- lcb_log(LOGARGS(provider, ERROR), LOGFMT "Couldn't open for reading: %s", LOGID(provider), strerror(errno));
254
- return false;
255
- } else {
256
- fclose(fp_tmp);
257
- }
258
- }
259
- return true;
260
- }
261
-
262
- const char *
263
- lcb::clconfig::file_get_filename(Provider *p)
264
- {
265
- FileProvider *fp = static_cast<FileProvider*>(p);
266
- if (fp->filename.empty()) {
267
- return NULL;
268
- } else {
269
- return fp->filename.c_str();
270
- }
271
- }
272
-
273
- void
274
- lcb::clconfig::file_set_readonly(Provider *p, bool val)
275
- {
276
- static_cast<FileProvider*>(p)->is_readonly = val;
277
- }
278
-
279
- Provider* lcb::clconfig::new_file_provider(Confmon *mon) {
280
- return new FileProvider(mon);
281
- }