Repository: ClickHouse/ClickHouse
File: src/Core/YTsaurus/YTsaurusClient.cpp (C++)

Code before:


ReadBufferPtr YTsaurusClient::readTable(const String & cypress_path, const std::pair<size_t, size_t>& rows_range)
{
    YTsaurusQueryPtr read_table_query(new YTsaurusReadTableQuery(cypress_path, rows_range));
    return executeQuery(read_table_query);
}

String YTsaurusClient::startTx(size_t timeout_ms)
{
    YTsaurusQueryPtr start_tx_query(new YTsaurusStartTxQuery(timeout_ms));
    auto read_buff = executeQuery(start_tx_query);
    String res;
    // Generally the result of each YTsaurus query should be json.
    // But... for start_tx query the result always doble quoted string.
    readDoubleQuotedString(res, *read_buff);
    return res;
}

void YTsaurusClient::commitTx(const String& transaction_id)
{
    YTsaurusQueryPtr commit_tx_query(new YTsaurusCommitTxQuery(transaction_id));
    executeQuery(commit_tx_query);
}

String YTsaurusClient::lock(const String& cypress_path, const String& transaction_id)
{
    YTsaurusQueryPtr lock_query(new YTsaurusLockQuery(cypress_path, transaction_id));
    auto read_buff = executeQuery(lock_query);
    String res;
    // Generally the result of each YTsaurus query should be json.
    // But... for start_tx query the result always doble quoted string.
    readDoubleQuotedString(res, *read_buff);
    return res;
}

String YTsaurusClient::getNodeIdFromLock(const String & lock_id)
{

    String lock_metadata_path = fmt::format("{}/{}/@node_id", LOCKS_STORAGE_CYPRESS_PATH, lock_id);
    YTsaurusQueryPtr get_query(new YTsaurusGetQuery(lock_metadata_path));
    auto read_buff = executeQuery(get_query);
    String res;
    readDoubleQuotedString(res, *read_buff);
    return res;
}

YTsaurusNodeType YTsaurusClient::getNodeType(const String & cypress_path)
{
    auto json_ptr = getNodeMetadata(cypress_path);
    return getNodeTypeFromAttributes(json_ptr);

Review comment (suggestion):
```suggestion
String YTsaurusClient::lock(const String & cypress_path, const String & transaction_id)
```

Code after:

YTsaurusClient::YTsaurusClient(const YTsaurusClient & other)
    : context(other.context)
    , connection_info(other.connection_info)
    , log(getLogger("YTsaurusClient"))
{
}

ReadBufferPtr YTsaurusClient::readTable(const String & cypress_path, const std::pair<size_t, size_t> & rows_range)
{
    YTsaurusQueryPtr read_table_query(new YTsaurusReadTableQuery(cypress_path, rows_range));
    return executeQuery(read_table_query);
}

String YTsaurusClient::startTx(size_t timeout_ms)
{
    YTsaurusQueryPtr start_tx_query(new YTsaurusStartTxQuery(timeout_ms));
    auto read_buff = executeQuery(start_tx_query);
    String res;
    // Generally the result of each YTsaurus query should be json.
    // But... for start_tx query the result always double quoted string.
    readDoubleQuotedString(res, *read_buff);
    return res;
}

void YTsaurusClient::commitTx(const String & transaction_id)
{
    YTsaurusQueryPtr commit_tx_query(new YTsaurusCommitTxQuery(transaction_id));
    executeQuery(commit_tx_query);
}

String YTsaurusClient::lock(const String & cypress_path, const String & transaction_id)
{
    YTsaurusQueryPtr lock_query(new YTsaurusLockQuery(cypress_path, transaction_id));
    auto read_buff = executeQuery(lock_query);
    String res;
    // Generally the result of each YTsaurus query should be json.
    // But... for start_tx query the result always double quoted string.
    readDoubleQuotedString(res, *read_buff);
    return res;
}

String YTsaurusClient::getNodeIdFromLock(const String & lock_id)
{
    String lock_metadata_path = fmt::format("{}/{}/@node_id", LOCKS_STORAGE_CYPRESS_PATH, lock_id);
    YTsaurusQueryPtr get_query(new YTsaurusGetQuery(lock_metadata_path));
    auto read_buff = executeQuery(get_query);
    String res;
    readDoubleQuotedString(res, *read_buff);
    return res;
}