Skip to content

Commit

Permalink
[#25312] DocDB: Table locks : Refactor lock Acquire/Release at master…
Browse files Browse the repository at this point in the history
… to MasterDdl Service

Summary:
As per our discussion, trying to move the master side acquire locks rpc
from TabletService to a master specific one.
Jira: DB-14516

Upgrade/Downgrade safety: New proto definitions introduced. Upgrade safe. Should be safe to downgrade if table/object locks is not used.

Test Plan: yb_build.sh --cxx-test object_lock-test

Reviewers: bkolagani, zdrudi

Reviewed By: zdrudi

Subscribers: yql, ybase

Differential Revision: https://phorge.dev.yugabyte.com/D37266
  • Loading branch information
basavaraj29 authored and amitanandaiyer committed Dec 18, 2024
1 parent eac29fa commit a4a8f7f
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 131 deletions.
8 changes: 6 additions & 2 deletions src/yb/client/client-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ Status YBClient::Data::SyncLeaderMasterRpc(
// These are not actually exposed outside, but it's nice to auto-add using directive.
YB_CLIENT_SPECIALIZE_SIMPLE(AlterNamespace);
YB_CLIENT_SPECIALIZE_SIMPLE(AlterTable);
YB_CLIENT_SPECIALIZE_SIMPLE(AcquireObjectLocksGlobal);
YB_CLIENT_SPECIALIZE_SIMPLE(BackfillIndex);
YB_CLIENT_SPECIALIZE_SIMPLE(ChangeMasterClusterConfig);
YB_CLIENT_SPECIALIZE_SIMPLE(CheckIfPitrActive);
YB_CLIENT_SPECIALIZE_SIMPLE(CreateNamespace);
YB_CLIENT_SPECIALIZE_SIMPLE(CreateTable);
YB_CLIENT_SPECIALIZE_SIMPLE(CreateTablegroup);
Expand All @@ -246,6 +248,7 @@ YB_CLIENT_SPECIALIZE_SIMPLE(FlushTables);
YB_CLIENT_SPECIALIZE_SIMPLE(GetBackfillStatus);
YB_CLIENT_SPECIALIZE_SIMPLE(GetTablegroupSchema);
YB_CLIENT_SPECIALIZE_SIMPLE(GetColocatedTabletSchema);
YB_CLIENT_SPECIALIZE_SIMPLE(GetCompactionStatus);
YB_CLIENT_SPECIALIZE_SIMPLE(GetMasterClusterConfig);
YB_CLIENT_SPECIALIZE_SIMPLE(GetNamespaceInfo);
YB_CLIENT_SPECIALIZE_SIMPLE(GetTableSchema);
Expand All @@ -256,16 +259,15 @@ YB_CLIENT_SPECIALIZE_SIMPLE(IsCreateTableDone);
YB_CLIENT_SPECIALIZE_SIMPLE(IsDeleteNamespaceDone);
YB_CLIENT_SPECIALIZE_SIMPLE(IsDeleteTableDone);
YB_CLIENT_SPECIALIZE_SIMPLE(IsFlushTablesDone);
YB_CLIENT_SPECIALIZE_SIMPLE(GetCompactionStatus);
YB_CLIENT_SPECIALIZE_SIMPLE(IsTruncateTableDone);
YB_CLIENT_SPECIALIZE_SIMPLE(ListClones);
YB_CLIENT_SPECIALIZE_SIMPLE(ListNamespaces);
YB_CLIENT_SPECIALIZE_SIMPLE(ListTablegroups);
YB_CLIENT_SPECIALIZE_SIMPLE(ListTables);
YB_CLIENT_SPECIALIZE_SIMPLE(ListUDTypes);
YB_CLIENT_SPECIALIZE_SIMPLE(ReleaseObjectLocksGlobal);
YB_CLIENT_SPECIALIZE_SIMPLE(TruncateTable);
YB_CLIENT_SPECIALIZE_SIMPLE(ValidateReplicationInfo);
YB_CLIENT_SPECIALIZE_SIMPLE(CheckIfPitrActive);
YB_CLIENT_SPECIALIZE_SIMPLE_EX(Encryption, GetFullUniverseKeyRegistry);
YB_CLIENT_SPECIALIZE_SIMPLE_EX(Admin, AddTransactionStatusTablet);
YB_CLIENT_SPECIALIZE_SIMPLE_EX(Admin, AreNodesSafeToTakeDown);
Expand All @@ -284,6 +286,8 @@ YB_CLIENT_SPECIALIZE_SIMPLE_EX(Client, RedisConfigGet);
YB_CLIENT_SPECIALIZE_SIMPLE_EX(Client, RedisConfigSet);
YB_CLIENT_SPECIALIZE_SIMPLE_EX(Client, ReservePgsqlOids);
YB_CLIENT_SPECIALIZE_SIMPLE_EX(Client, GetStatefulServiceLocation);
YB_CLIENT_SPECIALIZE_SIMPLE_EX(Client, AcquireObjectLocksGlobal);
YB_CLIENT_SPECIALIZE_SIMPLE_EX(Client, ReleaseObjectLocksGlobal);
YB_CLIENT_SPECIALIZE_SIMPLE_EX(Cluster, GetAutoFlagsConfig);
YB_CLIENT_SPECIALIZE_SIMPLE_EX(Cluster, ValidateAutoFlagsConfig);
YB_CLIENT_SPECIALIZE_SIMPLE_EX(Cluster, IsLoadBalanced);
Expand Down
37 changes: 37 additions & 0 deletions src/yb/client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ using google::protobuf::RepeatedPtrField;
using std::make_pair;
using std::string;
using std::vector;
using yb::master::AcquireObjectLocksGlobalRequestPB;
using yb::master::AcquireObjectLocksGlobalResponsePB;
using yb::master::AddTransactionStatusTabletRequestPB;
using yb::master::AddTransactionStatusTabletResponsePB;
using yb::master::AlterRoleRequestPB;
Expand Down Expand Up @@ -219,6 +221,8 @@ using yb::master::RedisConfigGetRequestPB;
using yb::master::RedisConfigGetResponsePB;
using yb::master::RedisConfigSetRequestPB;
using yb::master::RedisConfigSetResponsePB;
using yb::master::ReleaseObjectLocksGlobalRequestPB;
using yb::master::ReleaseObjectLocksGlobalResponsePB;
using yb::master::ReplicationInfoPB;
using yb::master::ReservePgsqlOidsRequestPB;
using yb::master::ReservePgsqlOidsResponsePB;
Expand Down Expand Up @@ -3035,5 +3039,38 @@ void YBClient::RequestAbortAllRpcs() {
data_->rpcs_.RequestAbortAll();
}

Status YBClient::AcquireObjectLocksGlobal(const tserver::AcquireObjectLockRequestPB& lock_req) {
LOG_WITH_FUNC(INFO) << lock_req.ShortDebugString();
AcquireObjectLocksGlobalRequestPB req;
AcquireObjectLocksGlobalResponsePB resp;
req.set_txn_id(lock_req.txn_id());
req.set_txn_reuse_version(lock_req.txn_reuse_version());
req.set_subtxn_id(lock_req.subtxn_id());
req.set_session_host_uuid(lock_req.session_host_uuid());
req.mutable_object_locks()->CopyFrom(lock_req.object_locks());
CALL_SYNC_LEADER_MASTER_RPC(req, resp, AcquireObjectLocksGlobal);
if (resp.has_error()) {
return StatusFromPB(resp.error().status());
}
return Status::OK();
}

Status YBClient::ReleaseObjectLocksGlobal(const tserver::ReleaseObjectLockRequestPB& release_req) {
LOG_WITH_FUNC(INFO) << release_req.ShortDebugString();
ReleaseObjectLocksGlobalRequestPB req;
ReleaseObjectLocksGlobalResponsePB resp;
req.set_txn_id(release_req.txn_id());
req.set_txn_reuse_version(release_req.txn_reuse_version());
req.set_subtxn_id(release_req.subtxn_id());
req.set_session_host_uuid(release_req.session_host_uuid());
req.mutable_object_locks()->CopyFrom(release_req.object_locks());
req.set_release_all_locks(release_req.release_all_locks());
CALL_SYNC_LEADER_MASTER_RPC(req, resp, ReleaseObjectLocksGlobal);
if (resp.has_error()) {
return StatusFromPB(resp.error().status());
}
return Status::OK();
}

} // namespace client
} // namespace yb
5 changes: 5 additions & 0 deletions src/yb/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
#include "yb/server/clock.h"

#include "yb/tserver/pg_client.pb.h"
#include "yb/tserver/tserver.pb.h"

#include "yb/util/enums.h"
#include "yb/util/mem_tracker.h"
#include "yb/util/monotime.h"
Expand Down Expand Up @@ -1053,6 +1055,9 @@ class YBClient {

void RequestAbortAllRpcs();

Status AcquireObjectLocksGlobal(const tserver::AcquireObjectLockRequestPB& lock_req);
Status ReleaseObjectLocksGlobal(const tserver::ReleaseObjectLockRequestPB& release_req);

private:
class Data;

Expand Down
5 changes: 5 additions & 0 deletions src/yb/common/common_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ DEFINE_NON_RUNTIME_bool(TEST_ysql_hide_catalog_version_increment_log, false,
"Hide catalog version increment log messages.");
TAG_FLAG(TEST_ysql_hide_catalog_version_increment_log, hidden);

DEFINE_test_flag(bool, enable_object_locking_for_table_locks, false,
"This test flag enables the object lock APIs provided by tservers and masters - "
"AcquireObject(Global)Lock, ReleaseObject(Global)Lock. These APIs are used to "
"implement pg table locks.");

// The following flags related to the cloud, region and availability zone that an instance is
// started in. These are passed in from whatever provisioning mechanics start the servers. They
// are used for generic placement policies on table creation and tablet load balancing, to
Expand Down
1 change: 1 addition & 0 deletions src/yb/common/common_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ DECLARE_bool(TEST_ysql_hide_catalog_version_increment_log);
DECLARE_bool(TEST_check_catalog_version_overflow);
DECLARE_int32(ysql_clone_pg_schema_rpc_timeout_ms);
DECLARE_bool(ysql_enable_auto_analyze_service);
DECLARE_bool(TEST_enable_object_locking_for_table_locks);

namespace yb {

Expand Down
Loading

0 comments on commit a4a8f7f

Please sign in to comment.