1/*****************************************************************************
2
3Copyright (c) 2016, Percona Inc. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15Street, Fifth Floor, Boston, MA 02110-1301, USA
16
17*****************************************************************************/
18
19/**************************************************//**
20@file include/buf0dblwr.ic
21Inline definitions for the doublewrite buffer
22
23*******************************************************/
24
25
26/** Return the number of partitions in the parallel doublewrite buffer
27@return number of parallel doublewrite partitions */
28MY_ATTRIBUTE((warn_unused_result))
29UNIV_INLINE
30ulint
31buf_parallel_dblwr_shard_num(void)
32{
33	compile_time_assert(BUF_FLUSH_LIST < 2);
34	compile_time_assert(BUF_FLUSH_LRU < 2);
35	return 2 * srv_buf_pool_instances;
36}
37
38/** Return the doublewrite partition number for a given buffer pool and flush
39type.
40@return the doublewrite partition number */
41MY_ATTRIBUTE((warn_unused_result))
42UNIV_INLINE
43ulint
44buf_parallel_dblwr_partition(ulint instance_no, buf_flush_t flush_type)
45{
46	ut_ad(flush_type == BUF_FLUSH_LIST || flush_type == BUF_FLUSH_LRU);
47	ut_ad(instance_no < srv_buf_pool_instances);
48	ulint result = instance_no * 2 + flush_type;
49	ut_ad(result < buf_parallel_dblwr_shard_num());
50	return(result);
51}
52
53/** Return the doublewrite partition number for a given buffer page and flush
54type.
55@return the doublewrite partition number */
56MY_ATTRIBUTE((warn_unused_result))
57UNIV_INLINE
58ulint
59buf_parallel_dblwr_partition(const buf_page_t* bpage, buf_flush_t flush_type)
60{
61	return(buf_parallel_dblwr_partition(bpage->buf_pool_index,
62					    flush_type));
63}
64
65/** Return the doublewrite partition number for a given buffer pool and flush
66type.
67@return the doublewrite partition number */
68MY_ATTRIBUTE((warn_unused_result))
69UNIV_INLINE
70ulint
71buf_parallel_dblwr_partition(const buf_pool_t* buf_pool,
72			     buf_flush_t flush_type)
73{
74	return(buf_parallel_dblwr_partition(buf_pool->instance_no, flush_type));
75}
76