Skip to content

Commit da5971c

Browse files
committed
Merge remote-tracking branch 'origin/jian.z/fix-test'
2 parents 5c6b2fc + 7e691d2 commit da5971c

13 files changed

+292
-94
lines changed

CMakeLists.txt

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
cmake_minimum_required(VERSION 3.7)
2+
13
# ------------------------------------------------------------------------------
24
# Project settings
35
# ------------------------------------------------------------------------------
46

57
project(leanstoredb)
6-
cmake_minimum_required(VERSION 3.7)
78
if (NOT UNIX)
89
message(SEND_ERROR "unsupported platform")
910
endif ()
@@ -12,20 +13,21 @@ enable_language(ASM)
1213
set(CMAKE_CXX_STANDARD 20)
1314
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1415
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -rdynamic -fno-omit-frame-pointer -g3 -static-libstdc++")
15-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused -Wunreachable-code")
16+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused -Wunreachable-code")
17+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
1618
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1719

1820
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
19-
ADD_COMPILE_OPTIONS(-Wall -Wextra -mavx2 -mcx16 -m64) # -fno-elide-constructors no need for now
21+
add_compile_options(-Wall -Wextra -mavx2 -mcx16 -m64) # -fno-elide-constructors no need for now
2022
else()
21-
ADD_COMPILE_OPTIONS(-Wall -Wextra -march=native)
23+
add_compile_options(-Wall -Wextra -march=native)
2224
endif()
2325

2426
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
2527
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") # because we had weird behavior on aws ARM
2628

2729
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND CMAKE_BUILD_TYPE MATCHES Debug)
28-
ADD_COMPILE_OPTIONS(-fstandalone-debug)
30+
add_compile_options(-fstandalone-debug)
2931
endif ()
3032

3133
if (APPLE)
@@ -46,6 +48,10 @@ include(${CMAKE_SOURCE_DIR}/third-party/tabluate.cmake)
4648
include(${CMAKE_SOURCE_DIR}/third-party/rapidjson.cmake)
4749
include(${CMAKE_SOURCE_DIR}/third-party/gflags.cmake)
4850
include(${CMAKE_SOURCE_DIR}/third-party/glog.cmake)
51+
include(${CMAKE_SOURCE_DIR}/third-party/gtest.cmake)
52+
include(${CMAKE_SOURCE_DIR}/third-party/gbench.cmake)
53+
include(${CMAKE_SOURCE_DIR}/third-party/prometheus-cpp.cmake)
54+
include(${CMAKE_SOURCE_DIR}/third-party/onetbb.cmake)
4955

5056

5157
# ------------------------------------------------------------------------------

source/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ file(GLOB_RECURSE LEANSTORE_SRC **.cpp **/**.cpp **.cc **/**.cc **.hpp **/**.hpp
1111
add_library(leanstore STATIC ${LEANSTORE_SRC})
1212

1313
# dependencies
14-
target_link_libraries(leanstore aio tbb tabulate rapidjson gflags glog)
14+
target_link_libraries(leanstore aio onetbb tabulate rapidjson gflags glog)
1515

1616
# include dirs
1717
target_include_directories(leanstore PUBLIC ${CMAKE_SOURCE_DIR}/include/shared-headers)

source/LeanStore.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class LeanStore {
7777
/**
7878
* @brief Unregister a BTreeLL
7979
*
80+
* TODO(jian.z): reclaim all the buffer frames in memory and pages in disk
81+
* occupied by the tree.
82+
*
8083
* @param name The unique name of the btree
8184
*/
8285
void UnRegisterBTreeLL(const std::string& name) {
@@ -136,10 +139,22 @@ class LeanStore {
136139
/**
137140
* @brief Unregister a BTreeVI
138141
*
142+
* TODO(jian.z): reclaim all the buffer frames in memory and pages in disk
143+
* occupied by the tree.
144+
*
139145
* @param name The unique name of the btree
140146
*/
141147
void UnRegisterBTreeVI(const std::string& name) {
148+
auto btree = dynamic_cast<storage::btree::BTreeGeneric*>(
149+
storage::TreeRegistry::sInstance->GetTree(name));
150+
leanstore::storage::btree::BTreeGeneric::FreeAndReclaim(*btree);
142151
storage::TreeRegistry::sInstance->UnregisterTree(name);
152+
153+
auto graveyardName = "_" + name + "_graveyard";
154+
btree = dynamic_cast<storage::btree::BTreeGeneric*>(
155+
storage::TreeRegistry::sInstance->GetTree(graveyardName));
156+
leanstore::storage::btree::BTreeGeneric::FreeAndReclaim(*btree);
157+
storage::TreeRegistry::sInstance->UnregisterTree(graveyardName);
143158
}
144159

145160
private:

source/concurrency-recovery/ConcurrencyControl.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "CRMG.hpp"
12
#include "Worker.hpp"
23
#include "storage/buffer-manager/TreeRegistry.hpp"
34

@@ -145,7 +146,7 @@ synclwm : {
145146
if (local_all_lwm > cleaned_untill_oltp_lwm) {
146147
utils::Timer timer(CRCounters::myCounters().cc_ms_gc_history_tree);
147148
// PURGE!
148-
mHistoryTree.purgeVersions(
149+
CRManager::sInstance->mHistoryTreePtr->purgeVersions(
149150
Worker::my().mWorkerId, 0, local_all_lwm - 1,
150151
[&](const TXID tx_id, const TREEID treeId, const u8* version_payload,
151152
[[maybe_unused]] u64 version_payload_length,
@@ -167,7 +168,7 @@ synclwm : {
167168
// MOVE deletes to the graveyard
168169
const u64 fromTxId =
169170
cleaned_untill_oltp_lwm > 0 ? cleaned_untill_oltp_lwm : 0;
170-
mHistoryTree.visitRemoveVersions(
171+
CRManager::sInstance->mHistoryTreePtr->visitRemoveVersions(
171172
Worker::my().mWorkerId, fromTxId, local_oltp_lwm - 1,
172173
[&](const TXID tx_id, const TREEID treeId, const u8* version_payload,
173174
[[maybe_unused]] u64 version_payload_length,

source/storage/btree/core/BTreeGeneric.hpp

+31
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,21 @@ class BTreeGeneric : public leanstore::storage::BufferManagedTree {
244244
return findParent<false>(btree, bfToFind);
245245
}
246246

247+
/// Removes a btree from disk, reclaim all the buffer frames in memory and
248+
/// pages in disk used by it.
249+
///
250+
/// @param btree The tree to free.
251+
static void FreeAndReclaim(BTreeGeneric& btree) {
252+
HybridPageGuard<BTreeNode> guardedMetaNode(btree.mMetaNodeSwip);
253+
HybridPageGuard<BTreeNode> guardedRootNode(
254+
guardedMetaNode, guardedMetaNode->mRightMostChildSwip);
255+
BTreeGeneric::freeBTreeNodesRecursive(guardedRootNode);
256+
257+
auto exclusiveGuardedMetaNode =
258+
ExclusivePageGuard(std::move(guardedMetaNode));
259+
exclusiveGuardedMetaNode.reclaim();
260+
}
261+
247262
static rapidjson::Document ToJSON(BTreeGeneric& btree) {
248263
HybridPageGuard<BTreeNode> guardedMetaNode(btree.mMetaNodeSwip);
249264
HybridPageGuard<BTreeNode> guardedRootNode(
@@ -252,6 +267,8 @@ class BTreeGeneric : public leanstore::storage::BufferManagedTree {
252267
}
253268

254269
private:
270+
static void freeBTreeNodesRecursive(HybridPageGuard<BTreeNode>& guardedNode);
271+
255272
static rapidjson::Document ToJSONRecursive(
256273
HybridPageGuard<BTreeNode>& guardedNode) {
257274
auto bfDoc = guardedNode.mBf->ToJSON();
@@ -282,6 +299,20 @@ class BTreeGeneric : public leanstore::storage::BufferManagedTree {
282299
static constexpr std::string META_PAGE_ID = "metaPageId";
283300
};
284301

302+
inline void BTreeGeneric::freeBTreeNodesRecursive(
303+
HybridPageGuard<BTreeNode>& guardedNode) {
304+
if (!guardedNode->mIsLeaf) {
305+
for (auto i = 0u; i <= guardedNode->mNumSeps; ++i) {
306+
auto childSwip = guardedNode->GetChildIncludingRightMost(i);
307+
HybridPageGuard<BTreeNode> guardedChild(guardedNode, childSwip);
308+
freeBTreeNodesRecursive(guardedChild);
309+
}
310+
}
311+
312+
auto exclusiveGuardedNode = ExclusivePageGuard(std::move(guardedNode));
313+
exclusiveGuardedNode.reclaim();
314+
}
315+
285316
inline void BTreeGeneric::IterateChildSwips(
286317
BufferFrame& bf, std::function<bool(Swip<BufferFrame>&)> callback) {
287318
// Pre: bf is read locked

source/storage/btree/core/BTreePessimisticIterator.hpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -63,41 +63,41 @@ class BTreePessimisticIterator : public BTreePessimisticIteratorInterface {
6363
protected:
6464
// We need a custom findLeafAndLatch to track the position in parent node
6565
template <LATCH_FALLBACK_MODE mode = LATCH_FALLBACK_MODE::SHARED>
66-
void findLeafAndLatch(HybridPageGuard<BTreeNode>& childGuard, Slice key) {
66+
void findLeafAndLatch(HybridPageGuard<BTreeNode>& guardedChild, Slice key) {
6767
while (true) {
6868
mLeafPosInParent = -1;
6969
JUMPMU_TRY() {
7070
mGuardedParent = HybridPageGuard<BTreeNode>(mBTree.mMetaNodeSwip);
71-
childGuard.unlock();
71+
guardedChild.unlock();
7272

7373
// it's the root node right now.
74-
childGuard = HybridPageGuard<BTreeNode>(
74+
guardedChild = HybridPageGuard<BTreeNode>(
7575
mGuardedParent, mGuardedParent->mRightMostChildSwip);
7676

77-
for (u16 level = 0; !childGuard->mIsLeaf; level++) {
77+
for (u16 level = 0; !guardedChild->mIsLeaf; level++) {
7878
COUNTERS_BLOCK() {
7979
WorkerCounters::myCounters().dt_inner_page[mBTree.mTreeId]++;
8080
}
81-
mLeafPosInParent = mGuardedLeaf->lowerBound<false>(key);
81+
mLeafPosInParent = guardedChild->lowerBound<false>(key);
8282
auto childSwip =
83-
&childGuard->GetChildIncludingRightMost(mLeafPosInParent);
84-
mGuardedParent = std::move(childGuard);
83+
&guardedChild->GetChildIncludingRightMost(mLeafPosInParent);
84+
mGuardedParent = std::move(guardedChild);
8585
if (level == mBTree.mHeight - 1) {
86-
childGuard = HybridPageGuard(mGuardedParent, *childSwip, mode);
86+
guardedChild = HybridPageGuard(mGuardedParent, *childSwip, mode);
8787
} else {
88-
childGuard = HybridPageGuard(mGuardedParent, *childSwip);
88+
guardedChild = HybridPageGuard(mGuardedParent, *childSwip);
8989
}
9090
}
9191

9292
mGuardedParent.unlock();
9393
if (mode == LATCH_FALLBACK_MODE::EXCLUSIVE) {
94-
childGuard.toExclusive();
94+
guardedChild.toExclusive();
9595
} else {
96-
childGuard.toShared();
96+
guardedChild.toShared();
9797
}
9898
mIsPrefixCopied = false;
9999
if (mFuncEnterLeaf != nullptr) {
100-
mFuncEnterLeaf(childGuard);
100+
mFuncEnterLeaf(guardedChild);
101101
}
102102
JUMPMU_RETURN;
103103
}

source/sync-primitives/PageGuard.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ template <typename T> class ExclusivePageGuard {
270270
}
271271

272272
template <typename WT, typename... Args>
273-
// template <> void init() {
274273
cr::WALPayloadHandler<WT> ReserveWALPayload(u64 payloadSize, Args&&... args) {
275274
return mRefGuard.template ReserveWALPayload<WT>(
276275
payloadSize, std::forward<Args>(args)...);

0 commit comments

Comments
 (0)