MySQL 8.4.2
Source Code Documentation
table_id.h
Go to the documentation of this file.
1/* Copyright (c) 2013, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23/**
24 @file table_id.h
25
26 @brief Contains the class Table_id, mainly used for row based replication.
27*/
28
29#ifndef MYSQL_BINLOG_EVENT_TABLE_ID_H
30#define MYSQL_BINLOG_EVENT_TABLE_ID_H
31#include <stdint.h>
33
34namespace mysql::binlog::event {
35
36/**
37 @class Table_id
38
39 @brief Each table share has a table id, it is mainly used for row based
40 replication. Meanwhile it is used as table's version too.
41*/
42class Table_id {
43 private:
44 /* In table map event and rows events, table id is 6 bytes.*/
45 static const unsigned long long TABLE_ID_MAX = (~0ULL >> 16);
46 uint64_t m_id;
47
48 public:
49 Table_id() : m_id(0) {}
50 explicit Table_id(unsigned long long id) : m_id(id) {}
51
52 unsigned long long id() const { return m_id; }
53 bool is_valid() const { return m_id <= TABLE_ID_MAX; }
54
55 Table_id &operator=(unsigned long long id) {
56 m_id = id;
57 return *this;
58 }
59
60 bool operator==(const Table_id &tid) const { return m_id == tid.m_id; }
61 bool operator!=(const Table_id &tid) const { return m_id != tid.m_id; }
62
63 /* Support implicit type converting from Table_id to unsigned long long */
64 operator unsigned long long() const { return m_id; }
65
68
69 /* m_id is reset to 0, when it exceeds the max value. */
70 m_id = (m_id == TABLE_ID_MAX ? 0 : m_id + 1);
71
73 return id;
74 }
75};
76
77} // namespace mysql::binlog::event
78
79#endif // MYSQL_BINLOG_EVENT_TABLE_ID_H
Each table share has a table id, it is mainly used for row based replication.
Definition: table_id.h:42
bool operator!=(const Table_id &tid) const
Definition: table_id.h:61
Table_id(unsigned long long id)
Definition: table_id.h:50
bool is_valid() const
Definition: table_id.h:53
static const unsigned long long TABLE_ID_MAX
Definition: table_id.h:45
Table_id()
Definition: table_id.h:49
uint64_t m_id
Definition: table_id.h:46
Table_id operator++(int)
Definition: table_id.h:66
Table_id & operator=(unsigned long long id)
Definition: table_id.h:55
unsigned long long id() const
Definition: table_id.h:52
bool operator==(const Table_id &tid) const
Definition: table_id.h:60
The namespace contains classes representing events that can occur in a replication stream.
Definition: binlog_event.cpp:36
Contains wrapper functions for memory allocation and deallocation.
#define BAPI_ASSERT(x)
Definition: wrapper_functions.h:61