Skip to content

Commit 2511064

Browse files
committed
add external glog and gflags
1 parent c322a28 commit 2511064

File tree

8 files changed

+168
-55
lines changed

8 files changed

+168
-55
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
build
21
.vscode

CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ endif (CYGWIN)
4242
# Dependencies
4343
# ------------------------------------------------------------------------------
4444

45-
find_package(gflags REQUIRED)
46-
find_package(glog 0.6.0 REQUIRED)
47-
find_package(absl 20220623 REQUIRED)
45+
# find_package(absl 20220623 REQUIRED)
4846

4947
include(${CMAKE_SOURCE_DIR}/third-party/tabluate.cmake)
5048
include(${CMAKE_SOURCE_DIR}/third-party/rapidjson.cmake)
49+
include(${CMAKE_SOURCE_DIR}/third-party/gflags.cmake)
50+
include(${CMAKE_SOURCE_DIR}/third-party/glog.cmake)
5151

5252
find_package(Threads REQUIRED)
5353
set(THREADS_PREFER_PTHREAD_FLAG ON)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
find_package(Git REQUIRED)
2+
include(ExternalProject)
3+
4+
# Define a cmake function to add an external lib
5+
function(leanstore_add_ext_lib TARGET_NAME LIB_NAME GIT_REPO GIT_TAG)
6+
set(TARGET_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/third-party/${TARGET_NAME}-prefix)
7+
set(TARGET_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/third-party/${TARGET_NAME}-install)
8+
ExternalProject_Add(${TARGET_NAME}_internal
9+
PREFIX ${TARGET_PREFIX}
10+
GIT_REPOSITORY ${GIT_REPO}
11+
GIT_TAG ${GIT_TAG}
12+
CMAKE_ARGS
13+
-DCMAKE_INSTALL_PREFIX=${TARGET_INSTALL}
14+
-DCMAKE_PREFIX_PATH=${TARGET_INSTALL}
15+
UPDATE_COMMAND ""
16+
)
17+
18+
add_library(${TARGET_NAME} INTERFACE)
19+
add_dependencies(${TARGET_NAME} ${TARGET_NAME}_internal)
20+
target_include_directories(${TARGET_NAME} INTERFACE ${TARGET_INSTALL}/include)
21+
target_link_libraries(${TARGET_NAME} INTERFACE ${TARGET_INSTALL}/lib/${LIB_NAME})
22+
list(APPEND CMAKE_PREFIX_PATH ${TARGET_INSTALL}/lib/cmake/${TARGET_NAME})
23+
24+
message(STATUS "External lib added: ${TARGET_NAME}")
25+
message(STATUS " - Include dir: ${TARGET_INSTALL}/include")
26+
message(STATUS " - Lib path: ${TARGET_INSTALL}/lib/${LIB_NAME}")
27+
endfunction(leanstore_add_ext_lib)

source/CMakeLists.txt

+2-10
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,8 @@ file(GLOB_RECURSE LEANSTORE_SRC **.cpp **/**.cpp **.cc **/**.cc **.hpp **/**.hpp
1010

1111
add_library(leanstore STATIC ${LEANSTORE_SRC})
1212

13-
# include(${CMAKE_SOURCE_DIR}/third-party/rapidjson.cmake)
14-
# add_dependencies(leanstore rapidjson)
15-
16-
# include(${CMAKE_SOURCE_DIR}/third-party/tabluate.cmake)
17-
# add_dependencies(leanstore tabluate)
18-
1913
# dependencies
20-
target_link_libraries(leanstore gflags glog::glog profiler Threads::Threads aio tbb atomic tabluate rapidjson ${Boost_LIBRARIES} ) #tbb
14+
target_link_libraries(leanstore gflags glog profiler Threads::Threads aio tbb atomic tabluate rapidjson ${Boost_LIBRARIES} ) #tbb
2115

2216
# include dirs
2317
target_include_directories(leanstore PUBLIC ${CMAKE_SOURCE_DIR}/include/shared-headers)
@@ -30,10 +24,8 @@ set_property(TARGET leanstore APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${LE
3024

3125
# Get the include directories for the target.
3226
get_target_property(LIBA_INCLUDES leanstore INCLUDE_DIRECTORIES)
33-
34-
# Construct the compiler string for the include directories.
3527
foreach(dir ${LIBA_INCLUDES})
36-
message(status "include dir: ${dir}")
28+
message(STATUS "include dir: ${dir}")
3729
endforeach()
3830

3931

source/storage/btree/core/BTreeGeneric.hpp

+17-22
Original file line numberDiff line numberDiff line change
@@ -255,29 +255,24 @@ class BTreeGeneric : public leanstore::storage::BufferManagedTree {
255255
static rapidjson::Document ToJSONRecursive(
256256
HybridPageGuard<BTreeNode>& guardedNode) {
257257
auto bfDoc = guardedNode.mBf->ToJSON();
258-
auto& allocator = bfDoc.GetAllocator();
258+
// auto& allocator = bfDoc.GetAllocator();
259+
260+
// auto nodeDoc = guardedNode->ToJSON();
261+
// bfDoc.AddMember("BTreeNode", nodeDoc, allocator);
262+
263+
// if (guardedNode->mIsLeaf) {
264+
// return bfDoc;
265+
// }
266+
// for (auto i = 0u; i <= guardedNode->mNumSeps; ++i) {
267+
// auto childSwip = guardedNode->GetChildIncludingRightMost(i);
268+
// HybridPageGuard<BTreeNode> guardedChild(guardedNode, childSwip);
269+
// auto childDoc = ToJSONRecursive(guardedChild);
270+
// auto childName = "mChild_" + std::to_string(i);
271+
// guardedChild.unlock();
272+
// leanstore::utils::JsonValue memberName(childName.c_str(), allocator);
273+
// bfDoc.AddMember(memberName, childDoc, allocator);
274+
// }
259275

260-
auto nodeDoc = guardedNode->ToJSON();
261-
bfDoc.AddMember("page.BTreeNode", nodeDoc, allocator);
262-
// auto& allocator = nodeDoc.GetAllocator();
263-
264-
if (guardedNode->mIsLeaf) {
265-
return bfDoc;
266-
}
267-
268-
for (auto i = 0u; i <= guardedNode->mNumSeps; ++i) {
269-
auto childSwip = guardedNode->GetChildIncludingRightMost(i);
270-
HybridPageGuard<BTreeNode> guardedChild(guardedNode, childSwip);
271-
auto childDoc = ToJSONRecursive(guardedChild);
272-
auto childName = "mChild_" + std::to_string(i);
273-
guardedChild.unlock();
274-
275-
leanstore::utils::JsonValue memberName(childName.c_str(), allocator);
276-
bfDoc.AddMember(memberName, childDoc, allocator);
277-
}
278-
279-
// bfDoc.AddMember("page.BTreeNode", doc, allocator);
280-
// return bfDoc;
281276
return bfDoc;
282277
}
283278

source/storage/buffer-manager/BufferFrame.hpp

+39-19
Original file line numberDiff line numberDiff line change
@@ -223,31 +223,51 @@ static_assert(sizeof(Page) == PAGE_SIZE, "The total sizeof page");
223223
inline rapidjson::Document BufferFrame::ToJSON() {
224224
rapidjson::Document doc;
225225
doc.SetObject();
226-
auto& allocator = doc.GetAllocator();
227-
226+
// auto& allocator = doc.GetAllocator();
227+
// header.mState
228228
{
229229
auto stateStr = header.StateString();
230230
rapidjson::Value member;
231231
member.SetString(stateStr.data(), stateStr.size(), doc.GetAllocator());
232232
doc.AddMember("header.mState", member, doc.GetAllocator());
233233
}
234-
leanstore::utils::AddMemberToJson(&doc, allocator, "header.mKeepInMemory",
235-
header.mKeepInMemory);
236-
leanstore::utils::AddMemberToJson(&doc, allocator, "header.mPageId",
237-
header.mPageId);
238-
leanstore::utils::AddMemberToJson(&doc, allocator, "header.mLastWriterWorker",
239-
header.mLastWriterWorker);
240-
leanstore::utils::AddMemberToJson(&doc, allocator, "header.mFlushedPSN",
241-
header.mFlushedPSN);
242-
leanstore::utils::AddMemberToJson(&doc, allocator,
243-
"header.mIsBeingWrittenBack",
244-
header.mIsBeingWrittenBack);
245-
leanstore::utils::AddMemberToJson(&doc, allocator, "page.mPSN", page.mPSN);
246-
leanstore::utils::AddMemberToJson(&doc, allocator, "page.mGSN", page.mGSN);
247-
leanstore::utils::AddMemberToJson(&doc, allocator, "page.mBTreeId",
248-
page.mBTreeId);
249-
leanstore::utils::AddMemberToJson(&doc, allocator, "page.mMagicDebuging",
250-
page.mMagicDebuging);
234+
235+
{
236+
rapidjson::Value member;
237+
member.SetBool(header.mKeepInMemory);
238+
doc.AddMember("header.mKeepInMemory", member, doc.GetAllocator());
239+
}
240+
241+
{
242+
rapidjson::Value member;
243+
member.SetUint64(header.mPageId);
244+
doc.AddMember("header.mPageId", member, doc.GetAllocator());
245+
}
246+
247+
{
248+
rapidjson::Value member;
249+
member.SetUint64(header.mLastWriterWorker);
250+
doc.AddMember("header.mLastWriterWorker", member, doc.GetAllocator());
251+
}
252+
253+
{
254+
rapidjson::Value member;
255+
member.SetUint64(header.mFlushedPSN);
256+
doc.AddMember("header.mFlushedPSN", member, doc.GetAllocator());
257+
}
258+
259+
{
260+
rapidjson::Value member;
261+
member.SetBool(header.mIsBeingWrittenBack);
262+
doc.AddMember("header.mIsBeingWrittenBack", member, doc.GetAllocator());
263+
}
264+
265+
// leanstore::utils::AddMemberToJson(&doc, allocator, "page.mPSN", page.mPSN);
266+
// leanstore::utils::AddMemberToJson(&doc, allocator, "page.mGSN", page.mGSN);
267+
// leanstore::utils::AddMemberToJson(&doc, allocator, "page.mBTreeId",
268+
// page.mBTreeId);
269+
// leanstore::utils::AddMemberToJson(&doc, allocator, "page.mMagicDebuging",
270+
// page.mMagicDebuging);
251271

252272
return doc;
253273
}

third-party/gflags.cmake

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# set(LIB_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR})
2+
3+
include(${CMAKE_SOURCE_DIR}/cmake/Modules/LeanStoreAddExternalLib.cmake)
4+
5+
6+
# find_package(Git REQUIRED)
7+
# include(ExternalProject)
8+
9+
# # Define a cmake function to add an external lib
10+
# function(leanstore_add_ext_lib TARGET_NAME LIB_NAME GIT_REPO GIT_TAG)
11+
# set(TARGET_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/third-party/${TARGET_NAME}-prefix)
12+
# set(TARGET_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/third-party/${TARGET_NAME}-install)
13+
# ExternalProject_Add(${TARGET_NAME}_internal
14+
# PREFIX ${TARGET_PREFIX}
15+
# GIT_REPOSITORY ${GIT_REPO}
16+
# GIT_TAG ${GIT_TAG}
17+
# CMAKE_ARGS
18+
# -DCMAKE_INSTALL_PREFIX=${TARGET_INSTALL}
19+
# -DCMAKE_PREFIX_PATH=${TARGET_INSTALL}
20+
# UPDATE_COMMAND ""
21+
# )
22+
#
23+
# add_library(${TARGET_NAME} INTERFACE)
24+
# add_dependencies(${TARGET_NAME} ${TARGET_NAME}_internal)
25+
# target_include_directories(${TARGET_NAME} INTERFACE ${TARGET_INSTALL}/include)
26+
# target_link_libraries(${TARGET_NAME} INTERFACE ${TARGET_INSTALL}/lib/${LIB_NAME})
27+
# list(APPEND CMAKE_PREFIX_PATH ${TARGET_INSTALL}/lib/cmake/${TARGET_NAME})
28+
#
29+
# message(STATUS "${TARGET_NAME} added.")
30+
# message(STATUS "${TARGET_NAME} header path: ${TARGET_INSTALL}/include")
31+
# message(STATUS "${TARGET_NAME} lib path: ${TARGET_INSTALL}/lib/${LIB_NAME}")
32+
# endfunction(leanstore_add_ext_lib)
33+
34+
leanstore_add_ext_lib(gflags libgflags.a "https://github.com/gflags/gflags.git" v2.2.2)
35+
36+
# set(gflags_prefix ${CMAKE_CURRENT_BINARY_DIR}/third-party/gflags-prefix)
37+
# set(gflags_install_dir ${CMAKE_CURRENT_BINARY_DIR}/third-party/gflags-install)
38+
# ExternalProject_Add(gflags
39+
# PREFIX ${gflags_prefix}
40+
# GIT_REPOSITORY "https://github.com/gflags/gflags.git"
41+
# GIT_TAG v2.2.2
42+
# CMAKE_ARGS
43+
# -DCMAKE_INSTALL_PREFIX=${gflags_install_dir}
44+
# UPDATE_COMMAND ""
45+
# )
46+
#
47+
# add_library(gflags_ext INTERFACE)
48+
# add_dependencies(gflags_ext gflags)
49+
# set(gflags_ext_include_dir ${gflags_install_dir}/include)
50+
# set(gflags_ext_lib ${gflags_install_dir}/lib/libgflags.a)
51+
# target_include_directories(gflags_ext INTERFACE ${gflags_ext_include_dir})
52+
# target_link_libraries(gflags_ext INTERFACE ${gflags_ext_lib})
53+
#
54+
# message(STATUS "Include directories for gflags_ext: ${gflags_ext_include_dir}")
55+
# message(STATUS "Link Libraries for gflags_ext: ${gflags_ext_lib}")

third-party/glog.cmake

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
include(${CMAKE_SOURCE_DIR}/cmake/Modules/LeanStoreAddExternalLib.cmake)
2+
leanstore_add_ext_lib(glog libglog.so "https://github.com/google/glog.git" v0.6.0)
3+
4+
# set(LIB_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR})
5+
#
6+
# find_package(Git REQUIRED)
7+
# include(ExternalProject)
8+
# set(glog_install_dir ${CMAKE_CURRENT_BINARY_DIR}/third-party/glog)
9+
# ExternalProject_Add(glog_build
10+
# GIT_REPOSITORY "https://github.com/google/glog.git"
11+
# GIT_TAG v0.6.0
12+
# CMAKE_ARGS
13+
# -DCMAKE_INSTALL_PREFIX=${glog_install_dir}
14+
# UPDATE_COMMAND ""
15+
# )
16+
#
17+
# add_library(glog_ext INTERFACE)
18+
# add_dependencies(glog_ext glog_build)
19+
# set(glog_ext_include_dir ${glog_install_dir}/include)
20+
# set(glog_ext_lib ${glog_install_dir}/lib/libglog.so)
21+
# target_include_directories(glog_ext INTERFACE ${glog_ext_include_dir})
22+
# target_link_libraries(glog_ext INTERFACE ${glog_ext_lib})
23+
#
24+
# message(STATUS "Include directories for glog_ext: ${glog_ext_include_dir}")
25+
# message(STATUS "Link Libraries for glog_ext: ${glog_ext_lib}")

0 commit comments

Comments
 (0)