MySQL 8.0.37
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 TABLE_ID_INCLUDED
30#define TABLE_ID_INCLUDED
31#include <stdint.h>
32#include "wrapper_functions.h"
33
34/**
35 @class Table_id
36
37 @brief Each table share has a table id, it is mainly used for row based
38 replication. Meanwhile it is used as table's version too.
39*/
40class Table_id {
41 private:
42 /* In table map event and rows events, table id is 6 bytes.*/
43 static const unsigned long long TABLE_ID_MAX = (~0ULL >> 16);
44 uint64_t m_id;
45
46 public:
47 Table_id() : m_id(0) {}
48 explicit Table_id(unsigned long long id) : m_id(id) {}
49
50 unsigned long long id() const { return m_id; }
51 bool is_valid() const { return m_id <= TABLE_ID_MAX; }
52
53 Table_id &operator=(unsigned long long id) {
54 m_id = id;
55 return *this;
56 }
57
58 bool operator==(const Table_id &tid) const { return m_id == tid.m_id; }
59 bool operator!=(const Table_id &tid) const { return m_id != tid.m_id; }
60
61 /* Support implicit type converting from Table_id to unsigned long long */
62 operator unsigned long long() const { return m_id; }
63
66
67 /* m_id is reset to 0, when it exceeds the max value. */
68 m_id = (m_id == TABLE_ID_MAX ? 0 : m_id + 1);
69
71 return id;
72 }
73};
74
75#endif
Each table share has a table id, it is mainly used for row based replication.
Definition: table_id.h:40
static const unsigned long long TABLE_ID_MAX
Definition: table_id.h:43
Table_id(unsigned long long id)
Definition: table_id.h:48
bool operator==(const Table_id &tid) const
Definition: table_id.h:58
uint64_t m_id
Definition: table_id.h:44
bool operator!=(const Table_id &tid) const
Definition: table_id.h:59
bool is_valid() const
Definition: table_id.h:51
unsigned long long id() const
Definition: table_id.h:50
Table_id & operator=(unsigned long long id)
Definition: table_id.h:53
Table_id operator++(int)
Definition: table_id.h:64
Table_id()
Definition: table_id.h:47
Contains wrapper functions for memory allocation and deallocation.
#define BAPI_ASSERT(x)
Definition: wrapper_functions.h:62