Skip to content

Commit

Permalink
[yugabyte#13733] docdb: Differentiate ybctid and dockey usage for col…
Browse files Browse the repository at this point in the history
…ocation

Summary: Currently dockeys and ybctids are used interchangeably in our code, which can be a bit confusing as there are some key differences. Notably, the main difference is that ybctids do not store any info about colocation ids or cotable ids. As part of simplifying colocation usage across ysql, this diff introduces a new `PgsqlYbctid` class that is just used for ybctids, and that has no references to colocation. Also introduces a `DocKeyBase` abstract class that both `PgsqlYbctid` and `DocKey` inherit from.

Test Plan: Jenkins

Reviewers: alex

Reviewed By: alex

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D19717
  • Loading branch information
hulien22 committed Nov 22, 2022
1 parent 650c831 commit c0e0034
Show file tree
Hide file tree
Showing 9 changed files with 711 additions and 513 deletions.
11 changes: 6 additions & 5 deletions src/yb/client/yb_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
#include "yb/common/wire_protocol.h"
#include "yb/common/wire_protocol.pb.h"

#include "yb/docdb/doc_key.h"
#include "yb/docdb/doc_scanspec_util.h"
#include "yb/docdb/pgsql_ybctid.h"
#include "yb/docdb/primitive_value.h"
#include "yb/docdb/primitive_value_util.h"
#include "yb/rpc/rpc_controller.h"
Expand Down Expand Up @@ -238,9 +238,10 @@ Status SetRangePartitionBounds(const Schema& schema,
key_upper_bound->clear();
return Status::OK();
}
auto upper_bound_key = docdb::DocKey(std::move(range_components_end)).Encode().ToStringBuffer();
auto upper_bound_key =
docdb::PgsqlYbctid(std::move(range_components_end)).Encode().ToStringBuffer();
if (request->is_forward_scan()) {
SetPartitionKey(docdb::DocKey(std::move(range_components)).Encode().AsSlice(), request);
SetPartitionKey(docdb::PgsqlYbctid(std::move(range_components)).Encode().AsSlice(), request);
*key_upper_bound = std::move(upper_bound_key);
} else {
// Backward scan should go from upper bound to lower. But because DocDB can check upper bound
Expand Down Expand Up @@ -351,7 +352,7 @@ Result<std::string> GetRangePartitionKey(
"Cannot get range partition key for hash partitioned table");

auto range_components = VERIFY_RESULT(GetRangeComponents(schema, range_cols, true));
return docdb::DocKey(std::move(range_components)).Encode().ToStringBuffer();
return docdb::PgsqlYbctid(std::move(range_components)).Encode().ToStringBuffer();
}

template<class Req>
Expand All @@ -371,7 +372,7 @@ Status InitWritePartitionKey(
const auto& ybctid = request->ybctid_column_value().value();
if (schema.num_hash_key_columns() > 0) {
if (!IsNull(ybctid)) {
const uint16 hash_code = VERIFY_RESULT(docdb::DocKey::DecodeHash(ybctid.binary_value()));
const uint16 hash_code = VERIFY_RESULT(docdb::PgsqlYbctid::DecodeHash(ybctid.binary_value()));
request->set_hash_code(hash_code);
SetPartitionKey(PartitionSchema::EncodeMultiColumnHashValue(hash_code), request);
return Status::OK();
Expand Down
2 changes: 2 additions & 0 deletions src/yb/docdb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ set(DOCDB_ENCODING_SRCS
primitive_value_util.cc
intent.cc
doc_scanspec_util.cc
doc_key_base.cc
pgsql_ybctid.cc
)

set(DOCDB_ENCODING_DEPS
Expand Down

0 comments on commit c0e0034

Please sign in to comment.