couchbase 3.0.0.alpha.1-universal-darwin-19 → 3.0.0.alpha.2-universal-darwin-19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/tests-6.0.3.yml +49 -0
- data/.github/workflows/tests.yml +47 -0
- data/.gitmodules +3 -0
- data/.idea/dictionaries/gem_terms.xml +5 -0
- data/.idea/inspectionProfiles/Project_Default.xml +1 -0
- data/.idea/vcs.xml +1 -0
- data/Gemfile +1 -0
- data/README.md +55 -2
- data/Rakefile +18 -0
- data/bin/init-cluster +62 -0
- data/bin/setup +1 -0
- data/couchbase.gemspec +3 -2
- data/examples/crud.rb +1 -2
- data/examples/managing_buckets.rb +47 -0
- data/examples/managing_collections.rb +58 -0
- data/examples/managing_query_indexes.rb +63 -0
- data/examples/query.rb +3 -2
- data/examples/query_with_consistency.rb +76 -0
- data/examples/subdocument.rb +23 -1
- data/ext/.clang-format +1 -1
- data/ext/.idea/dictionaries/couchbase_terms.xml +2 -0
- data/ext/.idea/vcs.xml +1 -0
- data/ext/CMakeLists.txt +30 -12
- data/ext/build_version.hxx.in +26 -0
- data/ext/couchbase/bucket.hxx +69 -8
- data/ext/couchbase/cluster.hxx +70 -54
- data/ext/couchbase/collections_manifest.hxx +3 -3
- data/ext/couchbase/configuration.hxx +14 -0
- data/ext/couchbase/couchbase.cxx +2044 -383
- data/ext/couchbase/{operations/document_id.hxx → document_id.hxx} +5 -4
- data/ext/couchbase/io/http_message.hxx +5 -1
- data/ext/couchbase/io/http_parser.hxx +2 -1
- data/ext/couchbase/io/http_session.hxx +6 -3
- data/ext/couchbase/io/{binary_message.hxx → mcbp_message.hxx} +15 -12
- data/ext/couchbase/io/mcbp_parser.hxx +99 -0
- data/ext/couchbase/io/{key_value_session.hxx → mcbp_session.hxx} +200 -95
- data/ext/couchbase/io/session_manager.hxx +37 -22
- data/ext/couchbase/mutation_token.hxx +2 -1
- data/ext/couchbase/operations.hxx +38 -8
- data/ext/couchbase/operations/bucket_create.hxx +138 -0
- data/ext/couchbase/operations/bucket_drop.hxx +65 -0
- data/ext/couchbase/operations/bucket_flush.hxx +65 -0
- data/ext/couchbase/operations/bucket_get.hxx +69 -0
- data/ext/couchbase/operations/bucket_get_all.hxx +62 -0
- data/ext/couchbase/operations/bucket_settings.hxx +111 -0
- data/ext/couchbase/operations/bucket_update.hxx +115 -0
- data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +60 -0
- data/ext/couchbase/operations/collection_create.hxx +86 -0
- data/ext/couchbase/operations/collection_drop.hxx +82 -0
- data/ext/couchbase/operations/command.hxx +10 -10
- data/ext/couchbase/operations/document_decrement.hxx +80 -0
- data/ext/couchbase/operations/document_exists.hxx +80 -0
- data/ext/couchbase/operations/{get.hxx → document_get.hxx} +4 -2
- data/ext/couchbase/operations/document_get_and_lock.hxx +64 -0
- data/ext/couchbase/operations/document_get_and_touch.hxx +64 -0
- data/ext/couchbase/operations/document_increment.hxx +80 -0
- data/ext/couchbase/operations/document_insert.hxx +74 -0
- data/ext/couchbase/operations/{lookup_in.hxx → document_lookup_in.hxx} +2 -2
- data/ext/couchbase/operations/{mutate_in.hxx → document_mutate_in.hxx} +11 -2
- data/ext/couchbase/operations/{query.hxx → document_query.hxx} +101 -6
- data/ext/couchbase/operations/document_remove.hxx +67 -0
- data/ext/couchbase/operations/document_replace.hxx +76 -0
- data/ext/couchbase/operations/{upsert.hxx → document_touch.hxx} +14 -14
- data/ext/couchbase/operations/{remove.hxx → document_unlock.hxx} +12 -10
- data/ext/couchbase/operations/document_upsert.hxx +74 -0
- data/ext/couchbase/operations/query_index_build_deferred.hxx +85 -0
- data/ext/couchbase/operations/query_index_create.hxx +134 -0
- data/ext/couchbase/operations/query_index_drop.hxx +108 -0
- data/ext/couchbase/operations/query_index_get_all.hxx +106 -0
- data/ext/couchbase/operations/scope_create.hxx +81 -0
- data/ext/couchbase/operations/scope_drop.hxx +79 -0
- data/ext/couchbase/operations/scope_get_all.hxx +72 -0
- data/ext/couchbase/protocol/client_opcode.hxx +35 -0
- data/ext/couchbase/protocol/client_request.hxx +56 -9
- data/ext/couchbase/protocol/client_response.hxx +52 -15
- data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +81 -0
- data/ext/couchbase/protocol/cmd_decrement.hxx +187 -0
- data/ext/couchbase/protocol/cmd_exists.hxx +171 -0
- data/ext/couchbase/protocol/cmd_get.hxx +31 -8
- data/ext/couchbase/protocol/cmd_get_and_lock.hxx +142 -0
- data/ext/couchbase/protocol/cmd_get_and_touch.hxx +142 -0
- data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +16 -3
- data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +16 -3
- data/ext/couchbase/protocol/cmd_get_error_map.hxx +16 -3
- data/ext/couchbase/protocol/cmd_hello.hxx +24 -8
- data/ext/couchbase/protocol/cmd_increment.hxx +187 -0
- data/ext/couchbase/protocol/cmd_info.hxx +1 -0
- data/ext/couchbase/protocol/cmd_insert.hxx +172 -0
- data/ext/couchbase/protocol/cmd_lookup_in.hxx +28 -13
- data/ext/couchbase/protocol/cmd_mutate_in.hxx +65 -13
- data/ext/couchbase/protocol/cmd_remove.hxx +59 -4
- data/ext/couchbase/protocol/cmd_replace.hxx +172 -0
- data/ext/couchbase/protocol/cmd_sasl_auth.hxx +15 -3
- data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +15 -3
- data/ext/couchbase/protocol/cmd_sasl_step.hxx +15 -3
- data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -2
- data/ext/couchbase/protocol/cmd_touch.hxx +102 -0
- data/ext/couchbase/protocol/cmd_unlock.hxx +95 -0
- data/ext/couchbase/protocol/cmd_upsert.hxx +50 -14
- data/ext/couchbase/protocol/durability_level.hxx +67 -0
- data/ext/couchbase/protocol/frame_info_id.hxx +187 -0
- data/ext/couchbase/protocol/hello_feature.hxx +137 -0
- data/ext/couchbase/protocol/server_opcode.hxx +57 -0
- data/ext/couchbase/protocol/server_request.hxx +122 -0
- data/ext/couchbase/protocol/unsigned_leb128.h +15 -15
- data/ext/couchbase/utils/byteswap.hxx +1 -2
- data/ext/couchbase/utils/url_codec.hxx +225 -0
- data/ext/couchbase/version.hxx +3 -1
- data/ext/extconf.rb +4 -1
- data/ext/test/main.cxx +37 -113
- data/ext/third_party/snappy/.appveyor.yml +36 -0
- data/ext/third_party/snappy/.gitignore +8 -0
- data/ext/third_party/snappy/.travis.yml +98 -0
- data/ext/third_party/snappy/AUTHORS +1 -0
- data/ext/third_party/snappy/CMakeLists.txt +345 -0
- data/ext/third_party/snappy/CONTRIBUTING.md +26 -0
- data/ext/third_party/snappy/COPYING +54 -0
- data/ext/third_party/snappy/NEWS +188 -0
- data/ext/third_party/snappy/README.md +148 -0
- data/ext/third_party/snappy/cmake/SnappyConfig.cmake.in +33 -0
- data/ext/third_party/snappy/cmake/config.h.in +59 -0
- data/ext/third_party/snappy/docs/README.md +72 -0
- data/ext/third_party/snappy/format_description.txt +110 -0
- data/ext/third_party/snappy/framing_format.txt +135 -0
- data/ext/third_party/snappy/snappy-c.cc +90 -0
- data/ext/third_party/snappy/snappy-c.h +138 -0
- data/ext/third_party/snappy/snappy-internal.h +315 -0
- data/ext/third_party/snappy/snappy-sinksource.cc +121 -0
- data/ext/third_party/snappy/snappy-sinksource.h +182 -0
- data/ext/third_party/snappy/snappy-stubs-internal.cc +42 -0
- data/ext/third_party/snappy/snappy-stubs-internal.h +493 -0
- data/ext/third_party/snappy/snappy-stubs-public.h.in +63 -0
- data/ext/third_party/snappy/snappy-test.cc +613 -0
- data/ext/third_party/snappy/snappy-test.h +526 -0
- data/ext/third_party/snappy/snappy.cc +1770 -0
- data/ext/third_party/snappy/snappy.h +209 -0
- data/ext/third_party/snappy/snappy_compress_fuzzer.cc +60 -0
- data/ext/third_party/snappy/snappy_uncompress_fuzzer.cc +58 -0
- data/ext/third_party/snappy/snappy_unittest.cc +1512 -0
- data/ext/third_party/snappy/testdata/alice29.txt +3609 -0
- data/ext/third_party/snappy/testdata/asyoulik.txt +4122 -0
- data/ext/third_party/snappy/testdata/baddata1.snappy +0 -0
- data/ext/third_party/snappy/testdata/baddata2.snappy +0 -0
- data/ext/third_party/snappy/testdata/baddata3.snappy +0 -0
- data/ext/third_party/snappy/testdata/fireworks.jpeg +0 -0
- data/ext/third_party/snappy/testdata/geo.protodata +0 -0
- data/ext/third_party/snappy/testdata/html +1 -0
- data/ext/third_party/snappy/testdata/html_x_4 +1 -0
- data/ext/third_party/snappy/testdata/kppkn.gtb +0 -0
- data/ext/third_party/snappy/testdata/lcet10.txt +7519 -0
- data/ext/third_party/snappy/testdata/paper-100k.pdf +600 -2
- data/ext/third_party/snappy/testdata/plrabn12.txt +10699 -0
- data/ext/third_party/snappy/testdata/urls.10K +10000 -0
- data/lib/couchbase/binary_collection.rb +33 -76
- data/lib/couchbase/binary_collection_options.rb +94 -0
- data/lib/couchbase/bucket.rb +9 -3
- data/lib/couchbase/cluster.rb +161 -23
- data/lib/couchbase/collection.rb +108 -191
- data/lib/couchbase/collection_options.rb +430 -0
- data/lib/couchbase/errors.rb +136 -134
- data/lib/couchbase/json_transcoder.rb +32 -0
- data/lib/couchbase/management/analytics_index_manager.rb +185 -9
- data/lib/couchbase/management/bucket_manager.rb +84 -33
- data/lib/couchbase/management/collection_manager.rb +166 -1
- data/lib/couchbase/management/query_index_manager.rb +261 -0
- data/lib/couchbase/management/search_index_manager.rb +291 -0
- data/lib/couchbase/management/user_manager.rb +12 -10
- data/lib/couchbase/management/view_index_manager.rb +151 -1
- data/lib/couchbase/mutation_state.rb +11 -1
- data/lib/couchbase/scope.rb +4 -4
- data/lib/couchbase/version.rb +1 -1
- metadata +113 -18
- data/.travis.yml +0 -7
- data/ext/couchbase/io/binary_parser.hxx +0 -64
- data/lib/couchbase/results.rb +0 -307
@@ -36,12 +36,18 @@ class sasl_list_mechs_response_body
|
|
36
36
|
return supported_mechs_;
|
37
37
|
}
|
38
38
|
|
39
|
-
bool parse(protocol::status status,
|
39
|
+
bool parse(protocol::status status,
|
40
|
+
const header_buffer& header,
|
41
|
+
std::uint8_t framing_extras_size,
|
42
|
+
std::uint16_t key_size,
|
43
|
+
std::uint8_t extras_size,
|
44
|
+
const std::vector<uint8_t>& body,
|
45
|
+
const cmd_info&)
|
40
46
|
{
|
41
47
|
Expects(header[1] == static_cast<uint8_t>(opcode));
|
42
48
|
if (status == protocol::status::success) {
|
43
49
|
auto previous = body.begin();
|
44
|
-
auto current = std::find(body.begin(), body.end(), ' ');
|
50
|
+
auto current = std::find(body.begin() + framing_extras_size + extras_size + key_size, body.end(), ' ');
|
45
51
|
while (current != body.end()) {
|
46
52
|
supported_mechs_.emplace_back(previous, current);
|
47
53
|
previous = current + 1;
|
@@ -67,7 +73,13 @@ class sasl_list_mechs_request_body
|
|
67
73
|
return empty;
|
68
74
|
}
|
69
75
|
|
70
|
-
const std::vector<std::uint8_t>&
|
76
|
+
const std::vector<std::uint8_t>& framing_extras()
|
77
|
+
{
|
78
|
+
static std::vector<std::uint8_t> empty;
|
79
|
+
return empty;
|
80
|
+
}
|
81
|
+
|
82
|
+
const std::vector<std::uint8_t>& extras()
|
71
83
|
{
|
72
84
|
static std::vector<std::uint8_t> empty;
|
73
85
|
return empty;
|
@@ -30,11 +30,17 @@ class sasl_step_response_body
|
|
30
30
|
std::string value_;
|
31
31
|
|
32
32
|
public:
|
33
|
-
bool parse(protocol::status status,
|
33
|
+
bool parse(protocol::status status,
|
34
|
+
const header_buffer& header,
|
35
|
+
std::uint8_t framing_extras_size,
|
36
|
+
std::uint16_t key_size,
|
37
|
+
std::uint8_t extras_size,
|
38
|
+
const std::vector<uint8_t>& body,
|
39
|
+
const cmd_info&)
|
34
40
|
{
|
35
41
|
Expects(header[1] == static_cast<uint8_t>(opcode));
|
36
42
|
if (status == protocol::status::success) {
|
37
|
-
value_ = { body.begin(), body.end() };
|
43
|
+
value_ = { body.begin() + framing_extras_size + extras_size + key_size, body.end() };
|
38
44
|
return true;
|
39
45
|
}
|
40
46
|
return false;
|
@@ -72,7 +78,13 @@ class sasl_step_request_body
|
|
72
78
|
return key_;
|
73
79
|
}
|
74
80
|
|
75
|
-
const std::vector<std::uint8_t>&
|
81
|
+
const std::vector<std::uint8_t>& framing_extras()
|
82
|
+
{
|
83
|
+
static std::vector<std::uint8_t> empty;
|
84
|
+
return empty;
|
85
|
+
}
|
86
|
+
|
87
|
+
const std::vector<std::uint8_t>& extras()
|
76
88
|
{
|
77
89
|
static std::vector<std::uint8_t> empty;
|
78
90
|
return empty;
|
@@ -25,7 +25,13 @@ class select_bucket_response_body
|
|
25
25
|
static const inline client_opcode opcode = client_opcode::select_bucket;
|
26
26
|
|
27
27
|
public:
|
28
|
-
bool parse(protocol::status,
|
28
|
+
bool parse(protocol::status,
|
29
|
+
const header_buffer& header,
|
30
|
+
std::uint8_t,
|
31
|
+
std::uint16_t,
|
32
|
+
std::uint8_t,
|
33
|
+
const std::vector<uint8_t>&,
|
34
|
+
const cmd_info&)
|
29
35
|
{
|
30
36
|
Expects(header[1] == static_cast<uint8_t>(opcode));
|
31
37
|
return false;
|
@@ -52,7 +58,13 @@ class select_bucket_request_body
|
|
52
58
|
return key_;
|
53
59
|
}
|
54
60
|
|
55
|
-
const std::vector<std::uint8_t>&
|
61
|
+
const std::vector<std::uint8_t>& framing_extras()
|
62
|
+
{
|
63
|
+
static std::vector<std::uint8_t> empty;
|
64
|
+
return empty;
|
65
|
+
}
|
66
|
+
|
67
|
+
const std::vector<std::uint8_t>& extras()
|
56
68
|
{
|
57
69
|
static std::vector<std::uint8_t> empty;
|
58
70
|
return empty;
|
@@ -0,0 +1,102 @@
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2020 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
|
+
#pragma once
|
19
|
+
|
20
|
+
#include <protocol/unsigned_leb128.h>
|
21
|
+
|
22
|
+
#include <protocol/client_opcode.hxx>
|
23
|
+
#include <document_id.hxx>
|
24
|
+
|
25
|
+
namespace couchbase::protocol
|
26
|
+
{
|
27
|
+
|
28
|
+
class touch_response_body
|
29
|
+
{
|
30
|
+
public:
|
31
|
+
static const inline client_opcode opcode = client_opcode::touch;
|
32
|
+
|
33
|
+
public:
|
34
|
+
bool parse(protocol::status /* status */,
|
35
|
+
const header_buffer& header,
|
36
|
+
std::uint8_t /* framing_extras_size */,
|
37
|
+
std::uint16_t /* key_size */,
|
38
|
+
std::uint8_t /* extras_size */,
|
39
|
+
const std::vector<uint8_t>& /* body */,
|
40
|
+
const cmd_info& /* info */)
|
41
|
+
{
|
42
|
+
Expects(header[1] == static_cast<uint8_t>(opcode));
|
43
|
+
return false;
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
class touch_request_body
|
48
|
+
{
|
49
|
+
public:
|
50
|
+
using response_body_type = touch_response_body;
|
51
|
+
static const inline client_opcode opcode = client_opcode::touch;
|
52
|
+
|
53
|
+
private:
|
54
|
+
std::string key_;
|
55
|
+
std::vector<std::uint8_t> extras_{};
|
56
|
+
|
57
|
+
public:
|
58
|
+
void id(const document_id& id)
|
59
|
+
{
|
60
|
+
key_ = id.key;
|
61
|
+
if (id.collection_uid) {
|
62
|
+
unsigned_leb128<uint32_t> encoded(*id.collection_uid);
|
63
|
+
key_.insert(0, encoded.get());
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
void expiration(std::uint32_t seconds)
|
68
|
+
{
|
69
|
+
extras_.resize(sizeof(seconds));
|
70
|
+
seconds = htonl(seconds);
|
71
|
+
memcpy(extras_.data(), &seconds, sizeof(seconds));
|
72
|
+
}
|
73
|
+
|
74
|
+
const std::string& key()
|
75
|
+
{
|
76
|
+
return key_;
|
77
|
+
}
|
78
|
+
|
79
|
+
const std::vector<std::uint8_t>& framing_extras()
|
80
|
+
{
|
81
|
+
static std::vector<std::uint8_t> empty;
|
82
|
+
return empty;
|
83
|
+
}
|
84
|
+
|
85
|
+
const std::vector<std::uint8_t>& extras()
|
86
|
+
{
|
87
|
+
return extras_;
|
88
|
+
}
|
89
|
+
|
90
|
+
const std::vector<std::uint8_t>& value()
|
91
|
+
{
|
92
|
+
static std::vector<std::uint8_t> empty;
|
93
|
+
return empty;
|
94
|
+
}
|
95
|
+
|
96
|
+
std::size_t size()
|
97
|
+
{
|
98
|
+
return key_.size() + extras_.size();
|
99
|
+
}
|
100
|
+
};
|
101
|
+
|
102
|
+
} // namespace couchbase::protocol
|
@@ -0,0 +1,95 @@
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2020 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
|
+
#pragma once
|
19
|
+
|
20
|
+
#include <protocol/unsigned_leb128.h>
|
21
|
+
|
22
|
+
#include <protocol/client_opcode.hxx>
|
23
|
+
#include <document_id.hxx>
|
24
|
+
|
25
|
+
namespace couchbase::protocol
|
26
|
+
{
|
27
|
+
|
28
|
+
class unlock_response_body
|
29
|
+
{
|
30
|
+
public:
|
31
|
+
static const inline client_opcode opcode = client_opcode::unlock;
|
32
|
+
|
33
|
+
public:
|
34
|
+
bool parse(protocol::status /* status */,
|
35
|
+
const header_buffer& header,
|
36
|
+
std::uint8_t /* framing_extras_size */,
|
37
|
+
std::uint16_t /* key_size */,
|
38
|
+
std::uint8_t /* extras_size */,
|
39
|
+
const std::vector<uint8_t>& /* body */,
|
40
|
+
const cmd_info&)
|
41
|
+
{
|
42
|
+
Expects(header[1] == static_cast<uint8_t>(opcode));
|
43
|
+
return false;
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
class unlock_request_body
|
48
|
+
{
|
49
|
+
public:
|
50
|
+
using response_body_type = unlock_response_body;
|
51
|
+
static const inline client_opcode opcode = client_opcode::unlock;
|
52
|
+
|
53
|
+
private:
|
54
|
+
std::string key_;
|
55
|
+
|
56
|
+
public:
|
57
|
+
void id(const document_id& id)
|
58
|
+
{
|
59
|
+
key_ = id.key;
|
60
|
+
if (id.collection_uid) {
|
61
|
+
unsigned_leb128<uint32_t> encoded(*id.collection_uid);
|
62
|
+
key_.insert(0, encoded.get());
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
const std::string& key()
|
67
|
+
{
|
68
|
+
return key_;
|
69
|
+
}
|
70
|
+
|
71
|
+
const std::vector<std::uint8_t>& framing_extras()
|
72
|
+
{
|
73
|
+
static std::vector<std::uint8_t> empty;
|
74
|
+
return empty;
|
75
|
+
}
|
76
|
+
|
77
|
+
const std::vector<std::uint8_t>& extras()
|
78
|
+
{
|
79
|
+
static std::vector<std::uint8_t> empty;
|
80
|
+
return empty;
|
81
|
+
}
|
82
|
+
|
83
|
+
const std::vector<std::uint8_t>& value()
|
84
|
+
{
|
85
|
+
static std::vector<std::uint8_t> empty;
|
86
|
+
return empty;
|
87
|
+
}
|
88
|
+
|
89
|
+
std::size_t size()
|
90
|
+
{
|
91
|
+
return key_.size();
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
95
|
+
} // namespace couchbase::protocol
|
@@ -19,7 +19,9 @@
|
|
19
19
|
|
20
20
|
#include <protocol/status.hxx>
|
21
21
|
#include <protocol/client_opcode.hxx>
|
22
|
+
#include <protocol/frame_info_id.hxx>
|
22
23
|
#include <protocol/unsigned_leb128.h>
|
24
|
+
#include <protocol/durability_level.hxx>
|
23
25
|
#include <mutation_token.hxx>
|
24
26
|
#include <utils/byteswap.hxx>
|
25
27
|
|
@@ -40,13 +42,18 @@ class upsert_response_body
|
|
40
42
|
return token_;
|
41
43
|
}
|
42
44
|
|
43
|
-
bool parse(protocol::status status,
|
45
|
+
bool parse(protocol::status status,
|
46
|
+
const header_buffer& header,
|
47
|
+
std::uint8_t framing_extras_size,
|
48
|
+
std::uint16_t,
|
49
|
+
std::uint8_t extras_size,
|
50
|
+
const std::vector<uint8_t>& body,
|
51
|
+
const cmd_info&)
|
44
52
|
{
|
45
53
|
Expects(header[1] == static_cast<uint8_t>(opcode));
|
46
54
|
if (status == protocol::status::success) {
|
47
|
-
std::vector<uint8_t>::difference_type offset =
|
48
|
-
|
49
|
-
if (ext_size == 16) {
|
55
|
+
std::vector<uint8_t>::difference_type offset = framing_extras_size;
|
56
|
+
if (extras_size == 16) {
|
50
57
|
memcpy(&token_.partition_uuid, body.data() + offset, sizeof(token_.partition_uuid));
|
51
58
|
token_.partition_uuid = utils::byte_swap_64(token_.partition_uuid);
|
52
59
|
offset += 8;
|
@@ -68,15 +75,39 @@ class upsert_request_body
|
|
68
75
|
|
69
76
|
private:
|
70
77
|
std::string key_{};
|
71
|
-
std::vector<std::uint8_t>
|
78
|
+
std::vector<std::uint8_t> extras_{};
|
72
79
|
std::vector<std::uint8_t> content_{};
|
73
80
|
std::uint32_t flags_{};
|
74
81
|
std::uint32_t expiration_{};
|
82
|
+
std::vector<std::uint8_t> framing_extras_{};
|
75
83
|
|
76
84
|
public:
|
77
|
-
void id(const
|
85
|
+
void id(const document_id& id)
|
78
86
|
{
|
79
87
|
key_ = id.key;
|
88
|
+
if (id.collection_uid) {
|
89
|
+
unsigned_leb128<uint32_t> encoded(*id.collection_uid);
|
90
|
+
key_.insert(0, encoded.get());
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
void durability(protocol::durability_level level, std::optional<std::uint16_t> timeout)
|
95
|
+
{
|
96
|
+
if (level == protocol::durability_level::none) {
|
97
|
+
return;
|
98
|
+
}
|
99
|
+
auto frame_id = static_cast<uint8_t>(protocol::request_frame_info_id::durability_requirement);
|
100
|
+
if (timeout) {
|
101
|
+
framing_extras_.resize(4);
|
102
|
+
framing_extras_[0] = static_cast<std::uint8_t>((static_cast<std::uint32_t>(frame_id) << 4U) | 3U);
|
103
|
+
framing_extras_[1] = static_cast<std::uint8_t>(level);
|
104
|
+
uint16_t val = htons(*timeout);
|
105
|
+
memcpy(framing_extras_.data() + 2, &val, sizeof(val));
|
106
|
+
} else {
|
107
|
+
framing_extras_.resize(2);
|
108
|
+
framing_extras_[0] = static_cast<std::uint8_t>(static_cast<std::uint32_t>(frame_id) << 4U | 1U);
|
109
|
+
framing_extras_[1] = static_cast<std::uint8_t>(level);
|
110
|
+
}
|
80
111
|
}
|
81
112
|
|
82
113
|
void content(const std::string& content)
|
@@ -99,12 +130,17 @@ class upsert_request_body
|
|
99
130
|
return key_;
|
100
131
|
}
|
101
132
|
|
102
|
-
const std::vector<std::uint8_t>&
|
133
|
+
const std::vector<std::uint8_t>& framing_extras()
|
134
|
+
{
|
135
|
+
return framing_extras_;
|
136
|
+
}
|
137
|
+
|
138
|
+
const std::vector<std::uint8_t>& extras()
|
103
139
|
{
|
104
|
-
if (
|
140
|
+
if (extras_.empty()) {
|
105
141
|
fill_extention();
|
106
142
|
}
|
107
|
-
return
|
143
|
+
return extras_;
|
108
144
|
}
|
109
145
|
|
110
146
|
const std::vector<std::uint8_t>& value()
|
@@ -114,22 +150,22 @@ class upsert_request_body
|
|
114
150
|
|
115
151
|
std::size_t size()
|
116
152
|
{
|
117
|
-
if (
|
153
|
+
if (extras_.empty()) {
|
118
154
|
fill_extention();
|
119
155
|
}
|
120
|
-
return
|
156
|
+
return framing_extras_.size() + extras_.size() + key_.size() + content_.size();
|
121
157
|
}
|
122
158
|
|
123
159
|
private:
|
124
160
|
void fill_extention()
|
125
161
|
{
|
126
|
-
|
162
|
+
extras_.resize(sizeof(flags_) + sizeof(expiration_));
|
127
163
|
|
128
164
|
uint32_t field = htonl(flags_);
|
129
|
-
memcpy(
|
165
|
+
memcpy(extras_.data(), &field, sizeof(field));
|
130
166
|
|
131
167
|
field = htonl(expiration_);
|
132
|
-
memcpy(
|
168
|
+
memcpy(extras_.data() + sizeof(flags_), &field, sizeof(field));
|
133
169
|
}
|
134
170
|
};
|
135
171
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2020 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
|
+
#pragma once
|
19
|
+
|
20
|
+
#include <spdlog/spdlog.h>
|
21
|
+
|
22
|
+
namespace couchbase::protocol
|
23
|
+
{
|
24
|
+
enum class durability_level : uint8_t {
|
25
|
+
none = 0x00,
|
26
|
+
majority = 0x01,
|
27
|
+
majority_and_persist_to_active = 0x02,
|
28
|
+
persist_to_majority = 0x03,
|
29
|
+
};
|
30
|
+
|
31
|
+
constexpr inline bool
|
32
|
+
is_valid_durability_level(uint8_t value)
|
33
|
+
{
|
34
|
+
switch (static_cast<durability_level>(value)) {
|
35
|
+
case durability_level::none:
|
36
|
+
case durability_level::majority:
|
37
|
+
case durability_level::majority_and_persist_to_active:
|
38
|
+
case durability_level::persist_to_majority:
|
39
|
+
return true;
|
40
|
+
}
|
41
|
+
return false;
|
42
|
+
}
|
43
|
+
} // namespace couchbase::protocol
|
44
|
+
|
45
|
+
template<>
|
46
|
+
struct fmt::formatter<couchbase::protocol::durability_level> : formatter<string_view> {
|
47
|
+
template<typename FormatContext>
|
48
|
+
auto format(couchbase::protocol::durability_level value, FormatContext& ctx)
|
49
|
+
{
|
50
|
+
string_view name = "unknown";
|
51
|
+
switch (value) {
|
52
|
+
case couchbase::protocol::durability_level::none:
|
53
|
+
name = "none";
|
54
|
+
break;
|
55
|
+
case couchbase::protocol::durability_level::majority:
|
56
|
+
name = "majority";
|
57
|
+
break;
|
58
|
+
case couchbase::protocol::durability_level::majority_and_persist_to_active:
|
59
|
+
name = "majority_and_persist_to_active";
|
60
|
+
break;
|
61
|
+
case couchbase::protocol::durability_level::persist_to_majority:
|
62
|
+
name = "persist_to_majority";
|
63
|
+
break;
|
64
|
+
}
|
65
|
+
return formatter<string_view>::format(name, ctx);
|
66
|
+
}
|
67
|
+
};
|