From 16262f7d919049950035252fa161f2c31b2f59d7 Mon Sep 17 00:00:00 2001 From: Dmitry Uspenskiy <47734295+d-uspenskiy@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:31:15 +0300 Subject: [PATCH] [#22519] YSQL: Simplify API of the ExplicitRowLockBuffer class Summary: This diff simplifies API of the `ExplicitRowLockBuffer` class by omitting `ybctid_reader` argument from `Add` and `Flush` methods. The `ybctid_reader` is stored as an object field instead. **Note:** In context of this class several formatting changes are performed. Jira: DB-11445 Test Plan: Jenkins Reviewers: pjain, kramanathan, telgersma, myang Reviewed By: kramanathan Subscribers: ybase, yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D37467 --- src/yb/util/lw_function.h | 6 +-- src/yb/yql/pggate/pg_doc_metrics.cc | 4 +- src/yb/yql/pggate/pg_doc_metrics.h | 4 +- src/yb/yql/pggate/pg_function.cc | 8 ++-- src/yb/yql/pggate/pg_function.h | 8 ++-- src/yb/yql/pggate/pg_session.cc | 53 ++++++++++++++--------- src/yb/yql/pggate/pg_session.h | 37 ++++++++-------- src/yb/yql/pggate/pggate.cc | 65 ++++++++++------------------- src/yb/yql/pggate/pggate.h | 8 ++-- src/yb/yql/pggate/ybc_pggate.cc | 8 ++-- 10 files changed, 97 insertions(+), 104 deletions(-) diff --git a/src/yb/util/lw_function.h b/src/yb/util/lw_function.h index 07ddac3c59c9..7126e14d9283 100644 --- a/src/yb/util/lw_function.h +++ b/src/yb/util/lw_function.h @@ -1,4 +1,4 @@ -// Copyright (c) YugaByte, Inc. +// Copyright (c) YugaByteDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -27,7 +27,7 @@ template class LightweightFunction { public: Ret operator()(Args... args) const { - return Call(std::move(args)...); + return Call(std::forward(args)...); } protected: @@ -71,7 +71,7 @@ class LightweightFunctionImpl : public LWFunction { private: Ret Call(Args... args) const override { - return Trans::Transform(functor_)(std::move(args)...); + return Trans::Transform(functor_)(std::forward(args)...); } const Func& functor_; diff --git a/src/yb/yql/pggate/pg_doc_metrics.cc b/src/yb/yql/pggate/pg_doc_metrics.cc index 2fa70c9f83bc..8f9424ca9538 100644 --- a/src/yb/yql/pggate/pg_doc_metrics.cc +++ b/src/yb/yql/pggate/pg_doc_metrics.cc @@ -1,5 +1,5 @@ //-------------------------------------------------------------------------------------------------- -// Copyright (c) YugaByte, Inc. +// Copyright (c) YugaByteDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -68,7 +68,7 @@ PgDocMetrics::DurationWatcher::~DurationWatcher() { *duration_ = GetNow(use_zero_duration_, use_high_res_timer_) - start_; } -PgDocMetrics::PgDocMetrics(YBCPgExecStatsState* state) : state_(*state) {} +PgDocMetrics::PgDocMetrics(YBCPgExecStatsState& state) : state_(state) {} void PgDocMetrics::ReadRequest(TableType relation, uint64_t wait_time) { IncRead(&GetStat(&state_, relation), wait_time); diff --git a/src/yb/yql/pggate/pg_doc_metrics.h b/src/yb/yql/pggate/pg_doc_metrics.h index e404e0defdb0..999aeb9cc3b7 100644 --- a/src/yb/yql/pggate/pg_doc_metrics.h +++ b/src/yb/yql/pggate/pg_doc_metrics.h @@ -1,5 +1,5 @@ //-------------------------------------------------------------------------------------------------- -// Copyright (c) YugaByte, Inc. +// Copyright (c) YugaByteDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -33,7 +33,7 @@ YB_DEFINE_ENUM(TableType, (SYSTEM)(USER)(INDEX)); class PgDocMetrics { public: - explicit PgDocMetrics(YBCPgExecStatsState* state); + explicit PgDocMetrics(YBCPgExecStatsState& state); void ReadRequest(TableType relation, uint64_t wait_time); void WriteRequest(TableType relation); diff --git a/src/yb/yql/pggate/pg_function.cc b/src/yb/yql/pggate/pg_function.cc index fc0bc7c370c7..f1af54bd7eb3 100644 --- a/src/yb/yql/pggate/pg_function.cc +++ b/src/yb/yql/pggate/pg_function.cc @@ -1,5 +1,5 @@ //-------------------------------------------------------------------------------------------------- -// Copyright (c) YugaByte, Inc. +// Copyright (c) YugaByteDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -74,12 +74,12 @@ PgFunctionParams::GetValueAndType(const std::string& name) const { //-------------------------------------------------------------------------------------------------- Status PgFunction::AddParam( - const std::string name, const YBCPgTypeEntity* type_entity, uint64_t datum, bool is_null) { + const std::string& name, const YBCPgTypeEntity* type_entity, uint64_t datum, bool is_null) { return params_.AddParam(name, type_entity, datum, is_null); } Status PgFunction::AddTarget( - const std::string name, const YBCPgTypeEntity* type_entity, const YBCPgTypeAttrs type_attrs) { + const std::string& name, const YBCPgTypeEntity* type_entity, const YBCPgTypeAttrs type_attrs) { RETURN_NOT_OK(schema_builder_.AddColumn(name, ToLW(PersistentDataType(type_entity->yb_type)))); RETURN_NOT_OK(schema_builder_.SetColumnPGType(name, type_entity->type_oid)); return schema_builder_.SetColumnPGTypmod(name, type_attrs.typmod); @@ -240,7 +240,7 @@ Result> GetDecodedBlockerTransactionIds( Result> PgLockStatusRequestor( const PgFunctionParams& params, const Schema& schema, const ReaderProjection& projection, - const scoped_refptr pg_session) { + const scoped_refptr& pg_session) { std::string table_id; const auto [relation, rel_null] = VERIFY_RESULT(params.GetParamValue("relation")); if (!rel_null) { diff --git a/src/yb/yql/pggate/pg_function.h b/src/yb/yql/pggate/pg_function.h index 741ddeb622a6..28a8b0484213 100644 --- a/src/yb/yql/pggate/pg_function.h +++ b/src/yb/yql/pggate/pg_function.h @@ -1,5 +1,5 @@ //-------------------------------------------------------------------------------------------------- -// Copyright (c) YugaByte, Inc. +// Copyright (c) YugaByteDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -82,10 +82,10 @@ class PgFunction : public PgMemctx::Registrable { virtual ~PgFunction() = default; Status AddParam( - const std::string name, const YBCPgTypeEntity* type_entity, uint64_t datum, bool is_null); + const std::string& name, const YBCPgTypeEntity* type_entity, uint64_t datum, bool is_null); Status AddTarget( - const std::string name, const YBCPgTypeEntity* type_entity, const YBCPgTypeAttrs type_attrs); + const std::string& name, const YBCPgTypeEntity* type_entity, const YBCPgTypeAttrs type_attrs); Status FinalizeTargets(); @@ -109,7 +109,7 @@ class PgFunction : public PgMemctx::Registrable { Result> PgLockStatusRequestor( const PgFunctionParams& params, const Schema& schema, - const dockv::ReaderProjection& reader_projection, const scoped_refptr pg_session); + const dockv::ReaderProjection& reader_projection, const scoped_refptr& pg_session); } // namespace pggate } // namespace yb diff --git a/src/yb/yql/pggate/pg_session.cc b/src/yb/yql/pggate/pg_session.cc index 4cb2f5227913..de8834c15891 100644 --- a/src/yb/yql/pggate/pg_session.cc +++ b/src/yb/yql/pggate/pg_session.cc @@ -1,5 +1,5 @@ //-------------------------------------------------------------------------------------------------- -// Copyright (c) YugaByte, Inc. +// Copyright (c) YugaByteDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -49,7 +49,6 @@ #include "yb/yql/pggate/pg_client.h" #include "yb/yql/pggate/pg_expr.h" #include "yb/yql/pggate/pg_op.h" -#include "yb/yql/pggate/pg_txn_manager.h" #include "yb/yql/pggate/pggate_flags.h" #include "yb/yql/pggate/ybc_pggate.h" @@ -100,7 +99,7 @@ bool IsNeedTransaction(const PgsqlOp& op, bool non_ddl_txn_for_sys_tables_allowe // Last statement inserts row with k = 1 and this is a single row transaction. // But row with k = 1 already exists in the t table. As a result the // 'duplicate key value violates unique constraint "t_pkey"' will be raised. - // But this error contains contraints name which is read from sys table pg_class (in case it + // But this error contains constraints name which is read from sys table pg_class (in case it // is not yet in the postgres's cache). And this read from sys table will be performed in context // of currently running transaction (single row) because the yb_non_ddl_txn_for_sys_tables_allowed // GUC variable is true. As a result there will be 2 operations in context of single row @@ -404,15 +403,16 @@ size_t TableYbctidHasher::operator()(const TableYbctid& value) const { return (*this)(static_cast(value)); } -ExplicitRowLockBuffer::ExplicitRowLockBuffer(TableYbctidVectorProvider* ybctid_container_provider) - : ybctid_container_provider_(*ybctid_container_provider) { +ExplicitRowLockBuffer::ExplicitRowLockBuffer( + TableYbctidVectorProvider& ybctid_container_provider, + std::reference_wrapper ybctid_reader) + : ybctid_container_provider_(ybctid_container_provider), ybctid_reader_(ybctid_reader) { } Status ExplicitRowLockBuffer::Add( - Info&& info, const LightweightTableYbctid& key, bool is_region_local, - const YbctidReader& reader) { + Info&& info, const LightweightTableYbctid& key, bool is_region_local) { if (info_ && *info_ != info) { - RETURN_NOT_OK(DoFlush(reader)); + RETURN_NOT_OK(DoFlush()); } if (!info_) { info_.emplace(std::move(info)); @@ -426,14 +426,14 @@ Status ExplicitRowLockBuffer::Add( DCHECK(is_region_local || !region_local_tables_.contains(key.table_id)); intents_.emplace(key.table_id, std::string(key.ybctid)); return narrow_cast(intents_.size()) >= yb_explicit_row_locking_batch_size - ? DoFlush(reader) : Status::OK(); + ? DoFlush() : Status::OK(); } -Status ExplicitRowLockBuffer::Flush(const YbctidReader& reader) { - return IsEmpty() ? Status::OK() : DoFlush(reader); +Status ExplicitRowLockBuffer::Flush() { + return IsEmpty() ? Status::OK() : DoFlush(); } -Status ExplicitRowLockBuffer::DoFlush(const YbctidReader& reader) { +Status ExplicitRowLockBuffer::DoFlush() { DCHECK(!IsEmpty()); auto scope = ScopeExit([this] { Clear(); }); auto ybctids = ybctid_container_provider_.Get(); @@ -443,7 +443,14 @@ Status ExplicitRowLockBuffer::DoFlush(const YbctidReader& reader) { auto node = intents_.extract(it++); ybctids->push_back(std::move(node.value())); } - RETURN_NOT_OK(reader(&*ybctids, *info_, region_local_tables_)); + RETURN_NOT_OK(ybctid_reader_( + info_->database_id, ybctids, region_local_tables_, + make_lw_function( + [&info = *info_](PgExecParameters& params) { + params.rowmark = info.rowmark; + params.pg_wait_policy = info.pg_wait_policy; + params.docdb_wait_policy = info.docdb_wait_policy; + }))); SCHECK(initial_intents_size == ybctids->size(), NotFound, "Some of the requested ybctids are missing"); return Status::OK(); @@ -464,13 +471,15 @@ bool ExplicitRowLockBuffer::IsEmpty() const { //-------------------------------------------------------------------------------------------------- PgSession::PgSession( - PgClient* pg_client, + PgClient& pg_client, scoped_refptr pg_txn_manager, const YBCPgCallbacks& pg_callbacks, - YBCPgExecStatsState* stats_state) - : pg_client_(*pg_client), + YBCPgExecStatsState& stats_state, + YbctidReader&& ybctid_reader) + : pg_client_(pg_client), pg_txn_manager_(std::move(pg_txn_manager)), - explicit_row_lock_buffer_(&aux_ybctid_container_provider_), + ybctid_reader_(std::move(ybctid_reader)), + explicit_row_lock_buffer_(aux_ybctid_container_provider_, ybctid_reader_), metrics_(stats_state), pg_callbacks_(pg_callbacks), buffer_( @@ -856,8 +865,8 @@ Result PgSession::Perform(BufferableOperations&& ops, PerformOpti return PerformFuture(std::move(future), std::move(ops.relations)); } -Result PgSession::ForeignKeyReferenceExists(const LightweightTableYbctid& key, - const YbctidReader& reader) { +Result PgSession::ForeignKeyReferenceExists( + PgOid database_id, const LightweightTableYbctid& key) { if (fk_reference_cache_.find(key) != fk_reference_cache_.end()) { return true; } @@ -889,7 +898,11 @@ Result PgSession::ForeignKeyReferenceExists(const LightweightTableYbctid& } // Add the keys found in docdb to the FK cache. - RETURN_NOT_OK(reader(&ybctids, fk_intent_region_local_tables_)); + RETURN_NOT_OK(ybctid_reader_( + database_id, ybctids, fk_intent_region_local_tables_, + make_lw_function([](PgExecParameters& params) { + params.rowmark = ROW_MARK_KEYSHARE; + }))); for (auto& ybctid : ybctids) { fk_reference_cache_.insert(std::move(ybctid)); } diff --git a/src/yb/yql/pggate/pg_session.h b/src/yb/yql/pggate/pg_session.h index d85cc1c8ede3..56099ee19e06 100644 --- a/src/yb/yql/pggate/pg_session.h +++ b/src/yb/yql/pggate/pg_session.h @@ -1,4 +1,4 @@ -// Copyright (c) YugaByte, Inc. +// Copyright (c) YugaByteDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -13,6 +13,7 @@ #pragma once +#include #include #include #include @@ -50,9 +51,6 @@ YB_STRONGLY_TYPED_BOOL(InvalidateOnPgClient); YB_STRONGLY_TYPED_BOOL(UseCatalogSession); YB_STRONGLY_TYPED_BOOL(ForceNonBufferable); -class PgTxnManager; -class PgSession; - struct LightweightTableYbctid { LightweightTableYbctid(PgOid table_id_, const std::string_view& ybctid_) : table_id(table_id_), ybctid(ybctid_) {} @@ -134,6 +132,11 @@ class TableYbctidVectorProvider { TableYbctidVector container_; }; +using ExecParametersMutator = LWFunction; + +using YbctidReader = + std::function; + class ExplicitRowLockBuffer { public: struct Info { @@ -145,20 +148,20 @@ class ExplicitRowLockBuffer { friend bool operator==(const Info&, const Info&) = default; }; - using YbctidReader = LWFunction; - - explicit ExplicitRowLockBuffer(TableYbctidVectorProvider* ybctid_container_provider); + ExplicitRowLockBuffer( + TableYbctidVectorProvider& ybctid_container_provider, + std::reference_wrapper ybctid_reader); Status Add( - Info&& info, const LightweightTableYbctid& key, bool is_region_local, - const YbctidReader& reader); - Status Flush(const YbctidReader& reader); + Info&& info, const LightweightTableYbctid& key, bool is_region_local); + Status Flush(); void Clear(); bool IsEmpty() const; private: - Status DoFlush(const YbctidReader& reader); + Status DoFlush(); TableYbctidVectorProvider& ybctid_container_provider_; + const YbctidReader& ybctid_reader_; TableYbctidSet intents_; OidSet region_local_tables_; std::optional info_; @@ -173,11 +176,12 @@ class PgSession : public RefCountedThreadSafe { // Constructors. PgSession( - PgClient* pg_client, + PgClient& pg_client, scoped_refptr pg_txn_manager, const YBCPgCallbacks& pg_callbacks, - YBCPgExecStatsState* stats_state); - virtual ~PgSession(); + YBCPgExecStatsState& stats_state, + YbctidReader&& ybctid_reader); + ~PgSession(); // Resets the read point for catalog tables. // Next catalog read operation will read the very latest catalog's state. @@ -341,9 +345,7 @@ class PgSession : public RefCountedThreadSafe { // Check if initdb has already been run before. Needed to make initdb idempotent. Result IsInitDbDone(); - using YbctidReader = LWFunction; - Result ForeignKeyReferenceExists( - const LightweightTableYbctid& key, const YbctidReader& reader); + Result ForeignKeyReferenceExists(PgOid database_id, const LightweightTableYbctid& key); void AddForeignKeyReferenceIntent(const LightweightTableYbctid& key, bool is_region_local); void AddForeignKeyReference(const LightweightTableYbctid& key); @@ -445,6 +447,7 @@ class PgSession : public RefCountedThreadSafe { CoarseTimePoint invalidate_table_cache_time_; std::unordered_map table_cache_; + const YbctidReader ybctid_reader_; TableYbctidSet fk_reference_cache_; TableYbctidSet fk_reference_intent_; OidSet fk_intent_region_local_tables_; diff --git a/src/yb/yql/pggate/pggate.cc b/src/yb/yql/pggate/pggate.cc index 1180ec41ea40..d1c95fc0c21d 100644 --- a/src/yb/yql/pggate/pggate.cc +++ b/src/yb/yql/pggate/pggate.cc @@ -1,5 +1,5 @@ //-------------------------------------------------------------------------------------------------- -// Copyright (c) YugaByte, Inc. +// Copyright (c) YugaByteDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -15,7 +15,6 @@ #include "yb/yql/pggate/pggate.h" #include -#include #include #include #include @@ -79,8 +78,6 @@ #include "yb/yql/pggate/ybc_pggate.h" using namespace std::literals; -using std::string; -using std::vector; DECLARE_bool(use_node_to_node_encryption); DECLARE_string(certs_dir); @@ -129,7 +126,7 @@ Status AddColumn(PgCreateTable* pg_stmt, const char *attr_name, int attr_num, } Result BuildMessenger( - const string& client_name, + const std::string& client_name, int32_t num_reactors, const scoped_refptr& metric_entity, const std::shared_ptr& parent_mem_tracker) { @@ -240,15 +237,13 @@ class PrecastRequestSender { boost::container::small_vector ops_; }; -using ExecParametersMutator = std::function; - Status FetchExistingYbctids(const PgSession::ScopedRefPtr& session, PgOid database_id, - TableYbctidVector* ybctids, + TableYbctidVector& ybctids, const OidSet& region_local_tables, const ExecParametersMutator& exec_params_mutator) { // Group the items by the table ID. - std::sort(ybctids->begin(), ybctids->end(), [](const auto& a, const auto& b) { + std::sort(ybctids.begin(), ybctids.end(), [](const auto& a, const auto& b) { return a.table_id < b.table_id; }); @@ -265,7 +260,7 @@ Status FetchExistingYbctids(const PgSession::ScopedRefPtr& session, }; // Start all the doc_ops to read from docdb in parallel, one doc_op per table ID. // Each doc_op will use request_sender to send all the requests with single perform RPC. - for (auto it = ybctids->begin(), end = ybctids->end(); it != end;) { + for (auto it = ybctids.begin(), end = ybctids.end(); it != end;) { const auto table_id = it->table_id; auto desc = VERIFY_RESULT(session->LoadTable(PgObjectId(database_id, table_id))); bool is_region_local = region_local_tables.find(table_id) != region_local_tables.end(); @@ -279,7 +274,7 @@ Status FetchExistingYbctids(const PgSession::ScopedRefPtr& session, session, &read_op->table(), std::move(read_op), request_sender)); auto& doc_op = *doc_ops.back(); auto exec_params = doc_op.ExecParameters(); - exec_params_mutator(&exec_params); + exec_params_mutator(exec_params); RETURN_NOT_OK(doc_op.ExecuteInit(&exec_params)); // Populate doc_op with ybctids which belong to current table. RETURN_NOT_OK(doc_op.PopulateByYbctidOps({make_lw_function([&it, table_id, end] { @@ -295,7 +290,7 @@ Status FetchExistingYbctids(const PgSession::ScopedRefPtr& session, // of each doc_op will be sent individually). precast_sender.DisableCollecting(); // Collect the results from the docdb ops. - ybctids->clear(); + ybctids.clear(); for (auto& it : doc_ops) { for (;;) { auto rowsets = VERIFY_RESULT(it->GetResult()); @@ -305,7 +300,7 @@ Status FetchExistingYbctids(const PgSession::ScopedRefPtr& session, for (auto& row : rowsets) { RETURN_NOT_OK(row.ProcessSystemColumns()); for (const auto& ybctid : row.ybctids()) { - ybctids->emplace_back(it->table()->relfilenode_id().object_oid, ybctid.ToBuffer()); + ybctids.emplace_back(it->table()->relfilenode_id().object_oid, ybctid.ToBuffer()); } } } @@ -314,20 +309,6 @@ Status FetchExistingYbctids(const PgSession::ScopedRefPtr& session, return Status::OK(); } -auto MakeYbctidReaderForExplicitRowLock(const PgSession::ScopedRefPtr& session) { - return [&session](TableYbctidVector* ybctids, - const ExplicitRowLockBuffer::Info& info, - const OidSet& region_local_tables) { - return FetchExistingYbctids( - session, info.database_id, ybctids, region_local_tables, - [&info](PgExecParameters* exec_params) { - exec_params->rowmark = info.rowmark; - exec_params->pg_wait_policy = info.pg_wait_policy; - exec_params->docdb_wait_policy = info.docdb_wait_policy; - }); - }; -} - } // namespace //-------------------------------------------------------------------------------------------------- @@ -558,10 +539,16 @@ const YBCPgTypeEntity *PgApiImpl::FindTypeEntity(int type_oid) { //-------------------------------------------------------------------------------------------------- -Status PgApiImpl::InitSession(YBCPgExecStatsState* session_stats) { +Status PgApiImpl::InitSession(YBCPgExecStatsState& session_stats) { CHECK(!pg_session_); + auto session = make_scoped_refptr( - &pg_client_, pg_txn_manager_, pg_callbacks_, session_stats); + pg_client_, pg_txn_manager_, pg_callbacks_, session_stats, + [&pg_session = pg_session_]( + PgOid database_id, TableYbctidVector& ybctids, const OidSet& region_local_tables, + const ExecParametersMutator& mutator) { + return FetchExistingYbctids(pg_session, database_id, ybctids, region_local_tables, mutator); + }); pg_session_.swap(session); return Status::OK(); @@ -1853,7 +1840,7 @@ Status PgApiImpl::NewSRF( } Status PgApiImpl::AddFunctionParam( - PgFunction *handle, const std::string name, const YBCPgTypeEntity *type_entity, uint64_t datum, + PgFunction *handle, const std::string& name, const YBCPgTypeEntity *type_entity, uint64_t datum, bool is_null) { if (!handle) { return STATUS(InvalidArgument, "Invalid function handle"); @@ -1863,7 +1850,7 @@ Status PgApiImpl::AddFunctionParam( } Status PgApiImpl::AddFunctionTarget( - PgFunction *handle, const std::string name, const YBCPgTypeEntity *type_entity, + PgFunction *handle, const std::string& name, const YBCPgTypeEntity *type_entity, const YBCPgTypeAttrs type_attrs) { if (!handle) { return STATUS(InvalidArgument, "Invalid function handle"); @@ -2271,14 +2258,7 @@ void PgApiImpl::ResetCatalogReadTime() { Result PgApiImpl::ForeignKeyReferenceExists( PgOid table_id, const Slice& ybctid, PgOid database_id) { return pg_session_->ForeignKeyReferenceExists( - LightweightTableYbctid(table_id, ybctid), - make_lw_function( - [this, database_id](TableYbctidVector* ybctids, - const OidSet& region_local_tables) { - return FetchExistingYbctids( - pg_session_, database_id, ybctids, region_local_tables, - [](PgExecParameters* exec_params) {exec_params->rowmark = ROW_MARK_KEYSHARE;}); - })); + database_id, LightweightTableYbctid(table_id, ybctid)); } void PgApiImpl::AddForeignKeyReferenceIntent( @@ -2303,14 +2283,11 @@ Status PgApiImpl::AddExplicitRowLockIntent( .pg_wait_policy = params.pg_wait_policy, .docdb_wait_policy = params.docdb_wait_policy, .database_id = table_id.database_oid}, - LightweightTableYbctid(table_id.object_oid, ybctid), - is_region_local, - make_lw_function(MakeYbctidReaderForExplicitRowLock(pg_session_))); + LightweightTableYbctid(table_id.object_oid, ybctid), is_region_local); } Status PgApiImpl::FlushExplicitRowLockIntents() { - return pg_session_->explicit_row_lock_buffer().Flush( - make_lw_function(MakeYbctidReaderForExplicitRowLock(pg_session_))); + return pg_session_->explicit_row_lock_buffer().Flush(); } void PgApiImpl::SetTimeout(int timeout_ms) { diff --git a/src/yb/yql/pggate/pggate.h b/src/yb/yql/pggate/pggate.h index 6f666ea6437e..5b998cb80f3c 100644 --- a/src/yb/yql/pggate/pggate.h +++ b/src/yb/yql/pggate/pggate.h @@ -1,4 +1,4 @@ -// Copyright (c) YugaByte, Inc. +// Copyright (c) YugaByteDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -134,7 +134,7 @@ class PgApiImpl { void ResetCatalogReadTime(); // Initialize a session to process statements that come from the same client connection. - Status InitSession(YBCPgExecStatsState* session_stats); + Status InitSession(YBCPgExecStatsState& session_stats); uint64_t GetSessionID() const; @@ -613,11 +613,11 @@ class PgApiImpl { Status NewSRF(PgFunction **handle, PgFunctionDataProcessor processor); Status AddFunctionParam( - PgFunction *handle, const std::string name, const YBCPgTypeEntity *type_entity, + PgFunction *handle, const std::string& name, const YBCPgTypeEntity *type_entity, uint64_t datum, bool is_null); Status AddFunctionTarget( - PgFunction *handle, const std::string name, const YBCPgTypeEntity *type_entity, + PgFunction *handle, const std::string& name, const YBCPgTypeEntity *type_entity, const YBCPgTypeAttrs type_attrs); Status FinalizeFunctionTargets(PgFunction *handle); diff --git a/src/yb/yql/pggate/ybc_pggate.cc b/src/yb/yql/pggate/ybc_pggate.cc index 809c7c02e352..fbfe48dcaadd 100644 --- a/src/yb/yql/pggate/ybc_pggate.cc +++ b/src/yb/yql/pggate/ybc_pggate.cc @@ -1,4 +1,4 @@ -// Copyright (c) YugaByte, Inc. +// Copyright (c) YugaByteDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at @@ -226,8 +226,8 @@ Status InitPgGateImpl(const YBCPgTypeEntity* data_type_table, }); } -Status PgInitSessionImpl(YBCPgExecStatsState* session_stats) { - return WithMaskedYsqlSignals([session_stats] { return pgapi->InitSession(session_stats); }); +Status PgInitSessionImpl(YBCPgExecStatsState& session_stats) { + return WithMaskedYsqlSignals([&session_stats] { return pgapi->InitSession(session_stats); }); } // ql_value is modified in-place. @@ -566,7 +566,7 @@ void YBCRestorePgSessionState(const YBCPgSessionState* session_data) { } YBCStatus YBCPgInitSession(YBCPgExecStatsState* session_stats) { - return ToYBCStatus(PgInitSessionImpl(session_stats)); + return ToYBCStatus(PgInitSessionImpl(*session_stats)); } uint64_t YBCPgGetSessionID() { return pgapi->GetSessionID(); }