Skip to content

Commit 98fcc5a

Browse files
committed
change data structure from HASHTABLE to std:map and std::unordered_map
1 parent f45ce48 commit 98fcc5a

File tree

4 files changed

+259
-688
lines changed

4 files changed

+259
-688
lines changed

build_mysql.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,10 @@ BUILD_NAME="-DUNIV_PMEMOBJ_PERSIST -DUNIV_PMEMOBJ_PPL_STAT -DUNIV_PMEMOBJ_PAGE_L
161161

162162
echo "BUILD MODE: $BUILD_NAME with debug=$IS_DEBUG"
163163
cd $MYSQL_HOME/bld
164-
cmake .. -DWITH_DEBUG=$IS_DEBUG -DCMAKE_C_FLAGS="$BUILD_NAME -DUNIV_AIO_IMPROVE" -DCMAKE_CXX_FLAGS="$BUILD_NAME -DUNIV_AIO_IMPROVE" -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/root/boost
164+
# For Original build
165+
#cmake .. -DWITH_DEBUG=$IS_DEBUG -DCMAKE_C_FLAGS="$BUILD_NAME -DUNIV_AIO_IMPROVE" -DCMAKE_CXX_FLAGS="-std=c++14 $BUILD_NAME -DUNIV_AIO_IMPROVE" -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/root/boost
166+
#make install -j48
167+
168+
# For C++14 build. Enable "auto" keyword and std::map, std::unordered_map
169+
cmake .. -DWITH_DEBUG=$IS_DEBUG -DCMAKE_C_FLAGS="$BUILD_NAME -DUNIV_AIO_IMPROVE" -DCMAKE_CXX_FLAGS="-std=c++14 $BUILD_NAME -DUNIV_AIO_IMPROVE" -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/root/boost
165170
make install -j48

storage/innobase/include/my_pmemobj.h

+49-24
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <wchar.h>
2222
#include <unistd.h> //for access()
2323

24+
#include <unordered_map>
25+
2426
#include "univ.i"
2527
#include "ut0byte.h"
2628
#include "ut0rbt.h"
@@ -218,6 +220,12 @@ typedef struct __pmem_recv_line PMEM_RECV_LINE;
218220
struct __pmem_space_t;
219221
typedef struct __pmem_space_t PMEM_SPACE;
220222

223+
//typedef std::map<uint64_t, PMEM_PAGE_LOG_BLOCK*, std::less<uint64_t>, ut_allocator<std::pair<uint64_t, PMEM_PAGE_LOG_BLOCK*>>> OFFSET_MAP;
224+
//typedef std::map<uint64_t, PMEM_PAGE_LOG_BLOCK*> OFFSET_MAP;
225+
226+
//typedef std::unordered_map<uint64_t, PMEM_PAGE_LOG_BLOCK*, std::hash<uint64_t>, std::equal_to<uint64_t>> KEY_MAP;
227+
//typedef std::unordered_map<uint64_t, PMEM_PAGE_LOG_BLOCK*> KEY_MAP;
228+
221229
// End Per-Page Logging
222230

223231
//////////////////////////////////////////////////
@@ -578,6 +586,14 @@ struct plog_hash_t {
578586
hash_node_t addr_hash;/*!< hash node in the hash bucket chain */
579587
};
580588

589+
using OFFSET_MAP =
590+
std::map<uint64_t, PMEM_PAGE_LOG_BLOCK*, std::less<uint64_t>,
591+
ut_allocator<std::pair<uint64_t, PMEM_PAGE_LOG_BLOCK*>>>;
592+
//
593+
using KEY_MAP =
594+
std::unordered_map<uint64_t, PMEM_PAGE_LOG_BLOCK*, std::hash<uint64_t>, std::equal_to<uint64_t>,
595+
ut_allocator<std::pair<uint64_t, PMEM_PAGE_LOG_BLOCK*>>>;
596+
581597
/*
582598
* A hashed line has array of log blocks share the same hashed value and log buffer
583599
* */
@@ -597,7 +613,7 @@ struct __pmem_page_log_hashed_line {
597613
uint64_t write_diskaddr; //diskaddr that log recs are durable write write_diskaddr < diskaddr
598614

599615
/*for checkpoint*/
600-
uint32_t oldest_block_off;//offset of the block has min (start_diskaddr + start_off)
616+
uint32_t oldest_block_id;//offset of the oldest block(start_diskaddr + start_off)
601617
uint64_t ckpt_lsn;
602618
bool is_req_checkpoint;
603619

@@ -615,10 +631,17 @@ struct __pmem_page_log_hashed_line {
615631
long long* bit_arr; //bit array to manage free slots
616632
uint16_t n_bit_blocks; //number of block in bit_arr
617633

618-
/*Hash table*/
619-
hash_table_t* addr_hash; //hash the log block in this line
620-
621-
std::map<uint64_t, uint32_t>* offset_map;
634+
/* DRAM data structures: (1) hashtables and (2) recovery objects.
635+
* */
636+
KEY_MAP* key_map; //hash the log block in this line
637+
//std::unordered_map<uint64_t, PMEM_PAGE_LOG_BLOCK*>* key_map;
638+
//std::map<uint64_t, PMEM_PAGE_LOG_BLOCK*>* key_map;
639+
640+
OFFSET_MAP* offset_map;
641+
//std::map<uint64_t, PMEM_PAGE_LOG_BLOCK*> * offset_map;
642+
///*Hash table*/
643+
//hash_table_t* addr_hash; //hash the log block in this line
644+
//std::map<uint64_t, uint32_t>* offset_map;
622645

623646
/*PART 3: recovery*/
624647
//Alternative to recv_sys_t in InnoDB, allocate in DRAM when recovery
@@ -1151,7 +1174,8 @@ pm_page_part_log_hash_free(
11511174
PMEMobjpool* pop,
11521175
PMEM_PAGE_PART_LOG* ppl);
11531176

1154-
plog_hash_t*
1177+
//plog_hash_t*
1178+
PMEM_PAGE_LOG_BLOCK*
11551179
pm_ppl_hash_get(
11561180
PMEMobjpool* pop,
11571181
PMEM_PAGE_PART_LOG* ppl,
@@ -1167,24 +1191,25 @@ pm_ppl_hash_get(
11671191
* @param[in] idx index of the block on the line
11681192
* @return: the hash item added
11691193
* */
1170-
static inline void
1171-
pm_ppl_hash_add(
1172-
PMEM_PAGE_LOG_HASHED_LINE* pline,
1173-
PMEM_PAGE_LOG_BLOCK* plog_block,
1174-
uint32_t idx
1175-
)
1176-
{
1177-
1178-
plog_hash_t* item;
1179-
1180-
item = (plog_hash_t*) malloc(sizeof(plog_hash_t));
1181-
item->key = plog_block->key;
1182-
item->block_off = idx;
1183-
HASH_INSERT(plog_hash_t, addr_hash, pline->addr_hash, plog_block->key, item);
1184-
1185-
}
1186-
1187-
plog_hash_t*
1194+
//static inline void
1195+
//pm_ppl_hash_add(
1196+
// PMEM_PAGE_LOG_HASHED_LINE* pline,
1197+
// PMEM_PAGE_LOG_BLOCK* plog_block,
1198+
// uint32_t idx
1199+
// )
1200+
//{
1201+
//
1202+
// plog_hash_t* item;
1203+
//
1204+
// item = (plog_hash_t*) malloc(sizeof(plog_hash_t));
1205+
// item->key = plog_block->key;
1206+
// item->block_off = idx;
1207+
// HASH_INSERT(plog_hash_t, addr_hash, pline->addr_hash, plog_block->key, item);
1208+
//
1209+
//}
1210+
1211+
//plog_hash_t*
1212+
PMEM_PAGE_LOG_BLOCK*
11881213
pm_ppl_hash_check_and_add(
11891214
PMEMobjpool* pop,
11901215
PMEM_PAGE_PART_LOG* ppl,

storage/innobase/log/log0recv.cc

+29-11
Original file line numberDiff line numberDiff line change
@@ -4428,6 +4428,7 @@ pm_ppl_analysis(
44284428
uint64_t min_delta;
44294429
uint64_t max_delta;
44304430
uint64_t total_delta;
4431+
uint64_t min_write_off;
44314432

44324433
TOID(PMEM_PAGE_LOG_HASHED_LINE) line;
44334434
PMEM_PAGE_LOG_HASHED_LINE* pline;
@@ -4478,13 +4479,27 @@ pm_ppl_analysis(
44784479
//plog_block->state = PMEM_FREE_BLOCK;
44794480
continue;
44804481
}
4482+
44814483
/*add block->key into the per-line hashtable */
4482-
pm_ppl_hash_add(pline, plog_block, j);
4484+
//pm_ppl_hash_add(pline, plog_block, j);
44834485

4484-
if(low_watermark >
4485-
(plog_block->start_diskaddr + plog_block->start_off)){
4486-
4487-
low_watermark = (plog_block->start_diskaddr + plog_block->start_off);
4486+
/*the minimum write offset of each pline*/
4487+
min_write_off = plog_block->start_diskaddr + plog_block->start_off;
4488+
4489+
/*add block->key into the per-line hashtable */
4490+
pline->key_map->insert(std::make_pair(plog_block->key, plog_block));
4491+
4492+
/*add min_write_off into the per-line sorted map*/
4493+
pline->offset_map->insert(std::make_pair(min_write_off, plog_block));
4494+
4495+
auto it = pline->offset_map->find(min_write_off);
4496+
if (it != pline->offset_map->end()){
4497+
assert(it->first == min_write_off);
4498+
}
4499+
4500+
if(low_watermark > min_write_off)
4501+
{
4502+
low_watermark = min_write_off;
44884503
low_diskaddr = plog_block->start_diskaddr;
44894504
low_offset = plog_block->start_off;
44904505

@@ -5219,13 +5234,16 @@ pm_ppl_recv_parse_log_rec(
52195234
PMEM_FOLD(key, *space, *page_no);
52205235

52215236
/*Get the log_block by hashtable. This hashtable is built during analysis phase*/
5222-
item = pm_ppl_hash_get(pop, ppl, pline, key);
5237+
//item = pm_ppl_hash_get(pop, ppl, pline, key);
5238+
5239+
//if (item == NULL) {
5240+
// plog_block = NULL;
5241+
//} else {
5242+
// plog_block = D_RW(D_RW(pline->arr)[item->block_off]);
5243+
//}
5244+
5245+
plog_block = pm_ppl_hash_get(pop, ppl, pline, key);
52235246

5224-
if (item == NULL) {
5225-
plog_block = NULL;
5226-
} else {
5227-
plog_block = D_RW(D_RW(pline->arr)[item->block_off]);
5228-
}
52295247
//We don't use this function because it has high overhead O(k)
52305248
//plog_block = pm_ppl_get_log_block_by_key(pop, ppl, key);
52315249
if (plog_block == NULL){

0 commit comments

Comments
 (0)