Skip to content

Commit

Permalink
Merge branch 'main' into backtrace
Browse files Browse the repository at this point in the history
  • Loading branch information
hnwyllmm authored Nov 14, 2024
2 parents b8c0340 + d0bae1b commit 9229df6
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 37 deletions.
18 changes: 7 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
./deps/3rd
./deps/libevent
./deps/googletest
./deps/jsoncpp
./deps/benchmark
deps/3rd/*
.vscode
!.vscode/tasks.json
!.vscode/launch.json
.VSCodeCounter/*
./docs/doxy/
docs/doxy/
build/*
build_*
cmake-build-*/*
Expand All @@ -17,11 +13,11 @@ build
.idea
.ccls-cache
compile_commands.json
./.name
./miniob.iml
./vcs.xml
./workspace.xml
./modules.xml
.name
miniob.iml
vcs.xml
workspace.xml
modules.xml
GRTAGS
GPATH
GTAGS
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MESSAGE(STATUS "This is Project source dir " ${PROJECT_SOURCE_DIR})
MESSAGE(STATUS "This is PROJECT_BINARY_DIR dir " ${PROJECT_BINARY_DIR})

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

SET(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${PROJECT_SOURCE_DIR}/deps/3rd/usr/local")
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)

# 设置默认构建类型为 Debug
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ MiniOB 采用 [木兰宽松许可证,第2版](https://license.coscl.org.cn/Mul
- [OceanBase 社区交流群 33254054](https://h5.dingtalk.com/circle/healthCheckin.html?corpId=dingd88359ef5e4c49ef87cda005313eea7a&1fe0ca69-72d=16c86a07-83c&cbdbhh=qwertyuiop&origin=1)
- [OceanBase 大赛官方交流群 35326455](https://qr.dingtalk.com/action/joingroup?code=v1,k1,g61jI0RwHQA8UMocuTbys2cyM7vck2c6jNE87vdxz9o=&_dt_no_comment=1&origin=11)
- [OceanBase 官方论坛](https://ask.oceanbase.com/)
- MiniOB 开发者微信群(添加 hnwyllmm_126 为好友,备注 MiniOB,邀请入群)
- MiniOB 开发者微信群(添加 OBCE888 为好友,备注 MiniOB SIG,邀请入群)
2 changes: 1 addition & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FOREACH (F ${ALL_SRC})
get_filename_component(prjName ${F} NAME_WE)
MESSAGE("Build ${prjName} according to ${F}")
ADD_EXECUTABLE(${prjName} ${F})
TARGET_LINK_LIBRARIES(${prjName} common pthread dl benchmark)
TARGET_LINK_LIBRARIES(${prjName} common pthread dl benchmark::benchmark)
if(NOT ${prjName} STREQUAL "memtracer_performance_test")
TARGET_LINK_LIBRARIES(${prjName} observer_static)
endif()
Expand Down
17 changes: 10 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
TOPDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

BUILD_SH=$TOPDIR/build.sh
echo "THIRD_PARTY_INSTALL_PREFIX is ${THIRD_PARTY_INSTALL_PREFIX:=$TOPDIR/deps/3rd/usr/local}"

CMAKE_COMMAND="cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 --log-level=STATUS"
CMAKE_COMMAND_THIRD_PARTY="$CMAKE_COMMAND -DCMAKE_INSTALL_PREFIX=$THIRD_PARTY_INSTALL_PREFIX"
CMAKE_COMMAND_MINIOB="$CMAKE_COMMAND"

ALL_ARGS=("$@")
BUILD_ARGS=()
Expand Down Expand Up @@ -80,31 +83,31 @@ function do_init
cd ${TOPDIR}/deps/3rd/libevent && \
mkdir -p build && \
cd build && \
${CMAKE_COMMAND} .. -DEVENT__DISABLE_OPENSSL=ON -DEVENT__LIBRARY_TYPE=BOTH && \
${CMAKE_COMMAND_THIRD_PARTY} .. -DEVENT__DISABLE_OPENSSL=ON -DEVENT__LIBRARY_TYPE=BOTH && \
${MAKE_COMMAND} -j4 && \
make install

# build googletest
cd ${TOPDIR}/deps/3rd/googletest && \
mkdir -p build && \
cd build && \
${CMAKE_COMMAND} .. && \
${CMAKE_COMMAND_THIRD_PARTY} .. && \
${MAKE_COMMAND} -j4 && \
${MAKE_COMMAND} install

# build google benchmark
cd ${TOPDIR}/deps/3rd/benchmark && \
mkdir -p build && \
cd build && \
${CMAKE_COMMAND} .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBENCHMARK_ENABLE_TESTING=OFF -DBENCHMARK_INSTALL_DOCS=OFF -DBENCHMARK_ENABLE_GTEST_TESTS=OFF -DBENCHMARK_USE_BUNDLED_GTEST=OFF -DBENCHMARK_ENABLE_ASSEMBLY_TESTS=OFF && \
${CMAKE_COMMAND_THIRD_PARTY} .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBENCHMARK_ENABLE_TESTING=OFF -DBENCHMARK_INSTALL_DOCS=OFF -DBENCHMARK_ENABLE_GTEST_TESTS=OFF -DBENCHMARK_USE_BUNDLED_GTEST=OFF -DBENCHMARK_ENABLE_ASSEMBLY_TESTS=OFF && \
${MAKE_COMMAND} -j4 && \
${MAKE_COMMAND} install

# build jsoncpp
cd ${TOPDIR}/deps/3rd/jsoncpp && \
mkdir -p build && \
cd build && \
${CMAKE_COMMAND} -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF .. && \
${CMAKE_COMMAND_THIRD_PARTY} -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF .. && \
${MAKE_COMMAND} && \
${MAKE_COMMAND} install

Expand Down Expand Up @@ -137,8 +140,8 @@ function do_build
{
TYPE=$1; shift
prepare_build_dir $TYPE || return
echo "${CMAKE_COMMAND} ${TOPDIR} $@"
${CMAKE_COMMAND} -S ${TOPDIR} $@
echo "${CMAKE_COMMAND_MINIOB} ${TOPDIR} $@"
${CMAKE_COMMAND_MINIOB} -S ${TOPDIR} $@
}

function do_clean
Expand All @@ -157,7 +160,7 @@ function build {
local build_type_lower=$(echo "$1" | tr '[:upper:]' '[:lower:]') # 转换为小写
echo "Build type: $build_type_lower" # 输出构建类型

do_build "$build_type_lower" -DCMAKE_BUILD_TYPE="$build_type_lower" # 调用 do_build
do_build $@ -DCMAKE_BUILD_TYPE="$build_type_lower" # 调用 do_build
}


Expand Down
14 changes: 14 additions & 0 deletions deps/common/lang/cmath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */
#pragma once

#include <cmath>

using std::round;
4 changes: 3 additions & 1 deletion deps/common/lang/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ See the Mulan PSL v2 for more details. */

#include "common/log/log.h"
#include "common/lang/algorithm.h"
#include "common/lang/cmath.h"
#include "common/lang/iomanip.h"

namespace common {
Expand Down Expand Up @@ -270,7 +271,8 @@ char *substr(const char *s, int n1, int n2)
string double_to_str(double v)
{
char buf[256];
snprintf(buf, sizeof(buf), "%.2f", v);
double rounded_v = round(v * 100.0) / 100.0;
snprintf(buf, sizeof(buf), "%.2f", rounded_v);
size_t len = strlen(buf);
while (buf[len - 1] == '0') {
len--;
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN apt-get install -y openssh-server
# init miniob dependencies
RUN git clone https://github.com/oceanbase/miniob /tmp/miniob \
&& cd /tmp/miniob \
&& bash build.sh init \
&& THIRD_PARTY_INSTALL_PREFIX=/usr/local bash build.sh init \
&& rm -rf /tmp/miniob

RUN mkdir /var/run/sshd
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/game/miniob-output-convention.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NOTE:后台测试程序,是将预先编辑好的Case执行后,将执行结
4. 所有输出不区分大小写
5. 日期(date)输出格式使用:"YYYY-mm-DD"
6. 输出的字符串不使用单引号双引号或其它括起来
7. 浮点数输出,不要带后面多余的0,可以参考C sprintf的%g格式输出,保留两位小数。参考函数 double_to_str
7. 浮点数输出,不要带后面多余的0,四舍五入保留两位小数。参考函数 double_to_str

FAQ
- 某张表或者某个查询结果一行数据都没有,但是依然需要输出表头信息
Expand Down
10 changes: 6 additions & 4 deletions docs/docs/how_to_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ MiniOB 需要使用:
bash build.sh init
```

脚本将自动拉取依赖库(可以参考 .gitmodules) 然后编译安装到系统目录
脚本将自动拉取依赖库(可以参考 .gitmodules) 然后编译安装到miniob源码目录的 `deps/3rd/usr/local`

如果执行用户不是root,需要在命令前加上 `sudo`
如果你想将第三方依赖安装到其它目录,比如 `/usr/local` 下,可以这样做

```bash
sudo bash build.sh init
THIRD_PARTY_INSTALL_PREFIX=/usr/local bash build.sh init
```

> 如果使用 GitPod 开发,可以跳过这步,会自动执行。
> 注意:安装到系统目录可能需要一些特殊权限,可能需要使用 `sudo` 来执行命令。
> 如果使用 GitPod、GitHub Devcontainer 或 miniob docker 容器开发,可以跳过这步,会自动执行。
## 2. 编译

Expand Down
5 changes: 2 additions & 3 deletions src/observer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ ENDFOREACH (F)

SET(LIBEVENT_STATIC_LINK TRUE)
FIND_PACKAGE(Libevent CONFIG REQUIRED)
FIND_PACKAGE(jsoncpp CONFIG REQUIRED)

# JsonCpp cannot work correctly with FIND_PACKAGE

SET(LIBRARIES common pthread dl libevent::core libevent::pthreads libjsoncpp.a)
SET(LIBRARIES common pthread dl libevent::core libevent::pthreads JsonCpp::JsonCpp)

# 指定目标文件位置
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
Expand Down
9 changes: 6 additions & 3 deletions src/observer/storage/buffer/disk_buffer_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Frame *BPFrameManager::get_internal(const FrameId &frame_id)
(void)frames_.get(frame_id, frame);
if (frame != nullptr) {
frame->pin();
LOG_DEBUG("got a frame. frame=%s", frame->to_string().c_str());
}
return frame;
}
Expand All @@ -138,6 +139,7 @@ Frame *BPFrameManager::alloc(int buffer_pool_id, PageNum page_num)
frame->set_page_num(page_num);
frame->pin();
frames_.put(frame_id, frame);
LOG_DEBUG("allocate a new frame. frame=%s", frame->to_string().c_str());
}
return frame;
}
Expand Down Expand Up @@ -372,7 +374,8 @@ RC DiskBufferPool::allocate_page(Frame **frame)

hdr_frame_->set_lsn(lsn);

LOG_INFO("allocate a new page without extend buffer pool. page num=%d, buffer pool=%d", i, id());
LOG_DEBUG("allocate a new page without extend buffer pool. page num=%d, buffer pool=%d", i, id());

lock_.unlock();
return get_this_page(i, frame);
}
Expand Down Expand Up @@ -402,8 +405,8 @@ RC DiskBufferPool::allocate_page(Frame **frame)
return rc;
}

LOG_INFO("allocate new page by extending bufferpool. file=%s, pageNum=%d, pin=%d",
file_name_.c_str(), page_num, allocated_frame->pin_count());
LOG_INFO("allocate new page by extending bufferpool. buffer_pool_id=%d, pageNum=%d, pin=%d",
id(), page_num, allocated_frame->pin_count());

file_header_->allocated_pages++;
file_header_->page_count++;
Expand Down
Binary file added src/observer/storage/index/.bplus_tree.h.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion unittest/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ FOREACH (F ${ALL_SRC})
get_filename_component(prjName ${F} NAME_WE)
MESSAGE("Build ${prjName} according to ${F}")
ADD_EXECUTABLE(${prjName} ${F})
TARGET_LINK_LIBRARIES(${prjName} common pthread dl gtest gtest_main)
TARGET_LINK_LIBRARIES(${prjName} common pthread dl GTest::gtest_main)
add_test(NAME ${prjName} COMMAND ${prjName})
ENDFOREACH (F)
2 changes: 1 addition & 1 deletion unittest/memtracer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ FOREACH (F ${ALL_SRC})
get_filename_component(prjName ${F} NAME_WE)
MESSAGE("Build ${prjName} according to ${F}")
ADD_EXECUTABLE(${prjName} ${F})
TARGET_LINK_LIBRARIES(${prjName} pthread dl gtest gtest_main memtracer)
TARGET_LINK_LIBRARIES(${prjName} pthread dl GTest::gtest_main memtracer)
add_test(NAME ${prjName} COMMAND ${prjName})
ENDFOREACH (F)
2 changes: 1 addition & 1 deletion unittest/observer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ FOREACH (F ${ALL_SRC})
get_filename_component(prjName ${F} NAME_WE)
MESSAGE("Build ${prjName} according to ${F}")
ADD_EXECUTABLE(${prjName} ${F})
TARGET_LINK_LIBRARIES(${prjName} common pthread dl gtest gtest_main observer_static)
TARGET_LINK_LIBRARIES(${prjName} common pthread dl GTest::gtest_main observer_static)
add_test(NAME ${prjName} COMMAND ${prjName})
ENDFOREACH (F)

0 comments on commit 9229df6

Please sign in to comment.