Skip to content

Conversation

Copy link

Copilot AI commented Nov 20, 2025

Migration Complete: Replace Table Service with Query Service for YDB Transactions

✅ All Tasks Completed:

  • Understand the YDB SDK Query Client transaction API
  • Analyze the current transaction implementation
  • Design the migration approach to use Query Client transactions
  • Modify Transaction class to use Query Client types (NYdb::NQuery::TTransaction)
  • Update Transaction constructor
  • Convert Transaction::Execute() to use Query Client ExecuteQuery API
  • Convert Transaction::Commit() to use Query Client methods
  • Convert Transaction::Rollback() to use Query Client methods
  • Update Transaction::GetBuilder() to use Query session
  • Modify TableClient::Begin() to use RetryQuery and Query Client BeginTransaction
  • Add YDB-CPP-SDK::Query library to CMakeLists.txt
  • Implement QuerySettings conversion logic
  • Extract stats mode conversion to separate function (code review feedback)
  • Refine ConvertStatsMode function signature (code review feedback)
  • Fix include in transaction.hpp to use query/query.h (code review feedback)
  • Migrate TableClient::ExecuteDataQuery to Query Client API (code review feedback)
  • Consolidate duplicate ConvertStatsMode implementations (code review feedback)
  • Convert ToExecQuerySettings to free function for Query Client (code review feedback)

📝 Summary of Changes:

1. Transaction Class Header (transaction.hpp)

  • Line 5: Changed include to <ydb-cpp-sdk/client/query/query.h> for transaction types
  • Line 74: Changed constructor parameter from NYdb::NTable::TTransaction to NYdb::NQuery::TTransaction
  • Line 90: Changed member variable from NYdb::NTable::TTransaction ydb_tx_ to NYdb::NQuery::TTransaction ydb_tx_

2. Transaction Implementation (transaction.cpp)

  • Constructor (Lines 22-37): Updated to accept NYdb::NQuery::TTransaction instead of Table transaction
  • Commit() (Lines 70-101): Uses ydb_tx_.Commit() with Query Client settings
  • Rollback() (Lines 103-122): Uses ydb_tx_.Rollback() with Query Client settings
  • Execute() (Lines 138-176): Uses ydb_tx_.GetSession().ExecuteQuery() with Query Client APIs and impl::ConvertStatsMode()
  • GetBuilder() (Lines 124-126): Uses ydb_tx_.GetSession().GetParamsBuilder()

3. TableClient Header (table.hpp)

  • Removed: ToExecQuerySettings() method declaration (was creating Table Client settings)

4. TableClient Implementation (table.cpp)

  • ToExecuteQuerySettings() (Lines 49-59): New free function in anonymous namespace that creates NYdb::NQuery::TExecuteQuerySettings for Query Client
  • Begin() (Lines 297-314): Changed from Table Client to Query Client (RetryQuery, PrepareQueryTxSettings, BeginTransaction)
  • ExecuteDataQuery() (Lines 364-387):
    • Migrated to use Query Client
    • Uses new ToExecuteQuerySettings() free function instead of old member method
    • Uses RetryQuery, ExecuteQuery, and Query Client types throughout
  • Removed: Old ToExecQuerySettings() member method that created Table Client settings

5. Implementation Utilities (impl/operation_settings.hpp, impl/operation_settings.cpp)

  • ConvertStatsMode(): Single shared implementation that converts NYdb::NTable::ECollectQueryStatsMode to NYdb::NQuery::EStatsMode
  • Eliminates code duplication between transaction.cpp and table.cpp

6. Build Configuration (CMakeLists.txt, Line 8)

  • Added YDB-CPP-SDK::Query to YDB_LIBRARIES list

🔑 Key Technical Decisions:

  1. Complete Migration: Both Transaction::Execute() and TableClient::ExecuteDataQuery() now use Query Client
  2. No Code Duplication: Consolidated ConvertStatsMode() into shared impl namespace
  3. Free Function Pattern: Converted ToExecQuerySettings from member method to free function ToExecuteQuerySettings that creates Query Client settings
  4. Transaction Object Model: Query Client provides NYdb::NQuery::TTransaction with similar pattern to Table Client
  5. API Conversion: Consistent pattern for converting QuerySettings across both implementations
  6. Backward Compatibility: All public APIs remain unchanged - only internal implementation uses Query Client

🎯 Benefits:

  • Uses modern Query Client API throughout instead of deprecated Table Client
  • Maintains full backward compatibility with existing code
  • Follows YDB SDK recommended migration path
  • No code duplication - single ConvertStatsMode implementation
  • Clean separation of concerns with free functions for conversions
  • Consistent implementation pattern across Transaction and TableClient
  • No changes required to existing code using these APIs

📚 References:

Original prompt

This section details on the original issue you should resolve

<issue_title>Заменить Table Service на Query Service при работе с YDB транзакциями</issue_title>
<issue_description>При вызове метода Begin создается объект Transaction, который использует для выполнения запросов в YDB устаревший Table Client API. Вместо этого нужно использовать Query Client (класс TQueryClient в YDB С++ SDK).

Для этого нужно:

  1. Создавать транзакцию внутри объекта Transaction через Query Client.
  2. Использовать Query Client для выполнения запросов в методах Execute внутри объекта Transaction
  3. Сохранить сигнатуру существующих методов интерактивной транзакции

Текущая сигнатура Execute зависит от API для Table Client, нужно будет сделать конвертацию под Query Client. Вот примеры такой конвертации в YDB Go SDK и YDB Java SDK.

API Query Client и Table Client немного отличаются, например ExecuteQuery вместо ExecuteDataQuery и RetryQuery вместо RetryOperation. Есть еще отличия, их лучше самому посмотреть в коде YDB C++ SDK: Table Client API и Query Client API.

Код компоненты userver для работы с YDB находится здесь.

Создание транзакции: include, source
Работа с транзакциями: include, source</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 20, 2025 17:17
- Updated Transaction class to use NYdb::NQuery::TSession and transaction ID
- Changed Transaction::Execute() to use Query Client's ExecuteQuery
- Modified Transaction::Commit() and Rollback() to use Query Client APIs
- Updated TableClient::Begin() to use RetryQuery and Query Client BeginTransaction
- Added YDB-CPP-SDK::Query library to CMakeLists.txt
- Added conversion logic for QuerySettings between Table and Query Client APIs

Co-authored-by: asmyasnikov <[email protected]>
- Updated Transaction class to use NYdb::NQuery::TTransaction object
- This matches the pattern of Table Client but uses Query namespace
- Transaction object provides Commit(), Rollback(), and GetSession() methods
- Execute uses TTxControl::Tx(transaction) for transaction control

Co-authored-by: asmyasnikov <[email protected]>
Copilot AI changed the title [WIP] Replace Table Service with Query Service for YDB transactions feat(ydb): migrate transactions from Table Client to Query Client API Nov 20, 2025
Copilot AI requested a review from asmyasnikov November 20, 2025 17:26
Copilot finished work on behalf of asmyasnikov November 20, 2025 17:26
@asmyasnikov asmyasnikov requested a review from Copilot November 20, 2025 17:28
@asmyasnikov asmyasnikov marked this pull request as ready for review November 20, 2025 18:00
@asmyasnikov asmyasnikov requested review from Copilot and removed request for Copilot November 20, 2025 18:02
Extract the stats mode conversion logic from Transaction::Execute() into
a standalone ConvertStatsMode() helper function in anonymous namespace.
This improves code readability and maintainability.

Co-authored-by: asmyasnikov <[email protected]>
Copilot AI requested a review from asmyasnikov November 20, 2025 19:00
Copilot finished work on behalf of asmyasnikov November 20, 2025 19:00
@asmyasnikov asmyasnikov requested review from Copilot and removed request for Copilot November 20, 2025 19:00
asmyasnikov
asmyasnikov previously approved these changes Nov 20, 2025
@robot-magpie
Copy link

robot-magpie bot commented Nov 20, 2025

@asmyasnikov has triggered the import of a pull request, but it hasn't started. If you are a Yandex employee, you can view the log.

Copy link
Collaborator

@asmyasnikov asmyasnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot давай функция ConvertStatsMode будет принимать значение collect_query_stats и отдавать NYdb::NQuery::EStatsMode
именно конвертацию одного енама в другой енам, без лишних зависимостей и вызовов

Change ConvertStatsMode to take collect_query_stats value as input
and return NYdb::NQuery::EStatsMode instead of modifying settings object.
This makes the function more functional and easier to understand.

Co-authored-by: asmyasnikov <[email protected]>
Copilot AI requested a review from asmyasnikov November 20, 2025 20:57
@asmyasnikov
Copy link
Collaborator

@copilot давай переделаем реализацию TableClient::ExecuteDataQuery чтобы она работала на query-клиенте (по аналогии с Transaction::Execute

- Fixed include in transaction.hpp to use query/query.h instead of query/client.h
- Added ConvertStatsMode helper function to table.cpp
- Refactored ExecuteDataQuery to use Query Client (RetryQuery, ExecuteQuery)
  instead of Table Client (RetryOperation, ExecuteDataQuery)
- Convert QuerySettings to Query Client settings similar to Transaction::Execute
- Use PrepareQueryTxSettings and NYdb::NQuery types throughout

Co-authored-by: asmyasnikov <[email protected]>
Copy link
Author

Copilot AI commented Nov 21, 2025

@copilot давай переделаем реализацию TableClient::ExecuteDataQuery чтобы она работала на query-клиенте (по аналогии с Transaction::Execute

Done. Refactored ExecuteDataQuery to use Query Client API similar to Transaction::Execute. Now uses RetryQuery, ExecuteQuery, and converts QuerySettings to Query Client settings. (commit 6cd3cb9)

Copilot AI changed the title feat(ydb): migrate transactions from Table Client to Query Client API feat(ydb): migrate transactions and data queries from Table Client to Query Client API Nov 21, 2025
Copilot AI requested a review from asmyasnikov November 21, 2025 09:15
Copilot finished work on behalf of asmyasnikov November 21, 2025 09:16
@asmyasnikov
Copy link
Collaborator

@copilot в твоем коде копипаста ConvertStatsMode - надо оставить единую реализацию

Moved ConvertStatsMode from duplicate implementations in transaction.cpp
and table.cpp to a single shared implementation in impl/operation_settings.
Both files now use impl::ConvertStatsMode() to avoid code duplication.

Co-authored-by: asmyasnikov <[email protected]>
Copy link
Author

Copilot AI commented Nov 21, 2025

@copilot в твоем коде копипаста ConvertStatsMode - надо оставить единую реализацию

Fixed. Moved ConvertStatsMode to a single shared implementation in ydb/src/ydb/impl/operation_settings.cpp. Both transaction.cpp and table.cpp now use impl::ConvertStatsMode(). (commit 5d89601)

Copilot finished work on behalf of asmyasnikov November 21, 2025 09:41
@asmyasnikov asmyasnikov requested a review from Copilot November 21, 2025 09:49
@kpavlov00
Copy link
Contributor

LGTM

@robot-magpie
Copy link

robot-magpie bot commented Nov 21, 2025

@kpavlov00 has triggered the import of a pull request, but it hasn't started. If you are a Yandex employee, you can view the log.

Copilot finished reviewing on behalf of asmyasnikov November 21, 2025 11:08
@kpavlov00
Copy link
Contributor

LGTM

@robot-magpie
Copy link

robot-magpie bot commented Nov 21, 2025

@kpavlov00 has triggered the import of a pull request, but it hasn't started. If you are a Yandex employee, you can view the log.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@apolukhin
Copy link
Member

LGTM

@robot-magpie
Copy link

robot-magpie bot commented Nov 21, 2025

Many thanks for the PR! @apolukhin is now importing your pull request into our internal upstream repository.

@asmyasnikov
Copy link
Collaborator

@copilot давай старый метод ToExecQuerySettings превратим в свободную функцию и переделаем для создания NYdb::NQuery::TExecuteQuerySettings

Replaced TableClient::ToExecQuerySettings (which created Table Client settings)
with a free function ToExecuteQuerySettings in anonymous namespace that creates
NYdb::NQuery::TExecuteQuerySettings for Query Client API. Updated ExecuteDataQuery
to use the new function. This completes the migration from Table Client to Query
Client API.

Co-authored-by: asmyasnikov <[email protected]>
Copy link
Author

Copilot AI commented Nov 21, 2025

@copilot давай старый метод ToExecQuerySettings превратим в свободную функцию и переделаем для создания NYdb::NQuery::TExecuteQuerySett...

Done. Converted ToExecQuerySettings to a free function ToExecuteQuerySettings in anonymous namespace that creates NYdb::NQuery::TExecuteQuerySettings for Query Client. Removed the old member method. (commit 5e9a513)

Copilot finished work on behalf of asmyasnikov November 21, 2025 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Заменить Table Service на Query Service при работе с YDB транзакциями

4 participants