Skip to content

Commit 1a61a47

Browse files
authored
Set value of subdoc exists to true/false when the result is no-error or path-not-found (#452)
1 parent a94d88d commit 1a61a47

7 files changed

+60
-53
lines changed

core/impl/lookup_in_all_replicas.cxx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ initiate_lookup_in_all_replicas_operation(std::shared_ptr<cluster> core,
114114
lookup_in_entry.exists = field.exists;
115115
lookup_in_entry.original_index = field.original_index;
116116
lookup_in_entry.ec = field.ec;
117-
if (field.opcode == protocol::subdoc_opcode::exists && field.ec == errc::key_value::path_not_found) {
118-
lookup_in_entry.ec.clear();
119-
}
120117
entries.emplace_back(lookup_in_entry);
121118
}
122119
ctx->result_.emplace_back(lookup_in_replica_result{ resp.cas, entries, resp.deleted, true /* replica */ });
@@ -160,9 +157,6 @@ initiate_lookup_in_all_replicas_operation(std::shared_ptr<cluster> core,
160157
lookup_in_entry.exists = field.exists;
161158
lookup_in_entry.original_index = field.original_index;
162159
lookup_in_entry.ec = field.ec;
163-
if (field.opcode == protocol::subdoc_opcode::exists && field.ec == errc::key_value::path_not_found) {
164-
lookup_in_entry.ec.clear();
165-
}
166160
entries.emplace_back(lookup_in_entry);
167161
}
168162
ctx->result_.emplace_back(lookup_in_replica_result{ resp.cas, entries, resp.deleted, false /* active */ });

core/impl/lookup_in_any_replica.cxx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ initiate_lookup_in_any_replica_operation(std::shared_ptr<cluster> core,
119119
entry.exists = field.exists;
120120
entry.value = field.value;
121121
entry.ec = field.ec;
122-
if (field.opcode == protocol::subdoc_opcode::exists &&
123-
field.ec == errc::key_value::path_not_found) {
124-
entry.ec.clear();
125-
}
126122
entries.emplace_back(entry);
127123
}
128124
return local_handler(std::move(resp.ctx),
@@ -162,9 +158,6 @@ initiate_lookup_in_any_replica_operation(std::shared_ptr<cluster> core,
162158
entry.exists = field.exists;
163159
entry.value = field.value;
164160
entry.ec = field.ec;
165-
if (field.opcode == protocol::subdoc_opcode::exists && field.ec == errc::key_value::path_not_found) {
166-
entry.ec.clear();
167-
}
168161
entries.emplace_back(entry);
169162
}
170163
return local_handler(std::move(resp.ctx),

core/impl/lookup_in_replica.cxx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ lookup_in_replica_request::make_response(key_value_error_context&& ctx, const en
7070
fields[i].status = res_entry.status;
7171
fields[i].ec =
7272
protocol::map_status_code(protocol::client_opcode::subdoc_multi_mutation, static_cast<std::uint16_t>(res_entry.status));
73+
if (fields[i].opcode == protocol::subdoc_opcode::exists && fields[i].ec == errc::key_value::path_not_found) {
74+
fields[i].ec.clear();
75+
}
7376
if (!fields[i].ec && !ctx.ec()) {
7477
ec = fields[i].ec;
7578
}
@@ -79,7 +82,11 @@ lookup_in_replica_request::make_response(key_value_error_context&& ctx, const en
7982
}
8083
fields[i].exists =
8184
res_entry.status == key_value_status_code::success || res_entry.status == key_value_status_code::subdoc_success_deleted;
82-
fields[i].value = utils::to_binary(res_entry.value);
85+
if (fields[i].opcode == protocol::subdoc_opcode::exists && !fields[i].ec) {
86+
fields[i].value = utils::json::generate_binary(fields[i].exists);
87+
} else {
88+
fields[i].value = utils::to_binary(res_entry.value);
89+
}
8390
}
8491
if (!ec) {
8592
cas = encoded.cas();

core/operations/document_lookup_in.cxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ lookup_in_request::make_response(key_value_error_context&& ctx, const encoded_re
8282
}
8383
fields[i].exists =
8484
res_entry.status == key_value_status_code::success || res_entry.status == key_value_status_code::subdoc_success_deleted;
85-
fields[i].value = utils::to_binary(res_entry.value);
85+
if (fields[i].opcode == protocol::subdoc_opcode::exists && !fields[i].ec) {
86+
fields[i].value = utils::json::generate_binary(fields[i].exists);
87+
} else {
88+
fields[i].value = utils::to_binary(res_entry.value);
89+
}
8690
}
8791
if (!ec) {
8892
cas = encoded.cas();

core/operations/document_lookup_in_all_replicas.hxx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ struct lookup_in_all_replicas_request {
127127
lookup_in_entry.exists = field.exists;
128128
lookup_in_entry.original_index = field.original_index;
129129
lookup_in_entry.opcode = field.opcode;
130-
if (lookup_in_entry.opcode == protocol::subdoc_opcode::exists &&
131-
lookup_in_entry.ec == errc::key_value::path_not_found) {
132-
lookup_in_entry.ec.clear();
133-
}
134130
top_entry.fields.emplace_back(lookup_in_entry);
135131
}
136132
ctx->result_.emplace_back(lookup_in_all_replicas_response::entry{ top_entry });
@@ -173,10 +169,6 @@ struct lookup_in_all_replicas_request {
173169
lookup_in_entry.exists = field.exists;
174170
lookup_in_entry.original_index = field.original_index;
175171
lookup_in_entry.opcode = field.opcode;
176-
if (lookup_in_entry.opcode == protocol::subdoc_opcode::exists &&
177-
lookup_in_entry.ec == errc::key_value::path_not_found) {
178-
lookup_in_entry.ec.clear();
179-
}
180172
top_entry.fields.emplace_back(lookup_in_entry);
181173
}
182174
ctx->result_.emplace_back(lookup_in_all_replicas_response::entry{ top_entry });

core/operations/document_lookup_in_any_replica.hxx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ struct lookup_in_any_replica_request {
133133
lookup_in_entry.exists = field.exists;
134134
lookup_in_entry.original_index = field.original_index;
135135
lookup_in_entry.opcode = field.opcode;
136-
if (lookup_in_entry.opcode == protocol::subdoc_opcode::exists &&
137-
lookup_in_entry.ec == errc::key_value::path_not_found) {
138-
lookup_in_entry.ec.clear();
139-
}
140136
res.fields.emplace_back(lookup_in_entry);
141137
}
142138
return local_handler(res);
@@ -177,10 +173,6 @@ struct lookup_in_any_replica_request {
177173
lookup_in_entry.exists = field.exists;
178174
lookup_in_entry.original_index = field.original_index;
179175
lookup_in_entry.opcode = field.opcode;
180-
if (lookup_in_entry.opcode == protocol::subdoc_opcode::exists &&
181-
lookup_in_entry.ec == errc::key_value::path_not_found) {
182-
lookup_in_entry.ec.clear();
183-
}
184176
res.fields.emplace_back(lookup_in_entry);
185177
}
186178
return local_handler(res);

0 commit comments

Comments
 (0)