Skip to content

Commit adabade

Browse files
authored
CXXCBC-645: get_multi_* API for transactions (#761)
1 parent 86549bc commit adabade

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2094
-83
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ set(couchbase_cxx_client_FILES
217217
core/impl/term_query.cxx
218218
core/impl/term_range_query.cxx
219219
core/impl/transaction_error_category.cxx
220+
core/impl/transaction_get_multi_replicas_from_preferred_server_group_spec.cxx
221+
core/impl/transaction_get_multi_spec.cxx
220222
core/impl/transaction_get_result.cxx
221223
core/impl/transaction_op_error_category.cxx
222224
core/impl/vector_query.cxx
@@ -417,6 +419,7 @@ set(couchbase_cxx_client_FILES
417419
core/transactions/cleanup_testing_hooks.cxx
418420
core/transactions/exceptions.cxx
419421
core/transactions/forward_compat.cxx
422+
core/transactions/get_multi_orchestrator.cxx
420423
core/transactions/internal/doc_record.cxx
421424
core/transactions/result.cxx
422425
core/transactions/staged_mutation.cxx

bin/run-unit-tests

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ if [ "x${STATUS}" != "x0" ]
115115
then
116116
if [ -e /usr/bin/coredumpctl ]
117117
then
118-
/usr/bin/coredumpctl list --no-pager
118+
/usr/bin/coredumpctl list --no-pager --json=pretty
119+
executable="$(coredumpctl --json=pretty list | jq -r .[-1].exe)"
120+
if [ -f "${executable}" ]
121+
then
122+
file "${executable}"
123+
ldd "${executable}"
124+
fi
119125
/usr/bin/coredumpctl -1 info
120126
elif [ -e /usr/bin/apport-unpack ]
121127
then
@@ -126,6 +132,11 @@ then
126132
echo $crash
127133
/usr/bin/apport-unpack $crash /tmp/the_crash/
128134
executable=$(cat /tmp/the_crash/ExecutablePath)
135+
if [ -f "${executable}" ]
136+
then
137+
file "${executable}"
138+
ldd "${executable}"
139+
fi
129140
gdb $executable /tmp/the_crash/CoreDump --batch -ex "thread apply all bt"
130141
rm -rf $crash /tmp/the_crash
131142
fi
@@ -138,6 +149,11 @@ then
138149
echo $core
139150
executable=$(file $core | ruby -e "print ARGF.read[/execfn: '([^']+)'/, 1]")
140151
echo $executable
152+
if [ -f "${executable}" ]
153+
then
154+
file "${executable}"
155+
ldd "${executable}"
156+
fi
141157
gdb $executable $core --batch -ex "thread apply all bt"
142158
rm -f $core
143159
fi

core/impl/error.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "core/error_context/transaction_op_error_context.hxx"
3636
#include "core/impl/internal_error_context.hxx"
3737
#include "core/transactions/exceptions.hxx"
38+
#include "core/transactions/exceptions_fmt.hxx"
3839
#include "core/transactions/internal/exceptions_internal.hxx"
3940

4041
#include <couchbase/error.hxx>

core/impl/replica_utils.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ effective_nodes(const document_id& id,
2929
const read_preference& preference,
3030
const std::string& preferred_server_group) -> std::vector<readable_node>
3131
{
32-
if (preference != read_preference::no_preference && preferred_server_group.empty()) {
32+
if (preference == read_preference::selected_server_group && preferred_server_group.empty()) {
3333
CB_LOG_WARNING("Preferred server group is required for zone-aware replica reads");
3434
return {};
3535
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2021-Present Couchbase, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <couchbase/transactions/transaction_get_multi_replicas_from_preferred_server_group_spec.hxx>
18+
19+
#include <couchbase/collection.hxx>
20+
21+
namespace couchbase::transactions
22+
{
23+
transaction_get_multi_replicas_from_preferred_server_group_spec::
24+
transaction_get_multi_replicas_from_preferred_server_group_spec(const collection& collection,
25+
std::string id)
26+
: bucket_{ collection.bucket_name() }
27+
, scope_{ collection.scope_name() }
28+
, collection_{ collection.name() }
29+
, id_{ std::move(id) }
30+
{
31+
}
32+
} // namespace couchbase::transactions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2021-Present Couchbase, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <couchbase/transactions/transaction_get_multi_spec.hxx>
18+
19+
#include <couchbase/collection.hxx>
20+
21+
namespace couchbase::transactions
22+
{
23+
transaction_get_multi_spec::transaction_get_multi_spec(const collection& collection, std::string id)
24+
: bucket_{ collection.bucket_name() }
25+
, scope_{ collection.scope_name() }
26+
, collection_{ collection.name() }
27+
, id_{ std::move(id) }
28+
{
29+
}
30+
} // namespace couchbase::transactions

core/impl/transaction_op_error_category.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ struct transaction_op_error_category : std::error_category {
7070
return "transaction_already_aborted (1318)";
7171
case errc::transaction_op::transaction_already_committed:
7272
return "transaction_already_committed (1319)";
73+
case errc::transaction_op::document_unretrievable:
74+
return "document_unretrievable (1320)";
7375
case errc::transaction_op::transaction_op_failed:
7476
return "transaction_op_failed (1399)";
7577
}

core/meta/features.hxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,8 @@
238238
* parameters.
239239
*/
240240
#define COUCHBASE_CXX_CLIENT_QUERY_SUPPORTS_BOTH_POSITIONAL_NAMED_PARAMETERS 1
241+
242+
/**
243+
* get_multi API is implemented for transactions
244+
*/
245+
#define COUCHBASE_CXX_CLIENT_HAS_TRANSACTIONS_GET_MULTI 1

core/transactions/async_attempt_context.hxx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
*/
1616
#pragma once
1717

18-
#include "core/error_context/subdocument_error_context.hxx"
1918
#include "core/operations/document_query.hxx"
20-
#include "exceptions.hxx"
19+
#include "transaction_get_multi_mode.hxx"
20+
#include "transaction_get_multi_replicas_from_preferred_server_group_mode.hxx"
21+
#include "transaction_get_multi_replicas_from_preferred_server_group_result.hxx"
22+
#include "transaction_get_multi_result.hxx"
2123
#include "transaction_get_result.hxx"
2224

25+
// FIXME(SA): remove public API from the core
2326
#include <couchbase/transactions/transaction_query_options.hxx>
2427

2528
#include <optional>
@@ -42,6 +45,11 @@ public:
4245
using QueryCallback =
4346
std::function<void(std::exception_ptr, std::optional<core::operations::query_response>)>;
4447

48+
async_attempt_context() = default;
49+
async_attempt_context(async_attempt_context&&) = default;
50+
async_attempt_context(const async_attempt_context&) noexcept = default;
51+
auto operator=(async_attempt_context&&) -> async_attempt_context& = default;
52+
auto operator=(const async_attempt_context&) noexcept -> async_attempt_context& = default;
4553
virtual ~async_attempt_context() = default;
4654

4755
/**
@@ -78,6 +86,18 @@ public:
7886
const core::document_id& id,
7987
std::function<void(std::exception_ptr, std::optional<transaction_get_result>)>&& cb) = 0;
8088

89+
virtual void get_multi(
90+
const std::vector<core::document_id>& ids,
91+
transaction_get_multi_mode mode,
92+
std::function<void(std::exception_ptr, std::optional<transaction_get_multi_result>)>&& cb) = 0;
93+
94+
virtual void get_multi_replicas_from_preferred_server_group(
95+
const std::vector<core::document_id>& ids,
96+
transaction_get_multi_replicas_from_preferred_server_group_mode mode,
97+
std::function<void(
98+
std::exception_ptr,
99+
std::optional<transaction_get_multi_replicas_from_preferred_server_group_result>)>&& cb) = 0;
100+
81101
/**
82102
* Mutates the specified document with new content, using the document's last
83103
* TransactionDocument#cas().

core/transactions/attempt_context.hxx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
*/
1616
#pragma once
1717

18+
#include "core/operations/document_query.hxx"
19+
#include "transaction_get_multi_mode.hxx"
20+
#include "transaction_get_multi_replicas_from_preferred_server_group_mode.hxx"
21+
#include "transaction_get_multi_replicas_from_preferred_server_group_result.hxx"
22+
#include "transaction_get_multi_result.hxx"
1823
#include "transaction_get_result.hxx"
1924

20-
#include "internal/exceptions_internal.hxx"
21-
25+
// TODO(SA): remove public API from core interfaces
2226
#include <couchbase/transactions/transaction_query_options.hxx>
2327

2428
#include <optional>
@@ -37,7 +41,13 @@ namespace couchbase::core::transactions
3741
class attempt_context
3842
{
3943
public:
44+
attempt_context() = default;
45+
attempt_context(attempt_context&&) noexcept = default;
46+
attempt_context(const attempt_context&) = default;
47+
auto operator=(attempt_context&&) noexcept -> attempt_context& = default;
48+
auto operator=(const attempt_context&) -> attempt_context& = default;
4049
virtual ~attempt_context() = default;
50+
4151
/**
4252
* Gets a document from the specified Couchbase collection matching the
4353
* specified id.
@@ -80,6 +90,14 @@ public:
8090
virtual auto get_replica_from_preferred_server_group(const core::document_id& id)
8191
-> std::optional<transaction_get_result> = 0;
8292

93+
virtual auto get_multi(const std::vector<core::document_id>& ids, transaction_get_multi_mode mode)
94+
-> transaction_get_multi_result = 0;
95+
96+
virtual auto get_multi_replicas_from_preferred_server_group(
97+
const std::vector<core::document_id>& ids,
98+
transaction_get_multi_replicas_from_preferred_server_group_mode mode)
99+
-> transaction_get_multi_replicas_from_preferred_server_group_result = 0;
100+
83101
/**
84102
* Mutates the specified document with new content, using the document's last
85103
* TransactionDocument#cas().
@@ -101,8 +119,8 @@ public:
101119
* @throws transaction_operation_failed which either should not be caught by
102120
* the lambda, or rethrown if it is caught.
103121
*/
104-
virtual auto replace(const transaction_get_result& document,
105-
codec::encoded_value content) -> transaction_get_result = 0;
122+
virtual auto replace(const transaction_get_result& document, codec::encoded_value content)
123+
-> transaction_get_result = 0;
106124

107125
/**
108126
* Inserts a new document into the specified Couchbase collection.
@@ -124,8 +142,8 @@ public:
124142
* @throws transaction_operation_failed which either should not be caught by
125143
* the lambda, or rethrown if it is caught.
126144
*/
127-
virtual auto insert(const core::document_id& id,
128-
codec::encoded_value content) -> transaction_get_result = 0;
145+
virtual auto insert(const core::document_id& id, codec::encoded_value content)
146+
-> transaction_get_result = 0;
129147

130148
/**
131149
* Removes the specified document, using the document's last
@@ -157,7 +175,7 @@ public:
157175
const couchbase::transactions::transaction_query_options& opts,
158176
std::optional<std::string> query_context = {}) -> core::operations::query_response
159177
{
160-
return do_core_query(statement, opts, query_context);
178+
return do_core_query(statement, opts, std::move(query_context));
161179
};
162180

163181
/**

0 commit comments

Comments
 (0)