diff options
author | hiddenpath <[email protected]> | 2024-12-18 17:25:58 +0300 |
---|---|---|
committer | hiddenpath <[email protected]> | 2024-12-18 17:44:47 +0300 |
commit | 492fb432bf89c4b16548b9cc215d0cb4e39c7b83 (patch) | |
tree | 7da4b45be23fcceeb5ea7ddc2cd962dd74a6c42c /yt/cpp/mapreduce/raw_client/raw_requests.cpp | |
parent | da0030f3cb73ddbbfc27f8dc404ba382b32bd60d (diff) |
[yt/cpp/mapreduce] YT-23616: Move Transaction, Misc, Table methods to THttpRawClient
commit_hash:a08daac218b8d8bbd805220429b62f2284ad094f
Diffstat (limited to 'yt/cpp/mapreduce/raw_client/raw_requests.cpp')
-rw-r--r-- | yt/cpp/mapreduce/raw_client/raw_requests.cpp | 251 |
1 files changed, 29 insertions, 222 deletions
diff --git a/yt/cpp/mapreduce/raw_client/raw_requests.cpp b/yt/cpp/mapreduce/raw_client/raw_requests.cpp index 31f09339756..a3f10e6c414 100644 --- a/yt/cpp/mapreduce/raw_client/raw_requests.cpp +++ b/yt/cpp/mapreduce/raw_client/raw_requests.cpp @@ -269,34 +269,36 @@ TJobAttributes ParseJobAttributes(const TNode& node) return result; } -TMaybe<TYPath> GetFileFromCache( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TTransactionId& transactionId, - const TString& md5Signature, - const TYPath& cachePath, - const TGetFileFromCacheOptions& options) +TCheckPermissionResponse ParseCheckPermissionResponse(const TNode& node) { - THttpHeader header("GET", "get_file_from_cache"); - header.MergeParameters(SerializeParamsForGetFileFromCache(transactionId, md5Signature, cachePath, options)); - auto responseInfo = RetryRequestWithPolicy(retryPolicy, context, header); - auto path = NodeFromYsonString(responseInfo.Response).AsString(); - return path.empty() ? Nothing() : TMaybe<TYPath>(path); -} + auto parseSingleResult = [] (const TNode::TMapType& node) { + TCheckPermissionResult result; + result.Action = ::FromString<ESecurityAction>(node.at("action").AsString()); + if (auto objectId = node.FindPtr("object_id")) { + result.ObjectId = GetGuid(objectId->AsString()); + } + if (auto objectName = node.FindPtr("object_name")) { + result.ObjectName = objectName->AsString(); + } + if (auto subjectId = node.FindPtr("subject_id")) { + result.SubjectId = GetGuid(subjectId->AsString()); + } + if (auto subjectName = node.FindPtr("subject_name")) { + result.SubjectName = subjectName->AsString(); + } + return result; + }; -TYPath PutFileToCache( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TTransactionId& transactionId, - const TYPath& filePath, - const TString& md5Signature, - const TYPath& cachePath, - const TPutFileToCacheOptions& options) -{ - THttpHeader header("POST", "put_file_to_cache"); - header.MergeParameters(SerializeParamsForPutFileToCache(transactionId, context.Config->Prefix, filePath, md5Signature, cachePath, options)); - auto result = RetryRequestWithPolicy(retryPolicy, context, header); - return NodeFromYsonString(result.Response).AsString(); + const auto& mapNode = node.AsMap(); + TCheckPermissionResponse result; + static_cast<TCheckPermissionResult&>(result) = parseSingleResult(mapNode); + if (auto columns = mapNode.FindPtr("columns")) { + result.Columns.reserve(columns->AsList().size()); + for (const auto& columnNode : columns->AsList()) { + result.Columns.push_back(parseSingleResult(columnNode.AsMap())); + } + } + return result; } TNode::TListType SkyShareTable( @@ -320,7 +322,7 @@ TNode::TListType SkyShareTable( patchedOptions.Pool(context.Config->Pool); } - header.MergeParameters(SerializeParamsForSkyShareTable(proxyName, context.Config->Prefix, tablePaths, patchedOptions)); + header.MergeParameters(NRawClient::SerializeParamsForSkyShareTable(proxyName, context.Config->Prefix, tablePaths, patchedOptions)); TClientContext skyApiHost({ .ServerName = host, .HttpClient = NHttpClient::CreateDefaultHttpClient() }); TResponseInfo response = {}; @@ -343,103 +345,6 @@ TNode::TListType SkyShareTable( } } -TCheckPermissionResponse ParseCheckPermissionResponse(const TNode& node) -{ - auto parseSingleResult = [] (const TNode::TMapType& node) { - TCheckPermissionResult result; - result.Action = ::FromString<ESecurityAction>(node.at("action").AsString()); - if (auto objectId = node.FindPtr("object_id")) { - result.ObjectId = GetGuid(objectId->AsString()); - } - if (auto objectName = node.FindPtr("object_name")) { - result.ObjectName = objectName->AsString(); - } - if (auto subjectId = node.FindPtr("subject_id")) { - result.SubjectId = GetGuid(subjectId->AsString()); - } - if (auto subjectName = node.FindPtr("subject_name")) { - result.SubjectName = subjectName->AsString(); - } - return result; - }; - - const auto& mapNode = node.AsMap(); - TCheckPermissionResponse result; - static_cast<TCheckPermissionResult&>(result) = parseSingleResult(mapNode); - if (auto columns = mapNode.FindPtr("columns")) { - result.Columns.reserve(columns->AsList().size()); - for (const auto& columnNode : columns->AsList()) { - result.Columns.push_back(parseSingleResult(columnNode.AsMap())); - } - } - return result; -} - -TCheckPermissionResponse CheckPermission( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TString& user, - EPermission permission, - const TYPath& path, - const TCheckPermissionOptions& options) -{ - THttpHeader header("GET", "check_permission"); - header.MergeParameters(SerializeParamsForCheckPermission(user, permission, context.Config->Prefix, path, options)); - auto response = RetryRequestWithPolicy(retryPolicy, context, header); - return ParseCheckPermissionResponse(NodeFromYsonString(response.Response)); -} - -TVector<TTabletInfo> GetTabletInfos( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TYPath& path, - const TVector<int>& tabletIndexes, - const TGetTabletInfosOptions& options) -{ - THttpHeader header("POST", "api/v4/get_tablet_infos", false); - header.MergeParameters(SerializeParamsForGetTabletInfos(context.Config->Prefix, path, tabletIndexes, options)); - auto response = RetryRequestWithPolicy(retryPolicy, context, header); - TVector<TTabletInfo> result; - Deserialize(result, *NodeFromYsonString(response.Response).AsMap().FindPtr("tablets")); - return result; -} - -TVector<TTableColumnarStatistics> GetTableColumnarStatistics( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TTransactionId& transactionId, - const TVector<TRichYPath>& paths, - const TGetTableColumnarStatisticsOptions& options) -{ - THttpHeader header("GET", "get_table_columnar_statistics"); - header.MergeParameters(SerializeParamsForGetTableColumnarStatistics(transactionId, paths, options)); - TRequestConfig config; - config.IsHeavy = true; - auto requestResult = RetryRequestWithPolicy(retryPolicy, context, header, {}, config); - auto response = NodeFromYsonString(requestResult.Response); - TVector<TTableColumnarStatistics> result; - Deserialize(result, response); - return result; -} - -TMultiTablePartitions GetTablePartitions( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TTransactionId& transactionId, - const TVector<TRichYPath>& paths, - const TGetTablePartitionsOptions& options) -{ - THttpHeader header("GET", "partition_tables"); - header.MergeParameters(SerializeParamsForGetTablePartitions(transactionId, paths, options)); - TRequestConfig config; - config.IsHeavy = true; - auto requestResult = RetryRequestWithPolicy(retryPolicy, context, header, {}, config); - auto response = NodeFromYsonString(requestResult.Response); - TMultiTablePartitions result; - Deserialize(result, response); - return result; -} - TRichYPath CanonizeYPath( const IRequestRetryPolicyPtr& retryPolicy, const TClientContext& context, @@ -468,104 +373,6 @@ TVector<TRichYPath> CanonizeYPaths( return result; } -void AlterTable( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TTransactionId& transactionId, - const TYPath& path, - const TAlterTableOptions& options) -{ - THttpHeader header("POST", "alter_table"); - header.AddMutationId(); - header.MergeParameters(SerializeParamsForAlterTable(transactionId, context.Config->Prefix, path, options)); - RetryRequestWithPolicy(retryPolicy, context, header); -} - -void AlterTableReplica( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TReplicaId& replicaId, - const TAlterTableReplicaOptions& options) -{ - THttpHeader header("POST", "alter_table_replica"); - header.AddMutationId(); - header.MergeParameters(NRawClient::SerializeParamsForAlterTableReplica(replicaId, options)); - RetryRequestWithPolicy(retryPolicy, context, header); -} - -void DeleteRows( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TYPath& path, - const TNode::TListType& keys, - const TDeleteRowsOptions& options) -{ - THttpHeader header("PUT", "delete_rows"); - header.SetInputFormat(TFormat::YsonBinary()); - header.MergeParameters(NRawClient::SerializeParametersForDeleteRows(context.Config->Prefix, path, options)); - - auto body = NodeListToYsonString(keys); - TRequestConfig requestConfig; - requestConfig.IsHeavy = true; - RetryRequestWithPolicy(retryPolicy, context, header, body, requestConfig); -} - -void FreezeTable( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TYPath& path, - const TFreezeTableOptions& options) -{ - THttpHeader header("POST", "freeze_table"); - header.MergeParameters(SerializeParamsForFreezeTable(context.Config->Prefix, path, options)); - RetryRequestWithPolicy(retryPolicy, context, header); -} - -void UnfreezeTable( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TYPath& path, - const TUnfreezeTableOptions& options) -{ - THttpHeader header("POST", "unfreeze_table"); - header.MergeParameters(SerializeParamsForUnfreezeTable(context.Config->Prefix, path, options)); - RetryRequestWithPolicy(retryPolicy, context, header); -} - -void AbortTransaction( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TTransactionId& transactionId) -{ - THttpHeader header("POST", "abort_tx"); - header.AddMutationId(); - header.MergeParameters(NRawClient::SerializeParamsForAbortTransaction(transactionId)); - RetryRequestWithPolicy(retryPolicy, context, header); -} - -void CommitTransaction( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TTransactionId& transactionId) -{ - THttpHeader header("POST", "commit_tx"); - header.AddMutationId(); - header.MergeParameters(NRawClient::SerializeParamsForCommitTransaction(transactionId)); - RetryRequestWithPolicy(retryPolicy, context, header); -} - -TTransactionId StartTransaction( - const IRequestRetryPolicyPtr& retryPolicy, - const TClientContext& context, - const TTransactionId& parentTransactionId, - const TStartTransactionOptions& options) -{ - THttpHeader header("POST", "start_tx"); - header.AddMutationId(); - header.MergeParameters(NRawClient::SerializeParamsForStartTransaction(parentTransactionId, context.Config->TxTimeout, options)); - return ParseGuidFromResponse(RetryRequestWithPolicy(retryPolicy, context, header).Response); -} - //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NDetail::NRawClient |