Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CXXCBC-412: Support document_not_locked #491

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/impl/key_value_error_category.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ struct key_value_error_category : std::error_category {
return "xattr_unknown_virtual_attribute (127)";
case errc::key_value::xattr_cannot_modify_virtual_attribute:
return "xattr_cannot_modify_virtual_attribute (128)";
case errc::key_value::cannot_revive_living_document:
return "cannot_revive_living_document (131)";
case errc::key_value::xattr_no_access:
return "xattr_no_access (130)";
case errc::key_value::document_not_locked:
return "document_not_locked (131)";
case errc::key_value::cannot_revive_living_document:
return "cannot_revive_living_document (132)";
case errc::key_value::mutation_token_outdated:
return "mutation_token_outdated (133)";
case errc::key_value::range_scan_completed:
Expand Down
5 changes: 5 additions & 0 deletions core/meta/features.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@
* couchbase::cluster::search_query() and couchbase::scope::search_query() support
*/
#define COUCHBASE_CXX_CLIENT_HAS_PUBLIC_SEARCH 1

/**
* The document not locked (couchbase::errc::key_value::document_not_locked) error code is supported
*/
#define COUCHBASE_CXX_CLIENT_HAS_ERRC_DOCUMENT_NOT_LOCKED 1
3 changes: 3 additions & 0 deletions core/protocol/status.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ map_status_code(protocol::client_opcode opcode, std::uint16_t status)
}
return errc::key_value::document_locked;

case key_value_status_code::not_locked:
return errc::key_value::document_not_locked;

case key_value_status_code::auth_stale:
case key_value_status_code::auth_error:
case key_value_status_code::no_access:
Expand Down
1 change: 1 addition & 0 deletions core/protocol/status.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ is_valid_status(std::uint16_t code)
case key_value_status_code::not_my_vbucket:
case key_value_status_code::no_bucket:
case key_value_status_code::locked:
case key_value_status_code::not_locked:
case key_value_status_code::auth_stale:
case key_value_status_code::auth_error:
case key_value_status_code::auth_continue:
Expand Down
23 changes: 22 additions & 1 deletion couchbase/error_codes.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -590,16 +590,37 @@ enum class key_value {
// KV Code: 0x24
xattr_no_access = 130,

/**
* The document is already locked - generally returned when an unlocking operation is being performed.
*
* @since 1.0.0
* @committed
*/
// KV Code: 0x0e
document_not_locked = 131,

/**
* Only deleted document could be revived
*
* @since 1.0.0
* @committed
*/
// KV Code: 0xd6
cannot_revive_living_document = 131,
cannot_revive_living_document = 132,

/**
* The provided mutation token is outdated compared to the current state of the server.
*
* @since 1.0.0
* @uncommitted
*/
// KV Code: 0xa8
mutation_token_outdated = 133,

/**
* @internal
*/
// KV Code: 0xa7
range_scan_completed = 134,
};

Expand Down
3 changes: 3 additions & 0 deletions couchbase/fmt/key_value_status_code.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ struct fmt::formatter<couchbase::key_value_status_code> {
case key_value_status_code::locked:
name = "locked (0x09)";
break;
case key_value_status_code::not_locked:
name = "not_locked (0x0e)";
break;
case key_value_status_code::auth_stale:
name = "auth_stale (0x1f)";
break;
Expand Down
1 change: 1 addition & 0 deletions couchbase/key_value_status_code.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum class key_value_status_code : std::uint16_t {
dcp_stream_not_found = 0x0a,
opaque_no_match = 0x0b,
locked = 0x09,
not_locked = 0x0e,
auth_stale = 0x1f,
auth_error = 0x20,
auth_continue = 0x21,
Expand Down
18 changes: 18 additions & 0 deletions test/test_integration_crud.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ TEST_CASE("integration: pessimistic locking", "[integration]")
auto resp = test::utils::execute(integration.cluster, req);
REQUIRE_SUCCESS(resp.ctx.ec());
}

if (integration.cluster_version().supports_document_not_locked_status()) {
// if unlock is performer again, a document_not_locked error code should be returned
{
couchbase::core::operations::unlock_request req{ id };
req.cas = cas;
auto resp = test::utils::execute(integration.cluster, req);
REQUIRE(resp.ctx.ec() == couchbase::errc::key_value::document_not_locked);
}
}
}

TEST_CASE("integration: lock/unlock without lock time", "[integration]")
Expand Down Expand Up @@ -909,6 +919,14 @@ TEST_CASE("integration: pessimistic locking with public API", "[integration]")
REQUIRE_SUCCESS(ctx.ec());
}

if (integration.cluster_version().supports_document_not_locked_status()) {
// if unlock is performer again, a document_not_locked error code should be returned
{
auto ctx = collection.unlock(id, cas, {}).get();
REQUIRE(ctx.ec() == couchbase::errc::key_value::document_not_locked);
}
}

// now the key is not locked
{
auto [ctx, resp] = collection.upsert(id, basic_doc, {}).get();
Expand Down
5 changes: 5 additions & 0 deletions test/utils/server_version.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ struct server_version {
return supports_search() && (is_mad_hatter() || is_cheshire_cat() || is_neo());
}

[[nodiscard]] bool supports_document_not_locked_status() const
{
return !use_gocaves && (major > 7 || (major == 7 && minor >= 6));
}

[[nodiscard]] bool is_capella() const
{
return deployment == deployment_type::capella;
Expand Down
Loading