Skip to content

Commit

Permalink
read server_info from proxy through ffi(with test)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinNeo committed Aug 20, 2021
1 parent 1e071f0 commit dd057cc
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
25 changes: 23 additions & 2 deletions dbms/src/Flash/DiagnosticsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <Flash/LogSearch.h>
#include <Poco/Path.h>
#include <Storages/PathPool.h>
#include <Storages/Transaction/KVStore.h>
#include <Storages/Transaction/ProxyFFI.h>
#include <Storages/Transaction/TMTContext.h>
#include <fmt/core.h>
#include <re2/re2.h>

Expand Down Expand Up @@ -363,7 +366,7 @@ struct CPUArchHelper
const std::string & get() const { return arch_; }

protected:
std::string execOrElse(const char * cmd [[ maybe_unused ]], const char * otherwise)
std::string execOrElse(const char * cmd [[maybe_unused]], const char * otherwise)
{
#if defined(__unix__)
std::array<char, 128> buffer;
Expand Down Expand Up @@ -942,6 +945,19 @@ try
{
(void)context;

#if true
//defined(__APPLE__)
const TiFlashRaftProxyHelper * helper = server.context().getTMTContext().getKVStore()->getProxyHelper();
if (helper)
{
std::string req = request->SerializeAsString();
helper->fn_server_info(helper->proxy_ptr, strIntoView(req), response);
}
else
{
LOG_ERROR(log, "TiFlashRaftProxyHelper is nullptr");
}
#else
auto tp = request->tp();
std::vector<ServerInfoItem> items;

Expand Down Expand Up @@ -1006,14 +1022,19 @@ try
added_pair->set_value(pair.value());
}
}

#endif
return ::grpc::Status::OK;
}
catch (const Exception & e)
{
LOG_ERROR(log, e.displayText());
return grpc::Status(grpc::StatusCode::INTERNAL, "internal error");
}
catch (const std::exception & e)
{
LOG_ERROR(log, e.what());
return grpc::Status(grpc::StatusCode::INTERNAL, "internal error");
}

::grpc::Status DiagnosticsService::search_log(::grpc::ServerContext * grpc_context, const ::diagnosticspb::SearchLogRequest * request,
::grpc::ServerWriter<::diagnosticspb::SearchLogResponse> * stream)
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <Common/getMultipleKeysFromConfig.h>
#include <Common/getNumberOfPhysicalCPUCores.h>
#include <Common/setThreadName.h>
#include <common/simd.h>
#include <Encryption/DataKeyManager.h>
#include <Encryption/FileProvider.h>
#include <Encryption/MockKeyManager.h>
Expand Down Expand Up @@ -874,6 +873,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
.fn_gc_raw_cpp_ptr = GcRawCppPtr,
.fn_gen_batch_read_index_res = GenBatchReadIndexRes,
.fn_insert_batch_read_index_resp = InsertBatchReadIndexResp,
.fn_set_server_info_resp = SetSetverInfoResp,
};

RaftStoreProxyRunner proxy_runner(RaftStoreProxyRunner::RunRaftStoreProxyParms{&helper, proxy_conf}, log);
Expand Down
7 changes: 7 additions & 0 deletions dbms/src/Storages/Transaction/ProxyFFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <Storages/Transaction/ProxyFFI.h>
#include <Storages/Transaction/Region.h>
#include <Storages/Transaction/TMTContext.h>
#include <diagnosticspb.pb.h>

namespace CurrentMetrics
{
Expand Down Expand Up @@ -370,4 +371,10 @@ void InsertBatchReadIndexResp(RawVoidPtr resp, BaseBuffView view, uint64_t regio

RawCppPtr GenRawCppPtr(RawVoidPtr ptr_, RawCppPtrTypeImpl type_) { return RawCppPtr{ptr_, static_cast<RawCppPtrType>(type_)}; }

void SetSetverInfoResp(BaseBuffView view, RawVoidPtr ptr)
{
using diagnosticspb::ServerInfoResponse;
reinterpret_cast<ServerInfoResponse *>(ptr)->ParseFromArray(view.data, view.len);
}

} // namespace DB
2 changes: 2 additions & 0 deletions dbms/src/Storages/Transaction/ProxyFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@ uint8_t CheckHttpUriAvailable(BaseBuffView);
void GcRawCppPtr(EngineStoreServerWrap *, void * ptr, RawCppPtrType type);
RawVoidPtr GenBatchReadIndexRes(uint64_t cap);
void InsertBatchReadIndexResp(RawVoidPtr, BaseBuffView, uint64_t);
void SetSetverInfoResp(BaseBuffView, RawVoidPtr);
BaseBuffView strIntoView(const std::string & view);
}
} // namespace DB
34 changes: 34 additions & 0 deletions tests/fullstack-test2/diagnostics/check_diagnostics.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
mysql> select distinct(NAME) from INFORMATION_SCHEMA.CLUSTER_HARDWARE where TYPE='tiflash' order by NAME;
+--------------------+
| NAME |
+--------------------+
| capacity |
| cpu-arch |
| cpu-frequency |
| cpu-logical-cores |
| cpu-physical-cores |
| cpu-vendor-id |
| flag |
| free |
| free-percent |
| fstype |
| index |
| ip |
| is-broadcast |
| is-loopback |
| is-multicast |
| is-point-to-point |
| is-up |
| l1-cache-line-size |
| l1-cache-size |
| l2-cache-line-size |
| l2-cache-size |
| l3-cache-line-size |
| l3-cache-size |
| mac |
| path |
| total |
| type |
| used |
| used-percent |
+--------------------+

0 comments on commit dd057cc

Please sign in to comment.