MySQL 8.3.0
Source Code Documentation
table_id.h
Go to the documentation of this file.
1/* Copyright (c) 2013, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22/**
23 @file table_id.h
24
25 @brief Contains the class Table_id, mainly used for row based replication.
26*/
27
28#ifndef MYSQL_BINLOG_EVENT_TABLE_ID_H
29#define MYSQL_BINLOG_EVENT_TABLE_ID_H
30#include <stdint.h>
32
33namespace mysql::binlog::event {
34
35/**
36 @class Table_id
37
38 @brief Each table share has a table id, it is mainly used for row based
39 replication. Meanwhile it is used as table's version too.
40*/
41class Table_id {
42 private:
43 /* In table map event and rows events, table id is 6 bytes.*/
44 static const unsigned long long TABLE_ID_MAX = (~0ULL >> 16);
45 uint64_t m_id;
46
47 public:
48 Table_id() : m_id(0) {}
49 explicit Table_id(unsigned long long id) : m_id(id) {}
50
51 unsigned long long id() const { return m_id; }
52 bool is_valid() const { return m_id <= TABLE_ID_MAX; }
53
54 Table_id &operator=(unsigned long long id) {
55 m_id = id;
56 return *this;
57 }
58
59 bool operator==(const Table_id &tid) const { return m_id == tid.m_id; }
60 bool operator!=(const Table_id &tid) const { return m_id != tid.m_id; }
61
62 /* Support implicit type converting from Table_id to unsigned long long */
63 operator unsigned long long() const { return m_id; }
64
67
68 /* m_id is reset to 0, when it exceeds the max value. */
69 m_id = (m_id == TABLE_ID_MAX ? 0 : m_id + 1);
70
72 return id;
73 }
74};
75
76} // namespace mysql::binlog::event
77
78#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:41
bool operator!=(const Table_id &tid) const
Definition: table_id.h:60
Table_id(unsigned long long id)
Definition: table_id.h:49
bool is_valid() const
Definition: table_id.h:52
static const unsigned long long TABLE_ID_MAX
Definition: table_id.h:44
Table_id()
Definition: table_id.h:48
uint64_t m_id
Definition: table_id.h:45
Table_id operator++(int)
Definition: table_id.h:65
Table_id & operator=(unsigned long long id)
Definition: table_id.h:54
unsigned long long id() const
Definition: table_id.h:51
bool operator==(const Table_id &tid) const
Definition: table_id.h:59
The namespace contains classes representing events that can occur in a replication stream.
Definition: binlog_event.cpp:35
Contains wrapper functions for memory allocation and deallocation.
#define BAPI_ASSERT(x)
Definition: wrapper_functions.h:60