| kcplantdb.h | | kcplantdb.h | |
| | | | |
| skipping to change at line 2118 | | skipping to change at line 2118 | |
| int64_t heir; ///< child before the first link | | int64_t heir; ///< child before the first link | |
| LinkArray links; ///< sorted array of links | | LinkArray links; ///< sorted array of links | |
| int64_t size; ///< total size of links | | int64_t size; ///< total size of links | |
| bool dirty; ///< whether to be written back | | bool dirty; ///< whether to be written back | |
| bool dead; ///< whether to be removed | | bool dead; ///< whether to be removed | |
| }; | | }; | |
| /** | | /** | |
| * Slot cache of leaf nodes. | | * Slot cache of leaf nodes. | |
| */ | | */ | |
| struct LeafSlot { | | struct LeafSlot { | |
|
| SpinLock lock; ///< lock | | Mutex lock; ///< lock | |
| LeafCache* hot; ///< hot cache | | LeafCache* hot; ///< hot cache | |
| LeafCache* warm; ///< warm cache | | LeafCache* warm; ///< warm cache | |
| }; | | }; | |
| /** | | /** | |
| * Slot cache of inner nodes. | | * Slot cache of inner nodes. | |
| */ | | */ | |
| struct InnerSlot { | | struct InnerSlot { | |
| SpinLock lock; ///< lock | | SpinLock lock; ///< lock | |
| InnerCache* warm; ///< warm cache | | InnerCache* warm; ///< warm cache | |
| }; | | }; | |
| | | | |
| skipping to change at line 2206 | | skipping to change at line 2206 | |
| } | | } | |
| /** | | /** | |
| * Clean all of the leaf cache. | | * Clean all of the leaf cache. | |
| * @return true on success, or false on failure. | | * @return true on success, or false on failure. | |
| */ | | */ | |
| bool clean_leaf_cache() { | | bool clean_leaf_cache() { | |
| _assert_(true); | | _assert_(true); | |
| bool err = false; | | bool err = false; | |
| for (int32_t i = 0; i < PLDBSLOTNUM; i++) { | | for (int32_t i = 0; i < PLDBSLOTNUM; i++) { | |
| LeafSlot* slot = lslots_ + i; | | LeafSlot* slot = lslots_ + i; | |
|
| ScopedSpinLock lock(&slot->lock); | | ScopedMutex lock(&slot->lock); | |
| typename LeafCache::Iterator it = slot->warm->begin(); | | typename LeafCache::Iterator it = slot->warm->begin(); | |
| typename LeafCache::Iterator itend = slot->warm->end(); | | typename LeafCache::Iterator itend = slot->warm->end(); | |
| while (it != itend) { | | while (it != itend) { | |
| LeafNode* node = it.value(); | | LeafNode* node = it.value(); | |
| if (!save_leaf_node(node)) err = true; | | if (!save_leaf_node(node)) err = true; | |
| it++; | | it++; | |
| } | | } | |
| it = slot->hot->begin(); | | it = slot->hot->begin(); | |
| itend = slot->hot->end(); | | itend = slot->hot->end(); | |
| while (it != itend) { | | while (it != itend) { | |
| | | | |
| skipping to change at line 2232 | | skipping to change at line 2232 | |
| return !err; | | return !err; | |
| } | | } | |
| /** | | /** | |
| * Clean a part of the leaf cache. | | * Clean a part of the leaf cache. | |
| * @param slot a slot of leaf nodes. | | * @param slot a slot of leaf nodes. | |
| * @return true on success, or false on failure. | | * @return true on success, or false on failure. | |
| */ | | */ | |
| bool clean_leaf_cache_part(LeafSlot* slot) { | | bool clean_leaf_cache_part(LeafSlot* slot) { | |
| _assert_(slot); | | _assert_(slot); | |
| bool err = false; | | bool err = false; | |
|
| ScopedSpinLock lock(&slot->lock); | | ScopedMutex lock(&slot->lock); | |
| if (slot->warm->count() > 0) { | | if (slot->warm->count() > 0) { | |
| LeafNode* node = slot->warm->first_value(); | | LeafNode* node = slot->warm->first_value(); | |
| if (!save_leaf_node(node)) err = true; | | if (!save_leaf_node(node)) err = true; | |
| } else if (slot->hot->count() > 0) { | | } else if (slot->hot->count() > 0) { | |
| LeafNode* node = slot->hot->first_value(); | | LeafNode* node = slot->hot->first_value(); | |
| if (!save_leaf_node(node)) err = true; | | if (!save_leaf_node(node)) err = true; | |
| } | | } | |
| return !err; | | return !err; | |
| } | | } | |
| /** | | /** | |
| | | | |
| skipping to change at line 2341 | | skipping to change at line 2341 | |
| /** | | /** | |
| * Load a leaf node. | | * Load a leaf node. | |
| * @param id the ID number of the leaf node. | | * @param id the ID number of the leaf node. | |
| * @param prom whether to promote the warm cache. | | * @param prom whether to promote the warm cache. | |
| * @return the loaded leaf node. | | * @return the loaded leaf node. | |
| */ | | */ | |
| LeafNode* load_leaf_node(int64_t id, bool prom) { | | LeafNode* load_leaf_node(int64_t id, bool prom) { | |
| _assert_(id > 0); | | _assert_(id > 0); | |
| int32_t sidx = id % PLDBSLOTNUM; | | int32_t sidx = id % PLDBSLOTNUM; | |
| LeafSlot* slot = lslots_ + sidx; | | LeafSlot* slot = lslots_ + sidx; | |
|
| ScopedSpinLock lock(&slot->lock); | | ScopedMutex lock(&slot->lock); | |
| LeafNode** np = slot->hot->get(id, LeafCache::MLAST); | | LeafNode** np = slot->hot->get(id, LeafCache::MLAST); | |
| if (np) return *np; | | if (np) return *np; | |
| if (prom) { | | if (prom) { | |
| if (slot->hot->count() * PLDBWARMRATIO > slot->warm->count() + PLDBWA
RMRATIO) { | | if (slot->hot->count() * PLDBWARMRATIO > slot->warm->count() + PLDBWA
RMRATIO) { | |
| slot->hot->first_value()->hot = false; | | slot->hot->first_value()->hot = false; | |
| slot->hot->migrate(slot->hot->first_key(), slot->warm, LeafCache::M
LAST); | | slot->hot->migrate(slot->hot->first_key(), slot->warm, LeafCache::M
LAST); | |
| } | | } | |
| np = slot->warm->migrate(id, slot->hot, LeafCache::MLAST); | | np = slot->warm->migrate(id, slot->hot, LeafCache::MLAST); | |
| if (np) { | | if (np) { | |
| (*np)->hot = true; | | (*np)->hot = true; | |
| | | | |
End of changes. 4 change blocks. |
| 4 lines changed or deleted | | 4 lines changed or added | |
|