Commit 8ccb3caa authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-17491 micro optimize page_id_t further

Let us define page_id_t as a thin wrapper of uint64_t so that
the comparison operators can be simplified. This is a follow-up
to the original commit 14be8143.

The comparison operator for recv_sys.pages.emplace() turned out to be
a busy spot in a recovery benchmark. That data structure was introduced
in MDEV-19586 in commit 177a571e.
parent f3dac591
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Copyright (c) 1995, 2018, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2018, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2008, Google Inc. Copyright (c) 2008, Google Inc.
Copyright (c) 2013, 2019, MariaDB Corporation. Copyright (c) 2013, 2020, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted by Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described Google, Inc. Those modifications are gratefully acknowledged and are described
...@@ -7144,14 +7144,11 @@ buf_pool_check_no_pending_io(void) ...@@ -7144,14 +7144,11 @@ buf_pool_check_no_pending_io(void)
@param[in,out] out the output stream @param[in,out] out the output stream
@param[in] page_id the page_id_t object to be printed @param[in] page_id the page_id_t object to be printed
@return the output stream */ @return the output stream */
std::ostream& std::ostream& operator<<(std::ostream &out, const page_id_t page_id)
operator<<(
std::ostream& out,
const page_id_t page_id)
{ {
out << "[page id: space=" << page_id.m_space out << "[page id: space=" << page_id.space()
<< ", page number=" << page_id.m_page_no << "]"; << ", page number=" << page_id.page_no() << "]";
return(out); return out;
} }
/** Print the given buf_pool_t object. /** Print the given buf_pool_t object.
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved. Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2019, MariaDB Corporation. Copyright (c) 2019, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -135,80 +135,49 @@ this must be equal to srv_page_size */ ...@@ -135,80 +135,49 @@ this must be equal to srv_page_size */
/* @} */ /* @} */
/** Page identifier. */ /** Page identifier. */
class page_id_t { class page_id_t
{
public: public:
/** Constructor from (space, page_no).
/** Constructor from (space, page_no). @param[in] space tablespace id
@param[in] space tablespace id @param[in] page_no page number */
@param[in] page_no page number */ page_id_t(ulint space, ulint page_no) : m_id(uint64_t{space} << 32 | page_no)
page_id_t(ulint space, ulint page_no) {
: m_space(uint32_t(space)), m_page_no(uint32(page_no)) ut_ad(space <= 0xFFFFFFFFU);
{ ut_ad(page_no <= 0xFFFFFFFFU);
ut_ad(space <= 0xFFFFFFFFU); }
ut_ad(page_no <= 0xFFFFFFFFU);
} bool operator==(const page_id_t& rhs) const { return m_id == rhs.m_id; }
bool operator!=(const page_id_t& rhs) const { return m_id != rhs.m_id; }
bool operator==(const page_id_t& rhs) const
{ bool operator<(const page_id_t& rhs) const { return m_id < rhs.m_id; }
return m_space == rhs.m_space && m_page_no == rhs.m_page_no;
} /** Retrieve the tablespace id.
bool operator!=(const page_id_t& rhs) const { return !(*this == rhs); } @return tablespace id */
uint32_t space() const { return static_cast<uint32_t>(m_id >> 32); }
bool operator<(const page_id_t& rhs) const
{ /** Retrieve the page number.
if (m_space == rhs.m_space) { @return page number */
return m_page_no < rhs.m_page_no; uint32_t page_no() const { return static_cast<uint32_t>(m_id); }
}
/** Retrieve the fold value.
return m_space < rhs.m_space; @return fold value */
} ulint fold() const { return (space() << 20) + space() + page_no(); }
/** Retrieve the tablespace id. /** Reset the page number only.
@return tablespace id */ @param[in] page_no page number */
uint32_t space() const { return m_space; } void set_page_no(ulint page_no)
{
/** Retrieve the page number. ut_ad(page_no <= 0xFFFFFFFFU);
@return page number */ m_id= (m_id & ~uint64_t{0} << 32) | page_no;
uint32_t page_no() const { return m_page_no; } }
/** Retrieve the fold value. /** Set the FIL_NULL for the space and page_no */
@return fold value */ void set_corrupt_id() { m_id= ~uint64_t{0}; }
ulint fold() const { return (m_space << 20) + m_space + m_page_no; }
/** Reset the page number only.
@param[in] page_no page number */
void set_page_no(ulint page_no)
{
m_page_no = uint32_t(page_no);
ut_ad(page_no <= 0xFFFFFFFFU);
}
/** Set the FIL_NULL for the space and page_no */
void set_corrupt_id()
{
m_space = m_page_no = ULINT32_UNDEFINED;
}
private: private:
/** The page identifier */
/** Tablespace id. */ uint64_t m_id;
uint32_t m_space;
/** Page number. */
uint32_t m_page_no;
/** Declare the overloaded global operator<< as a friend of this
class. Refer to the global declaration for further details. Print
the given page_id_t object.
@param[in,out] out the output stream
@param[in] page_id the page_id_t object to be printed
@return the output stream */
friend
std::ostream&
operator<<(
std::ostream& out,
const page_id_t page_id);
}; };
#ifndef UNIV_INNOCHECKSUM #ifndef UNIV_INNOCHECKSUM
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment