diff --git a/be/CMakeLists.txt b/be/CMakeLists.txt index 0305e886ef964a8..7b24ebe10518ae5 100644 --- a/be/CMakeLists.txt +++ b/be/CMakeLists.txt @@ -729,6 +729,11 @@ if (BUILD_META_TOOL) add_subdirectory(${SRC_DIR}/tools) endif() +option(BUILD_MY_TOOL "Build my tool" ON) +if (BUILD_MY_TOOL) + add_subdirectory(${SRC_DIR}/my-tools) +endif() + option(BUILD_INDEX_TOOL "Build index tool" OFF) if (BUILD_INDEX_TOOL) add_subdirectory(${SRC_DIR}/index-tools) diff --git a/be/src/my-tools/CMakeLists.txt b/be/src/my-tools/CMakeLists.txt new file mode 100644 index 000000000000000..988327a4b335a97 --- /dev/null +++ b/be/src/my-tools/CMakeLists.txt @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# where to put generated libraries +set(LIBRARY_OUTPUT_PATH "${BUILD_DIR}/src/my-tools") + +# where to put generated binaries +set(EXECUTABLE_OUTPUT_PATH "${BUILD_DIR}/src/my-tools") + +add_executable(my_tool + my_tool.cpp +) + +# pch_reuse(my_tool) + +# This permits libraries loaded by dlopen to link to the symbols in the program. +set_target_properties(my_tool PROPERTIES ENABLE_EXPORTS 1) + +target_link_libraries(my_tool + ${DORIS_LINK_LIBS} +) + +install(DIRECTORY DESTINATION ${OUTPUT_DIR}/lib/) +install(TARGETS my_tool DESTINATION ${OUTPUT_DIR}/lib/) + +if (NOT OS_MACOSX) +# Meta tool never need debug info +add_custom_command(TARGET my_tool POST_BUILD + COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $ $.dbg + COMMAND ${CMAKE_STRIP} --strip-debug --strip-unneeded $ + COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$.dbg $ + ) +endif() diff --git a/be/src/my-tools/my_tool.cpp b/be/src/my-tools/my_tool.cpp new file mode 100644 index 000000000000000..eabb098373396b4 --- /dev/null +++ b/be/src/my-tools/my_tool.cpp @@ -0,0 +1,57 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include + +#include "common/status.h" +#include "olap/olap_meta.h" + +namespace doris { + +DEFINE_string(operation, "", "valid operation: show"); +DEFINE_string(root_path, "", "root path"); + +std::string get_usage(const std::string& progname) { + std::stringstream ss; + ss << progname << " is the Doris inverted index file tool.\n"; + ss << "Usage:\n"; + ss << "./my_tool"; + return ss.str(); +} + +int main(int argc, char** argv) { + std::string usage = get_usage(argv[0]); + gflags::SetUsageMessage(usage); + google::ParseCommandLineFlags(&argc, &argv, true); + + if (FLAGS_operation == "show") { + std::string root_path {FLAGS_root_path}; + std::cout << fmt::format("get root_path={}", root_path); + OlapMeta meta {root_path}; + std::cout << fmt::format("begin to init OlapMeta, root_path={}", root_path); + Status res = meta.init(); + if (!res.ok()) { + RETURN_NOT_OK_STATUS_WITH_WARN( + Status::IOError("open rocksdb failed, path={}", root_path), + "init OlapMeta failed"); + } + std::cout << fmt::format("successfully open RocksDB, path={}", meta.get_root_path()); + } + gflags::ShutDownCommandLineFlags(); + return 0; +} +} // namespace doris \ No newline at end of file diff --git a/be/src/tools/meta_tool.cpp b/be/src/tools/meta_tool.cpp index e4ac6493da9a5af..2b59cace9f7c8d5 100644 --- a/be/src/tools/meta_tool.cpp +++ b/be/src/tools/meta_tool.cpp @@ -61,7 +61,7 @@ using doris::segment_v2::ColumnIteratorOptions; using doris::segment_v2::PageFooterPB; using doris::io::FileReaderSPtr; -const std::string HEADER_PREFIX = "tabletmeta_"; +// const std::string HEADER_PREFIX = "tabletmeta_"; DEFINE_string(root_path, "", "storage root path"); DEFINE_string(operation, "get_meta", diff --git a/build.sh b/build.sh index d8c7786531da140..98b9a9cdbf9eabf 100755 --- a/build.sh +++ b/build.sh @@ -140,6 +140,7 @@ BUILD_FE=0 BUILD_BE=0 BUILD_BROKER=0 BUILD_META_TOOL='OFF' +BUILD_MY_TOOL='ON' BUILD_INDEX_TOOL='OFF' BUILD_SPARK_DPP=0 BUILD_BE_JAVA_EXTENSIONS=0 @@ -535,6 +536,7 @@ if [[ "${BUILD_BE}" -eq 1 ]]; then -DWITH_MYSQL="${WITH_MYSQL}" \ -DUSE_LIBCPP="${USE_LIBCPP}" \ -DBUILD_META_TOOL="${BUILD_META_TOOL}" \ + -DBUILD_MY_TOOL="${BUILD_MY_TOOL}" \ -DBUILD_INDEX_TOOL="${BUILD_INDEX_TOOL}" \ -DSTRIP_DEBUG_INFO="${STRIP_DEBUG_INFO}" \ -DUSE_DWARF="${USE_DWARF}" \