Skip to content

Commit 89e1b84

Browse files
committed
Initialized necessary data structures for temporary write buffer
1 parent b6ae30e commit 89e1b84

File tree

6 files changed

+110
-3
lines changed

6 files changed

+110
-3
lines changed

storage/innobase/buf/buf0buf.cc

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,50 @@ buf_pool_init_instance(
18341834
buf_pool->watch[i].buf_pool_index = buf_pool->instance_no;
18351835
}
18361836

1837+
/* mijin */
1838+
buf_pool->need_to_flush_twb = false;
1839+
buf_pool->batch_running = false;
1840+
buf_pool->flush_running = false;
1841+
1842+
buf_pool->b_event = os_event_create(0);
1843+
buf_pool->f_event = os_event_create(0);
1844+
1845+
buf_pool->total_entry = srv_LRU_scan_depth;
1846+
buf_pool->first_free = 0;
1847+
1848+
/* Initialize the temporary write buffer. */
1849+
buf_pool->write_buf_unaligned = static_cast<byte*>(
1850+
ut_malloc_nokey((1 + buf_pool->total_entry) * UNIV_PAGE_SIZE));
1851+
1852+
buf_pool->write_buf = static_cast<byte*>(
1853+
ut_align(buf_pool->write_buf_unaligned,
1854+
UNIV_PAGE_SIZE));
1855+
1856+
/* Initialize hash structure for copy pool. */
1857+
srv_n_twb_hash_locks = static_cast<ulong>(
1858+
ut_2_power_up(srv_n_twb_hash_locks));
1859+
1860+
buf_pool->twb_hash = ib_create(
1861+
2 * buf_pool->total_entry,
1862+
LATCH_ID_HASH_TABLE_RW_LOCK,
1863+
srv_n_twb_hash_locks,
1864+
MEM_HEAP_FOR_TWB_HASH);
1865+
1866+
/* Initialize a block and page structure. */
1867+
buf_pool->twb_block_arr = static_cast<buf_block_t*>(
1868+
ut_zalloc_nokey(buf_pool->total_entry * sizeof(buf_block_t)));
1869+
1870+
for (i = 0; i < buf_pool->total_entry; i++) {
1871+
mutex_create(LATCH_ID_BUF_BLOCK_MUTEX,
1872+
&(buf_pool->copy_block_arr[i]).mutex);
1873+
rw_lock_create(PFS_NOT_INSTRUMENTED,
1874+
&(buf_pool->copy_block_arr[i]).lock, SYNC_LEVEL_VARYING);
1875+
1876+
assert(!posix_memalign((void **) &(buf_pool->copy_block_arr[i]).frame,
1877+
4096, UNIV_PAGE_SIZE));
1878+
}
1879+
/* end */
1880+
18371881
/* All fields are initialized by ut_zalloc_nokey(). */
18381882

18391883
buf_pool->try_LRU_scan = TRUE;
@@ -1922,6 +1966,17 @@ buf_pool_free_instance(
19221966
hash_table_free(buf_pool->page_hash);
19231967
hash_table_free(buf_pool->zip_hash);
19241968

1969+
/* mijin */
1970+
os_event_destroy(buf_pool->b_event);
1971+
os_event_destroy(buf_pool->f_event);
1972+
1973+
ut_free(buf_pool->write_buf_unaligned);
1974+
ut_free(buf_pool->twb_block_arr);
1975+
1976+
ha_clear(buf_pool->twb_hash);
1977+
hash_table_free(buf_pool->twb_hash);
1978+
/* end */
1979+
19251980
buf_pool->allocator.~ut_allocator();
19261981
}
19271982

@@ -5000,6 +5055,10 @@ buf_page_init_low(
50005055
HASH_INVALIDATE(bpage, hash);
50015056

50025057
ut_d(bpage->file_page_was_freed = FALSE);
5058+
5059+
/* mijin */
5060+
bpage->copy_target = false;
5061+
/* end */
50035062
}
50045063

50055064
/** Inits a page to the buffer buf_pool.
@@ -5882,6 +5941,30 @@ buf_page_io_complete(
58825941

58835942
buf_pool->stat.n_pages_written++;
58845943

5944+
/* mijin: TODO: NEED TO BE FIXED!!!*/
5945+
if (bpage->copy_target) {
5946+
twb_meta_dir_t* entry = NULL;
5947+
ulint fold;
5948+
5949+
fold = bpage->id.fold();
5950+
5951+
rw_lock_s_lock(buf_pool->twb_hash_lock);
5952+
HASH_SEARCH(hash, buf_pool->copy_pool_cache, fold, copy_pool_meta_dir_t*, entry, ut_ad(1),
5953+
entry->space == bpage->space && entry->offset == bpage->offset);
5954+
rw_lock_s_unlock(buf_pool->copy_pool_cache_hash_lock);
5955+
5956+
if (entry) {
5957+
rw_lock_x_lock(buf_pool->copy_pool_cache_hash_lock);
5958+
HASH_DELETE(copy_pool_meta_dir_t, hash, buf_pool->copy_pool_cache, fold, entry);
5959+
rw_lock_x_unlock(buf_pool->copy_pool_cache_hash_lock);
5960+
5961+
free(entry);
5962+
}
5963+
}
5964+
/* end */
5965+
5966+
5967+
58855968
/* We decide whether or not to evict the page from the
58865969
LRU list based on the flush_type.
58875970
* BUF_FLUSH_LIST: don't evict

storage/innobase/ha/ha0ha.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ ib_create(
5959
hash_table_t* table;
6060

6161
ut_a(type == MEM_HEAP_FOR_BTR_SEARCH
62-
|| type == MEM_HEAP_FOR_PAGE_HASH);
62+
|| type == MEM_HEAP_FOR_PAGE_HASH
63+
/* mijin */
64+
|| type == MEM_HEAP_FOR_TWB_HASH
65+
/* end */);
6366

6467
ut_ad(ut_is_2pow(n_sync_obj));
6568
table = hash_create(n);
@@ -78,9 +81,12 @@ ib_create(
7881
return(table);
7982
}
8083

81-
if (type == MEM_HEAP_FOR_PAGE_HASH) {
84+
if (type == MEM_HEAP_FOR_PAGE_HASH
85+
/* mijin*/
86+
|| type == MEM_HEAP_FOR_TWB_HASH
87+
/* end */) {
8288
/* We create a hash table protected by rw_locks for
83-
buf_pool->page_hash. */
89+
buf_pool->page_hash or buf_pool->twb_hash. */
8490
hash_create_sync_obj(
8591
table, HASH_TABLE_SYNC_RW_LOCK, id, n_sync_obj);
8692
} else {

storage/innobase/handler/ha_innodb.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19709,6 +19709,13 @@ static MYSQL_SYSVAR_ULONG(page_hash_locks, srv_n_page_hash_locks,
1970919709
"Number of rw_locks protecting buffer pool page_hash. Rounded up to the next power of 2",
1971019710
NULL, NULL, 16, 1, MAX_PAGE_HASH_LOCKS, 0);
1971119711

19712+
/* mijin */
19713+
static MYSQL_SYSVAR_ULONG(twb_hash_locks, srv_n_twb_hash_locks,
19714+
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
19715+
"Number of rw_locks protecting buffer pool twb_hash. Rounded up to the next power of 2",
19716+
NULL, NULL, 16, 1, 1024, 0);
19717+
/* end */
19718+
1971219719
static MYSQL_SYSVAR_ULONG(doublewrite_batch_size, srv_doublewrite_batch_size,
1971319720
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
1971419721
"Number of pages reserved in doublewrite buffer for batch flushing",

storage/innobase/include/mem0mem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ buffer pool; the latter method is used for very big heaps */
6060
/** Different type of heaps in terms of which datastructure is using them */
6161
#define MEM_HEAP_FOR_BTR_SEARCH (MEM_HEAP_BTR_SEARCH | MEM_HEAP_BUFFER)
6262
#define MEM_HEAP_FOR_PAGE_HASH (MEM_HEAP_DYNAMIC)
63+
/* mijin */
64+
#define MEM_HEAP_FOR_TWB_HASH (MEM_HEAP_DYNAMIC)
65+
/* end */
6366
#define MEM_HEAP_FOR_RECV_SYS (MEM_HEAP_BUFFER)
6467
#define MEM_HEAP_FOR_LOCK_HEAP (MEM_HEAP_BUFFER)
6568

storage/innobase/include/srv0srv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ extern ulong srv_buf_pool_instances;
312312
extern const ulong srv_buf_pool_instances_default;
313313
/** Number of locks to protect buf_pool->page_hash */
314314
extern ulong srv_n_page_hash_locks;
315+
/* mijin */
316+
/** Number of locks to protect buf_pool->twb_hash */
317+
extern ulong srv_n_twb_hash_locks;
318+
/* end */
315319
/** Scan depth for LRU flush batch i.e.: number of blocks scanned*/
316320
extern ulong srv_LRU_scan_depth;
317321
/** Whether or not to flush neighbors of a block */

storage/innobase/srv/srv0srv.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ ulong srv_buf_pool_instances;
257257
const ulong srv_buf_pool_instances_default = 0;
258258
/** Number of locks to protect buf_pool->page_hash */
259259
ulong srv_n_page_hash_locks = 16;
260+
/* mijin */
261+
/** Number of locks to protect buf_pool->twb_hash */
262+
ulong srv_n_twb_hash_locks = 16;
263+
/* end */
260264
/** Scan depth for LRU flush batch i.e.: number of blocks scanned*/
261265
ulong srv_LRU_scan_depth = 1024;
262266
/** Whether or not to flush neighbors of a block */

0 commit comments

Comments
 (0)