Skip to content

Commit

Permalink
maintained RpcReqError with headers in vkext (#915)
Browse files Browse the repository at this point in the history
* rename 'memcache' to 'rpc-tl' in serialization code

* fetch RpcReqError with Header as `rpcResponseHeader` with error inside `$result` field

* added ini parameter to enable rpc error with header fetching, turned off by default
  • Loading branch information
DrDet authored Oct 24, 2023
1 parent efd53e4 commit 126a015
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 67 deletions.
15 changes: 12 additions & 3 deletions common/tl/constants/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

/* Autogenerated from common.tl and left only used constants */
#pragma once

#define TL__ 0x840e0eccU
#define TL_BOOL_FALSE 0xbc799737U
#define TL_BOOL_STAT 0x92cbcbfaU
#define TL_BOOL_TRUE 0x997275b5U
#define TL_DICTIONARY 0x1f4c618fU
#define TL_DICTIONARY_FIELD 0x239c1b62U
#define TL_DOUBLE 0x2210c154U
#define TL_FLOAT 0x824dab22U
#define TL_INT 0xa8509bdaU
#define TL_INT_KEY_DICTIONARY 0x07bafc42U
#define TL_INT_KEY_DICTIONARY_FIELD 0x721ea8b9U
#define TL_LEFT 0x0a29cd5dU
#define TL_LONG 0x22076cbaU
#define TL_LONG_KEY_DICTIONARY 0xb424d8f1U
#define TL_REQ_RESULT_HEADER 0x8cc84ce1U
Expand All @@ -22,10 +25,12 @@
#define TL_RPC_DEST_ACTOR_FLAGS 0xf0a5acf7U
#define TL_RPC_DEST_FLAGS 0xe352035eU
#define TL_RPC_INVOKE_REQ 0x2374df3dU
#define TL_RPC_INVOKE_REQ_EXTRA 0xf3ef81a9U
#define TL_RPC_PING 0x5730a2dfU
#define TL_RPC_PONG 0x8430eaa7U
#define TL_RPC_REQ_ERROR 0x7ae432f5U
#define TL_RPC_REQ_RESULT 0x63aeda4eU
#define TL_RPC_REQ_RESULT_EXTRA 0xc5011709U
#define TL_STAT 0x9d56e6b2U
#define TL_STRING 0xb5286e24U
#define TL_TRUE 0x3fedd339U
Expand Down Expand Up @@ -54,7 +59,9 @@ constexpr static uint32_t int_forward = 1
constexpr static uint32_t custom_timeout_ms = 1U << 23U;
constexpr static uint32_t supported_compression_version = 1U << 25U;
constexpr static uint32_t random_delay = 1U << 26U;
constexpr static uint32_t ALL = 0x06bd00df;
constexpr static uint32_t return_view_number = 1U << 27U;
constexpr static uint32_t persistent_query = 1U << 28U;
constexpr static uint32_t ALL = 0x1ebd00df;
} // namespace rpc_invoke_req_extra_flags

namespace rpc_req_result_extra_flags {
Expand All @@ -66,7 +73,9 @@ constexpr static uint32_t response_size = 1
constexpr static uint32_t failed_subqueries = 1U << 4U;
constexpr static uint32_t compression_version = 1U << 5U;
constexpr static uint32_t stats = 1U << 6U;
constexpr static uint32_t ALL = 0x0000007f;
constexpr static uint32_t epoch_number = 1U << 27U;
constexpr static uint32_t view_number = 1U << 27U;
constexpr static uint32_t ALL = 0x0800007f;
} // namespace rpc_req_result_extra_flags

} // namespace common
Expand Down
72 changes: 72 additions & 0 deletions vkext/vkext-rpc-req-error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Compiler for PHP (aka KPHP)
// Copyright (c) 2023 LLC «V Kontakte»
// Distributed under the GPL v3 License, see LICENSE.notice.txt

#include "vkext/vkext-rpc-req-error.h"

#include "common/tl/constants/common.h"

namespace vkext_rpc {
void tl::NetPid::tl_fetch() {
ip = tl_parse_int();
port_pid = tl_parse_int();
utime = tl_parse_int();
}

void tl::RpcReqResultExtra::tl_fetch(int flags) {
if (flags & vk::tl::common::rpc_req_result_extra_flags::binlog_pos) {
binlog_pos = tl_parse_long();
}
if (flags & vk::tl::common::rpc_req_result_extra_flags::binlog_time) {
binlog_time = tl_parse_long();
}
if (flags & vk::tl::common::rpc_req_result_extra_flags::engine_pid) {
engine_pid.emplace().tl_fetch();
}
if (flags & vk::tl::common::rpc_req_result_extra_flags::request_size) {
request_size = tl_parse_int();
}
if (flags & vk::tl::common::rpc_req_result_extra_flags::response_size) {
response_size = tl_parse_int();
}
if (flags & vk::tl::common::rpc_req_result_extra_flags::failed_subqueries) {
failed_subqueries = tl_parse_int();
}
if (flags & vk::tl::common::rpc_req_result_extra_flags::compression_version) {
compression_version = tl_parse_int();
}
if (flags & vk::tl::common::rpc_req_result_extra_flags::stats) {
size_t n = tl_parse_int();
stats.emplace();
for (int i = 0; i < n; ++i) {
auto key = tl_parse_string();
auto val = tl_parse_string();
stats->emplace(std::move(key), std::move(val));
}
}
if (flags & vk::tl::common::rpc_req_result_extra_flags::epoch_number) {
epoch_number = tl_parse_long();
}
if (flags & vk::tl::common::rpc_req_result_extra_flags::view_number) {
view_number = tl_parse_long();
}
}

void tl::RpcReqError::tl_fetch() {
tl_parse_long(); // unused query_id
error_code = tl_parse_int();
error_msg = tl_parse_string();
}

void RpcError::try_fetch() {
int op = tl_parse_int();
if (op == TL_REQ_RESULT_HEADER) {
flags = tl_parse_int();
header.emplace().tl_fetch(flags);
op = tl_parse_int();
}
if (op == TL_RPC_REQ_ERROR) {
error.emplace().tl_fetch();
}
}
} // namespace vkext_rpc
54 changes: 54 additions & 0 deletions vkext/vkext-rpc-req-error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Compiler for PHP (aka KPHP)
// Copyright (c) 2023 LLC «V Kontakte»
// Distributed under the GPL v3 License, see LICENSE.notice.txt

#pragma once


#include <map>
#include <optional>
#include <string>

#include "vkext/vkext-tl-parse.h"

namespace vkext_rpc {
namespace tl {
struct NetPid {
int ip{0};
int port_pid{0};
int utime{0};

void tl_fetch();
};

struct RpcReqResultExtra {
std::optional<long long> binlog_pos;
std::optional<long long> binlog_time;
std::optional<NetPid> engine_pid;
std::optional<int> request_size;
std::optional<int> response_size;
std::optional<int> failed_subqueries;
std::optional<int> compression_version;
std::optional<std::map<std::string, std::string>> stats;
std::optional<long long> epoch_number;
std::optional<long long> view_number;

void tl_fetch(int flags);
};

struct RpcReqError {
int error_code{0};
std::string error_msg;

void tl_fetch();
};
} // namespace tl

struct RpcError {
int flags{0};
std::optional<tl::RpcReqResultExtra> header;
std::optional<tl::RpcReqError> error;

void try_fetch();
};
} // namespace vkext_rpc
Loading

0 comments on commit 126a015

Please sign in to comment.