Skip to content

Commit 9c4dd1b

Browse files
committed
prepare WAL mode. Implement UNIV_PMEMOBJ_BUF_APPEND that append page in pm_buf_write and read the lasted in pm_buf_read
1 parent ae95903 commit 9c4dd1b

File tree

15 files changed

+526
-47
lines changed

15 files changed

+526
-47
lines changed

storage/innobase/buf/buf0flu.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,8 @@ buf_flush_write_block_low(
10961096
int ret = pm_buf_write_no_free_pool(gb_pmw->pop, gb_pmw->pbuf, bpage->id, bpage->size, frame, sync);
10971097
#elif defined (UNIV_PMEMOBJ_BUF_FLUSHER)
10981098
int ret = pm_buf_write_with_flusher(gb_pmw->pop, gb_pmw->pbuf, bpage->id, bpage->size, frame, sync);
1099+
#elif defined (UNIV_PMEMOBJ_BUF_APPEND)
1100+
int ret = pm_buf_write_with_flusher_append(gb_pmw->pop, gb_pmw->pbuf, bpage->id, bpage->size, frame, sync);
10991101
#else
11001102
int ret = pm_buf_write(gb_pmw->pop, gb_pmw->pbuf, bpage->id, bpage->size, frame, sync);
11011103
#endif
@@ -4084,6 +4086,7 @@ DECLARE_THREAD(pm_flusher_worker)(
40844086
plist = flusher->flush_list_arr[i];
40854087
if (plist)
40864088
{
4089+
//***this call aio_batch ***
40874090
pm_buf_flush_list(gb_pmw->pop, gb_pmw->pbuf, plist);
40884091
flusher->n_requested--;
40894092
os_event_set(flusher->is_req_full);
@@ -4095,7 +4098,6 @@ DECLARE_THREAD(pm_flusher_worker)(
40954098
} //end if flusher->n_requested > 0
40964099

40974100
if (flusher->n_requested == 0) {
4098-
//if (srv_shutdown_state != SRV_SHUTDOWN_NONE) {
40994101
if (buf_page_cleaner_is_active) {
41004102
//buf_page_cleaner is running, start waiting
41014103
os_event_reset(flusher->is_req_not_empty);
@@ -4160,6 +4162,14 @@ pm_handle_finished_block_with_flusher(
41604162
//Now all pages in this list are persistent in disk
41614163
//(0) flush spaces
41624164
pm_buf_flush_spaces_in_list(pop, buf, pflush_list);
4165+
// Reset the param_array
4166+
ulint arr_idx;
4167+
arr_idx = pflush_list->param_arr_index;
4168+
assert(arr_idx >= 0);
4169+
4170+
pmemobj_rwlock_wrlock(pop, &buf->param_lock);
4171+
buf->param_arrs[arr_idx].is_free = true;
4172+
pmemobj_rwlock_unlock(pop, &buf->param_lock);
41634173

41644174
//(1) Reset blocks in the list
41654175
ulint i;

storage/innobase/buf/buf0rea.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ buf_read_page_low(
195195
);
196196
#if defined (UNIV_PMEMOBJ_BUF)
197197
//size_t read_bytes= pm_buf_read(gb_pmw->pop, gb_pmw->pbuf, page_id, page_size, (byte*)dst, sync);
198+
#if defined (UNIV_PMEMOBJ_BUF_APPEND)
199+
const PMEM_BUF_BLOCK* pblock= pm_buf_read_lasted(gb_pmw->pop, gb_pmw->pbuf, page_id, page_size, (byte*)dst, sync);
200+
#else
198201
const PMEM_BUF_BLOCK* pblock= pm_buf_read(gb_pmw->pop, gb_pmw->pbuf, page_id, page_size, (byte*)dst, sync);
202+
#endif
199203
//if (read_bytes > 0) {
200204
if (pblock) {
201205
if (sync) {

storage/innobase/fil/fil0fil.cc

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5930,8 +5930,34 @@ pm_fil_io_batch(
59305930
plist->n_flush = 0;
59315931
#endif
59325932
assert(plist->hashed_id != PMEM_ID_NONE);
5933+
5934+
//find a free params to fill aio_batch info
5935+
//params = pmem_buf->params_arr[plist->hashed_id];
5936+
ulint cur_free = pmem_buf->cur_free_param;
5937+
ulint arr_size = pmem_buf->param_arr_size;
5938+
5939+
/*Note that this thread've acquired flusher->mutex, so we don't need another mutex for param_array*/
5940+
pmemobj_rwlock_wrlock(pop, &pmem_buf->param_lock);
5941+
for (i = 0; i < arr_size; i++) {
5942+
if (pmem_buf->param_arrs[cur_free].is_free) {
5943+
params = pmem_buf->param_arrs[cur_free].params;
5944+
pmem_buf->param_arrs[cur_free].is_free = false; //we set this true in io_complete
5945+
plist->param_arr_index = cur_free;
5946+
pmem_buf->cur_free_param = (cur_free + 1) % arr_size;
5947+
break;
5948+
}
5949+
else {
5950+
cur_free = (cur_free + 1) % arr_size;
5951+
}
5952+
}
59335953

5934-
params = pmem_buf->params_arr[plist->hashed_id];
5954+
if (i == arr_size) {
5955+
//There is no free params to assign
5956+
printf("PMEM_ERROR: there is no free params to assign");
5957+
assert(0);
5958+
}
5959+
pmemobj_rwlock_unlock(pop, &pmem_buf->param_lock);
5960+
//params = pmem_buf->params_arr[plist->hashed_id];
59355961

59365962
n_params = 0;
59375963

storage/innobase/fsp/fsp0file.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,13 @@ Datafile::read_first_page(bool read_only_mode)
339339
ulint n_read = 0;
340340
#if defined (UNIV_PMEMOBJ_BUF)
341341
//size_t read_bytes= pm_buf_read(gb_pmw->pop, gb_pmw->pbuf,
342+
#if defined (UNIV_PMEMOBJ_BUF_APPEND)
343+
const PMEM_BUF_BLOCK* pblock = pm_buf_read_lasted(gb_pmw->pop, gb_pmw->pbuf,
344+
page_id_t(0,0), page_size_t(UNIV_PAGE_SIZE, UNIV_PAGE_SIZE, false), m_first_page, true);
345+
#else
342346
const PMEM_BUF_BLOCK* pblock = pm_buf_read(gb_pmw->pop, gb_pmw->pbuf,
343347
page_id_t(0,0), page_size_t(UNIV_PAGE_SIZE, UNIV_PAGE_SIZE, false), m_first_page, true);
348+
#endif
344349
//if (read_bytes > 0) {
345350
if (pblock) {
346351
err = DB_SUCCESS;

storage/innobase/handler/ha_innodb.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4448,7 +4448,7 @@ innobase_commit(
44484448

44494449
/* Now do a write + flush of logs. */
44504450
if (!read_only) {
4451-
#if defined(UNIV_PMEMOBJ_LOG)
4451+
#if defined(UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
44524452
/*Set this flag to true make the trx_commit_complete_for_mysql() do nothing
44534453
//Since the log buffer now is in NVDIMM, we can safely skip writting
44544454
//and flushing log records when the transaction commit
@@ -19522,7 +19522,7 @@ static MYSQL_SYSVAR_ULONG(pmem_page_per_bucket_bits, srv_pmem_page_per_bucket_bi
1952219522
"Number of bits present the maxmum number of pages per space in a bucket in partition algorithm, from 1 to log2(srv_pmem_buf_bucket_size), default is 10.",
1952319523
NULL, NULL, 10, 1, 32, 0);
1952419524
#endif
19525-
#if defined (UNIV_PMEMOBJ_BUF) || defined (UNIV_PMEMOBJ_DBW) || defined (UNIV_PMEMOBJ_LOG)
19525+
#if defined (UNIV_PMEMOBJ_BUF) || defined (UNIV_PMEMOBJ_DBW) || defined (UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
1952619526
static MYSQL_SYSVAR_STR(pmem_home_dir, srv_pmem_home_dir,
1952719527
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
1952819528
"Path to PMEM home dir.", NULL, NULL, NULL);
@@ -20364,7 +20364,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
2036420364
MYSQL_SYSVAR(pmem_n_space_bits),
2036520365
MYSQL_SYSVAR(pmem_page_per_bucket_bits),
2036620366
#endif
20367-
#if defined (UNIV_PMEMOBJ_BUF) || defined (UNIV_PMEMOBJ_DBW) || defined (UNIV_PMEMOBJ_LOG)
20367+
#if defined (UNIV_PMEMOBJ_BUF) || defined (UNIV_PMEMOBJ_DBW) || defined (UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
2036820368
MYSQL_SYSVAR(pmem_home_dir),
2036920369
MYSQL_SYSVAR(pmem_pool_size),
2037020370
MYSQL_SYSVAR(pmem_buf_size),

storage/innobase/include/my_pmemobj.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ struct __pmem_buf_block_list_t {
250250
int check;
251251
ulint last_time;
252252

253+
ulint param_arr_index; //index of the param in the param_arrs used to carry the info of this list
253254
//int flush_worker_id;
254255
//bool is_worker_handling;
255256

@@ -286,13 +287,19 @@ struct __pmem_buf {
286287
//Those varables are in DRAM
287288
os_event_t* flush_events; //N flush events for N buckets
288289
os_event_t free_pool_event; //event for free_pool
289-
PMEM_AIO_PARAM** params_arr;
290+
291+
292+
PMEMrwlock param_lock;
293+
PMEM_AIO_PARAM_ARRAY* param_arrs;//circular array of pointers
294+
ulint param_arr_size; //size of the array
295+
ulint cur_free_param; //circular index, where the next free params is
290296

291297
PMEM_FLUSHER* flusher;
292298

293299
PMEM_FILE_MAP* filemap;
294300
};
295301

302+
296303
// PARTITION //////////////
297304
/*Map space id to hashed_id, for partition purpose
298305
* */
@@ -418,6 +425,15 @@ pm_buf_write_with_flusher(
418425
page_size_t size,
419426
byte* src_data,
420427
bool sync);
428+
int
429+
pm_buf_write_with_flusher_append(
430+
PMEMobjpool* pop,
431+
PMEM_BUF* buf,
432+
page_id_t page_id,
433+
page_size_t size,
434+
byte* src_data,
435+
bool sync);
436+
421437

422438
const PMEM_BUF_BLOCK*
423439
pm_buf_read(
@@ -428,6 +444,15 @@ pm_buf_read(
428444
byte* data,
429445
bool sync);
430446

447+
const PMEM_BUF_BLOCK*
448+
pm_buf_read_lasted(
449+
PMEMobjpool* pop,
450+
PMEM_BUF* buf,
451+
const page_id_t page_id,
452+
const page_size_t size,
453+
byte* data,
454+
bool sync);
455+
431456
void
432457
pm_buf_flush_list(
433458
PMEMobjpool* pop,

storage/innobase/include/os0file.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,8 @@ pfs_os_aio_func(
15051505
#if defined (UNIV_PMEMOBJ_BUF)
15061506
struct __pmem_aio_param;
15071507
typedef struct __pmem_aio_param PMEM_AIO_PARAM;
1508+
struct __pmem_aio_param_arr;
1509+
typedef struct __pmem_aio_param_arr PMEM_AIO_PARAM_ARRAY;
15081510

15091511
struct __pmem_aio_param {
15101512
const char* name;
@@ -1515,6 +1517,10 @@ struct __pmem_aio_param {
15151517
fil_node_t* m1;
15161518
void* m2;
15171519
};
1520+
struct __pmem_aio_param_arr {
1521+
bool is_free;
1522+
PMEM_AIO_PARAM* params;
1523+
};
15181524

15191525
UNIV_INLINE
15201526
dberr_t

storage/innobase/include/srv0srv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ extern ulong srv_pmem_n_flush_threads;
281281
extern ulong srv_pmem_n_space_bits;
282282
extern ulong srv_pmem_page_per_bucket_bits;
283283
#endif
284-
#if defined(UNIV_PMEMOBJ_BUF) || defined (UNIV_PMEMOBJ_DBW) || defined (UNIV_PMEMOBJ_LOG)
284+
#if defined(UNIV_PMEMOBJ_BUF) || defined (UNIV_PMEMOBJ_DBW) || defined (UNIV_PMEMOBJ_LOG) || defined(UNIV_PMEMOBJ_WAL)
285285
extern char* srv_pmem_home_dir;
286286
extern ulong srv_pmem_pool_size;
287287
extern ulong srv_pmem_buf_size;

storage/innobase/log/log0log.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ log_buffer_extend(
224224

225225
log_sys->buf_free -= move_start;
226226
log_sys->buf_next_to_write -= move_start;
227-
#if defined (UNIV_PMEMOBJ_LOG)
227+
#if defined (UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
228228
/* reallocate log buffer */
229229
srv_log_buffer_size = len / UNIV_PAGE_SIZE + 1;
230230
//do not free here, does it by our API
@@ -472,7 +472,7 @@ log_write_low(
472472
- LOG_BLOCK_TRL_SIZE;
473473
}
474474

475-
#if defined (UNIV_PMEMOBJ_LOG)
475+
#if defined (UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
476476
//copy the trasaction's log records to persistent memory
477477
pmemobj_memcpy_persist(gb_pmw->pop, log->buf + log->buf_free, str, len);
478478
//set the flag here
@@ -512,7 +512,7 @@ log_write_low(
512512
if (str_len > 0) {
513513
goto part_loop;
514514
}
515-
#if defined(UNIV_PMEMOBJ_LOG)
515+
#if defined(UNIV_PMEMOBJ_LOG) || defined(UNIV_PMEMOBJ_WAL)
516516
// update the lsn and buf_free
517517
gb_pmw->plogbuf->lsn = log->lsn;
518518
gb_pmw->plogbuf->buf_free = log->buf_free;
@@ -860,7 +860,7 @@ log_init(void)
860860
ut_a(LOG_BUFFER_SIZE >= 4 * UNIV_PAGE_SIZE);
861861

862862
log_sys->buf_size = LOG_BUFFER_SIZE;
863-
#if defined(UNIV_PMEMOBJ_LOG)
863+
#if defined(UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
864864
//allocate the log buffer in persistent memory
865865
if (!gb_pmw->plogbuf){
866866
if ( pm_wrapper_logbuf_alloc(gb_pmw, 2 * LOG_BUFFER_SIZE + OS_FILE_LOG_BLOCK_SIZE)
@@ -929,7 +929,7 @@ log_init(void)
929929

930930
log_sys->buf_free = LOG_BLOCK_HDR_SIZE;
931931
log_sys->lsn = LOG_START_LSN + LOG_BLOCK_HDR_SIZE;
932-
#if defined(UNIV_PMEMOBJ_LOG)
932+
#if defined(UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
933933
//Update the lsn, buf_free in necessary
934934
if(gb_pmw->plogbuf->lsn < log_sys->lsn)
935935
gb_pmw->plogbuf->lsn = log_sys->lsn;
@@ -1002,7 +1002,7 @@ log_io_complete(
10021002
/*============*/
10031003
log_group_t* group) /*!< in: log group or a dummy pointer */
10041004
{
1005-
#if defined (UNIV_PMEMOBJ_LOG)
1005+
#if defined (UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
10061006
//In original: This function called by fil_aio_wait as async call from log_checkpoint
10071007
//In our PMEMOBJ_LOG, log_write_up_to use async too, so we need distinguish between two cases
10081008

@@ -1223,7 +1223,7 @@ log_group_write_buf(
12231223

12241224
const ulint page_no
12251225
= (ulint) (next_offset / univ_page_size.physical());
1226-
#if defined (UNIV_PMEMOBJ_LOG)
1226+
#if defined (UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
12271227
//We can write async when the log buffer is in PMEM
12281228
//We don't adjust group to group + 1 because we already handled that in log_io_complete
12291229
fil_io(IORequestLogWrite, false,
@@ -2631,7 +2631,7 @@ log_shutdown(void)
26312631
/*==============*/
26322632
{
26332633
log_group_close_all();
2634-
#if defined(UNIV_PMEMOBJ_LOG)
2634+
#if defined(UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
26352635
//The pmem free() is done later
26362636
//do nothing for log_sys->buf_ptr
26372637
#else //original

storage/innobase/log/log0recv.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool recv_replay_file_ops = true;
6868
#include "fut0lst.h"
6969
#endif /* !UNIV_HOTBACKUP */
7070

71-
#if defined(UNIV_PMEMOBJ_LOG)
71+
#if defined(UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
7272
#include "my_pmemobj.h"
7373
extern PMEM_WRAPPER* gb_pmw;
7474
#endif
@@ -4293,7 +4293,7 @@ recv_recovery_from_checkpoint_start(
42934293

42944294
log_sys->next_checkpoint_no = checkpoint_no + 1;
42954295

4296-
#if defined(UNIV_PMEMOBJ_LOG)
4296+
#if defined(UNIV_PMEMOBJ_LOG) || defined (UNIV_PMEMOBJ_WAL)
42974297
if ( gb_pmw->plogbuf->buf_free > log_sys->buf_free &&
42984298
gb_pmw->plogbuf->lsn > log_sys->lsn ) {
42994299
uint64_t len = gb_pmw->plogbuf->buf_free - log_sys->buf_free;

0 commit comments

Comments
 (0)