diff --git a/storage/rocksdb/CMakeLists.txt b/storage/rocksdb/CMakeLists.txt index cf12b93a06c..37df44541a1 100644 --- a/storage/rocksdb/CMakeLists.txt +++ b/storage/rocksdb/CMakeLists.txt @@ -162,6 +162,7 @@ INCLUDE_DIRECTORIES( SET(ROCKSDB_SOURCES ${ROCKSDB_SOURCES} + show_git_info.cc ha_rocksdb.cc rdb_datadic.cc rdb_iterator.cc diff --git a/storage/rocksdb/mytopling.json b/storage/rocksdb/mytopling.json index 934d8f046b3..96d4fbfa86f 100644 --- a/storage/rocksdb/mytopling.json +++ b/storage/rocksdb/mytopling.json @@ -13,6 +13,7 @@ "//end": "end" }, "AnyPlugin": { + "git_info": "GitInfoShower", "sys_cf_key_coder": "HtmlTextUserKeyCoder", "html_text_key_coder": "HtmlTextUserKeyCoder" }, diff --git a/storage/rocksdb/show_git_info.cc b/storage/rocksdb/show_git_info.cc new file mode 100644 index 00000000000..32a40b569c1 --- /dev/null +++ b/storage/rocksdb/show_git_info.cc @@ -0,0 +1,72 @@ +#include +#include +#include +#include "sql/mysql_githash.h" + +const char* git_version_hash_info_cspp_memtable(); +const char* git_version_hash_info_cspp_wbwi(); + +namespace rocksdb { + +void JS_TopTable_AddVersion(json& djs, bool html); +__attribute__((weak)) void JS_ZipTable_AddVersion(json& djs, bool html); + +class GitInfoShower : public AnyPlugin { +public: + const char* Name() const final { return "GitInfoShower"; } + void Update(const json&, const json&, const SidePluginRepo &) {} + std::string ToString(const json& dump_options, const SidePluginRepo&) const { + json js, jtop, jzip; + bool html = JsonSmartBool(dump_options, "html", true); + + if (JS_ZipTable_AddVersion) { + JS_ZipTable_AddVersion(jzip, html); + } + JS_TopTable_AddVersion(jtop, html); + + std::string mysql_git_hash(MYSQL_GIT_HASH); + js["mytopling"]["git_sha"] = html ? + "" + + mysql_git_hash + "" + : mysql_git_hash; + js["mytopling"]["git_date"] = MYSQL_GIT_DATE; + + js["toplingdb"] = jtop["version"]["rocksdb"]; + + constexpr uint SHA_BEGIN_POS = 33; + std::string git_cspp_mem = + std::string(git_version_hash_info_cspp_memtable()).substr(SHA_BEGIN_POS); + std::string git_cspp_wbwi = + std::string(git_version_hash_info_cspp_wbwi()).substr(SHA_BEGIN_POS); + if (html) { + js["cspp-memtable"] = insert_html_link_and_symbol( + git_cspp_mem, "https://github.com/topling/cspp-memtable/commit/"); + js["cspp-wbwi"] = insert_html_link_and_symbol( + git_cspp_wbwi, "https://github.com/topling/cspp-wbwi/commit/"); + } else { + js["cspp-memtable"] = git_cspp_mem; + js["cspp-wbwi"] = git_cspp_wbwi; + } + js.merge_patch(jzip["version"]); + js["topling-sst"] = jtop["version"]["topling-sst"]; + js["topling-zip"] = jtop["version"]["topling-zip"]; + + return JsonToString(js, dump_options); + } + +private: + std::string& insert_html_link_and_symbol( + std::string& str, const std::string link) const { + constexpr uint GIT_SHA_LEN = 40; + str.append(""); + str.insert(GIT_SHA_LEN, ""); + str.insert(0, "
");
+        return str;
+    }
+};
+
+ROCKSDB_REG_DEFAULT_CONS(GitInfoShower, AnyPlugin);
+ROCKSDB_REG_AnyPluginManip("GitInfoShower");
+
+} // namespace rocksdb
\ No newline at end of file