Skip to content

Commit 672ada5

Browse files
committed
fix bug in finish aio batch, check the list_id of the prev/next list with the current list
1 parent 5f06a23 commit 672ada5

File tree

5 files changed

+160
-46
lines changed

5 files changed

+160
-46
lines changed

storage/innobase/buf/buf0flu.cc

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4079,9 +4079,12 @@ DECLARE_THREAD(pm_flusher_worker)(
40794079
{
40804080
//***this call aio_batch ***
40814081
#if defined(UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
4082-
printf("in flusher thread, pointer id=%zu, list_id =%zu\n", i, plist->list_id);
4082+
printf("\n [2] BEGIN (in flusher thread), pointer id=%zu, list_id =%zu\n", i, plist->list_id);
40834083
#endif
40844084
pm_buf_flush_list(gb_pmw->pop, gb_pmw->pbuf, plist);
4085+
#if defined(UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
4086+
printf("\n [2] END (in flusher thread), pointer id=%zu, list_id =%zu\n", i, plist->list_id);
4087+
#endif
40854088
flusher->n_requested--;
40864089
os_event_set(flusher->is_req_full);
40874090
//we can set the pointer to null after the pm_buf_flush_list finished
@@ -4143,6 +4146,10 @@ pm_handle_finished_block_with_flusher(
41434146
TOID_ASSIGN(flush_list, pblock->list.oid);
41444147
PMEM_BUF_BLOCK_LIST* pflush_list = D_RW(flush_list);
41454148

4149+
PMEM_BUF_BLOCK_LIST* pnext_list;
4150+
PMEM_BUF_BLOCK_LIST* pprev_list;
4151+
4152+
41464153
assert(pflush_list);
41474154

41484155
pmemobj_rwlock_wrlock(pop, &pflush_list->lock);
@@ -4153,7 +4160,10 @@ pm_handle_finished_block_with_flusher(
41534160
pflush_list->n_aio_pending--;
41544161

41554162
if (pflush_list->n_aio_pending + pflush_list->n_sio_pending == 0) {
4156-
//printf("\n [begin finish AIO list %zu\n", pflush_list->list_id);
4163+
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
4164+
printf("\n [*****[4] BEGIN finish AIO list %zu hashed_id %zu\n",
4165+
pflush_list->list_id, pflush_list->hashed_id);
4166+
#endif
41574167
//Now all pages in this list are persistent in disk
41584168
//(0) flush spaces
41594169
pm_buf_flush_spaces_in_list(pop, buf, pflush_list);
@@ -4179,21 +4189,74 @@ pm_handle_finished_block_with_flusher(
41794189

41804190
// (2) Remove this list from the doubled-linked list
41814191
//assert( !TOID_IS_NULL(pflush_list->prev_list) );
4182-
if( !TOID_IS_NULL(pflush_list->prev_list) ) {
4183-
//if (is_lock_prev_list)
4184-
//pmemobj_rwlock_wrlock(pop, &D_RW(pflush_list->prev_list)->lock);
4185-
TOID_ASSIGN( D_RW(pflush_list->prev_list)->next_list, pflush_list->next_list.oid);
4186-
//if (is_lock_prev_list)
4187-
//pmemobj_rwlock_unlock(pop, &D_RW(pflush_list->prev_list)->lock);
4188-
}
4192+
4193+
pnext_list = D_RW(pflush_list->next_list);
4194+
pprev_list = D_RW(pflush_list->prev_list);
41894195

4190-
if (!TOID_IS_NULL(pflush_list->next_list) ) {
4191-
//pmemobj_rwlock_wrlock(pop, &D_RW(pflush_list->next_list)->lock);
4196+
if (pprev_list != NULL &&
4197+
D_RW(pprev_list->next_list) != NULL &&
4198+
D_RW(pprev_list->next_list)->list_id == pflush_list->list_id){
41924199

4193-
TOID_ASSIGN(D_RW(pflush_list->next_list)->prev_list, pflush_list->prev_list.oid);
4200+
if (pnext_list == NULL) {
4201+
TOID_ASSIGN(pprev_list->next_list, OID_NULL);
4202+
}
4203+
else {
4204+
TOID_ASSIGN(pprev_list->next_list, (pflush_list->next_list).oid);
4205+
}
4206+
}
41944207

4195-
//pmemobj_rwlock_unlock(pop, &D_RW(pflush_list->next_list)->lock);
4208+
if (pnext_list != NULL &&
4209+
D_RW(pnext_list->prev_list) != NULL &&
4210+
D_RW(pnext_list->prev_list)->list_id == pflush_list->list_id) {
4211+
if (pprev_list == NULL) {
4212+
TOID_ASSIGN(pnext_list->prev_list, OID_NULL);
4213+
}
4214+
else {
4215+
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
4216+
printf("[4] !!!!! handle finish, cur_list_id %zu ",
4217+
pflush_list->list_id);
4218+
printf ("[4] !!!! has next_list_id %zu ", pnext_list->list_id);
4219+
printf ("[4] !!!! has prev_list_id %zu \n", pprev_list->list_id);
4220+
#endif
4221+
TOID_ASSIGN(pnext_list->prev_list, (pflush_list->prev_list).oid);
4222+
}
41964223
}
4224+
4225+
//if( !TOID_IS_NULL(pflush_list->prev_list) &&
4226+
// D_RW(pflush_list->prev_list) != NULL &&
4227+
// D_RW(D_RW(pflush_list->prev_list)->next_list) != NULL ) {
4228+
// //if (is_lock_prev_list)
4229+
// //pmemobj_rwlock_wrlock(pop, &D_RW(pflush_list->prev_list)->lock);
4230+
// if (D_RW(pflush_list->next_list) == NULL) {
4231+
// TOID_ASSIGN( D_RW(pflush_list->prev_list)->next_list, OID_NULL);
4232+
// }
4233+
// else {
4234+
// TOID_ASSIGN( D_RW(pflush_list->prev_list)->next_list, pflush_list->next_list.oid);
4235+
// }
4236+
// //if (is_lock_prev_list)
4237+
// //pmemobj_rwlock_unlock(pop, &D_RW(pflush_list->prev_list)->lock);
4238+
//}
4239+
4240+
//This case is rarely, can occur bug if happen
4241+
//if (!TOID_IS_NULL(pflush_list->next_list) &&
4242+
// D_RW(pflush_list->next_list) != NULL &&
4243+
// D_RW(D_RW(pflush_list->next_list)->prev_list) != NULL ) {
4244+
// //pmemobj_rwlock_wrlock(pop, &D_RW(pflush_list->next_list)->lock);
4245+
// if ( D_RW(pflush_list->prev_list) == NULL) {
4246+
// TOID_ASSIGN( D_RW(pflush_list->next_list)->prev_list, OID_NULL);
4247+
// }
4248+
// else {
4249+
// #if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
4250+
// printf("[4] !!!!! handle finish, cur_list_id %zu ",
4251+
// pflush_list->list_id);
4252+
// printf ("[4] !!!! has next_list_id %zu ", D_RW(pflush_list->next_list)->list_id);
4253+
// printf ("[4] !!!! has prev_list_id %zu \n", D_RW(pflush_list->prev_list)->list_id);
4254+
// #endif
4255+
// TOID_ASSIGN(D_RW(pflush_list->next_list)->prev_list, pflush_list->prev_list.oid);
4256+
// }
4257+
4258+
// //pmemobj_rwlock_unlock(pop, &D_RW(pflush_list->next_list)->lock);
4259+
//}
41974260

41984261
TOID_ASSIGN(pflush_list->next_list, OID_NULL);
41994262
TOID_ASSIGN(pflush_list->prev_list, OID_NULL);
@@ -4202,15 +4265,16 @@ pm_handle_finished_block_with_flusher(
42024265
PMEM_BUF_FREE_POOL* pfree_pool;
42034266
pfree_pool = D_RW(buf->free_pool);
42044267

4205-
//printf("PMEM_DEBUG: in fil_aio_wait(), try to lock free_pool list id: %zd, cur_lists in free_pool= %zd \n", pflush_list->list_id, pfree_pool->cur_lists);
42064268
pmemobj_rwlock_wrlock(pop, &pfree_pool->lock);
42074269

42084270
POBJ_LIST_INSERT_TAIL(pop, &pfree_pool->head, flush_list, list_entries);
42094271
pfree_pool->cur_lists++;
42104272
//wakeup who is waitting for free_pool available
42114273
os_event_set(buf->free_pool_event);
42124274

4213-
//printf("end finish AIO List %zu]", pflush_list->list_id);
4275+
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
4276+
printf("\n *****[4] END finish AIO List %zu]\n", pflush_list->list_id);
4277+
#endif
42144278
pmemobj_rwlock_unlock(pop, &pfree_pool->lock);
42154279
}
42164280
//the list has some unfinished aio

storage/innobase/fil/fil0fil.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5945,7 +5945,10 @@ pm_fil_io_batch(
59455945
//params = pmem_buf->params_arr[plist->hashed_id];
59465946
ulint cur_free = pmem_buf->cur_free_param;
59475947
ulint arr_size = pmem_buf->param_arr_size;
5948-
5948+
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
5949+
printf("\n[2.1] BEGIN fill param info list_id %zu, hashed_id %zu ... \n",
5950+
plist->list_id, plist->hashed_id);
5951+
#endif
59495952
/*Note that this thread've acquired flusher->mutex, so we don't need another mutex for param_array*/
59505953
pmemobj_rwlock_wrlock(pop, &pmem_buf->param_lock);
59515954
for (i = 0; i < arr_size; i++) {
@@ -6194,7 +6197,15 @@ pm_fil_io_batch(
61946197
//Now submit in batch
61956198
dberr_t err;
61966199
/* Queue the aio request */
6200+
#if defined(UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
6201+
printf("\n [2.2] BEGIN os_aio_batch, list_id %zu hashed_id %zu... \n",
6202+
plist->list_id, plist->hashed_id);
6203+
#endif
61976204
err = os_aio_batch(params, n_params);
6205+
#if defined(UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
6206+
printf("\n [2.2] END os_aio_batch, list_id %zu hashed_id %zu... \n",
6207+
plist->list_id, plist->hashed_id);
6208+
#endif
61986209

61996210
if (err != DB_SUCCESS){
62006211
printf("PMEM_ERROR: pm_fil_io_batch()list id %zu\n", plist->list_id );

storage/innobase/include/my_pmemobj.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,13 @@ pm_buf_flush_list_cleaner_disabled_loop(void);
613613

614614
ulint
615615
hash_f1(
616+
ulint& hashed,
616617
uint32_t space_no,
617618
uint32_t page_no,
618-
uint64_t n_buckets,
619-
uint64_t page_per_bucket_bits);
619+
uint64_t n,
620+
uint64_t B,
621+
uint64_t S,
622+
uint64_t P);
620623

621624
#define PMEM_BUF_LIST_INSERT(pop, list, entries, type, func, args) do {\
622625
POBJ_LIST_INSERT_NEW_HEAD(pop, &list.head, entries, sizeof(type), func, &args); \
@@ -640,6 +643,12 @@ hash_f1(
640643
@S [in]: number of bits present space_no
641644
@P [in]: number of bits present max number of pages per space on a bucket, this value is log2(page_per_bucket)
642645
* */
646+
//#define PMEM_LESS_BUCKET_HASH_KEY(hashed, space, page)\
647+
// hash_f1(hashed, space, page,\
648+
// PMEM_N_BUCKETS,\
649+
// PMEM_N_BUCKET_BITS,\
650+
// PMEM_N_SPACE_BITS,\
651+
// PMEM_PAGE_PER_BUCKET_BITS)
643652
#define PMEM_LESS_BUCKET_HASH_KEY(hashed, space, page)\
644653
PARTITION_FUNC1(hashed, space, page,\
645654
PMEM_N_BUCKETS,\

storage/innobase/os/os0file.cc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7308,7 +7308,9 @@ AIO::pm_process_batch(
73087308
//assert (n_params <= slots_per_seg);
73097309
assert(srv_use_native_aio);
73107310
assert(!request.is_encrypted() && !request.is_compressed());
7311-
7311+
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
7312+
printf("\n [3] BEGIN pm_process_batch m_n_seg_reserved %zu \n", m_n_seg_reserved);
7313+
#endif
73127314
/*
73137315
* if n_params < slots_per_seg: just need 1 seg to handle (waste, because write thread can handle more params)
73147316
* if n_params == slots_per_seg: just need 1 seg to handle (OK)
@@ -7327,8 +7329,9 @@ AIO::pm_process_batch(
73277329
if (m_n_seg_reserved + n_seg_need < m_n_segments) {
73287330
break;
73297331
}
7330-
7331-
//printf("PMEM_INFO all segs are full, %zu/%zu, wait for a aio seg free...\n", m_n_seg_reserved, m_n_segments);
7332+
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
7333+
printf("\n [3] pm_process_batch all segs are full, %zu/%zu, wait for a aio seg free...\n", m_n_seg_reserved, m_n_segments);
7334+
#endif
73327335

73337336
release();
73347337
//os_event_wait(m_not_full);
@@ -7372,6 +7375,9 @@ AIO::pm_process_batch(
73727375
assert (wrapper->local_index == local_seg);
73737376
wrapper->io_pending = 0;
73747377

7378+
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
7379+
printf("\n [3.1] BEGIN assign params from input param \n");
7380+
#endif
73757381
//this loop does assign parameters from input params to io_cb
73767382
for (i = count, slot_i = local_seg * slots_per_seg;
73777383
i < n_params && slot_i < m_slots.size();
@@ -7439,6 +7445,9 @@ AIO::pm_process_batch(
74397445
//next param
74407446
} //end for
74417447

7448+
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
7449+
printf("\n [3.1] END assign params from input param \n");
7450+
#endif
74427451
//AIO Submit in batch
74437452
io_ctx_index = local_seg;
74447453
int ret = io_submit(
@@ -7448,6 +7457,10 @@ AIO::pm_process_batch(
74487457

74497458
//release();
74507459

7460+
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
7461+
printf("\n [3] END pm_process_batch m_n_seg_reserved %zu \n", m_n_seg_reserved);
7462+
#endif
7463+
74517464
if (ret == wrapper->io_pending){
74527465
//return DB_SUCCESS;
74537466
count = i;

0 commit comments

Comments
 (0)