1/*****************************************************************************
2
3Copyright (c) 1996, 2018, Oracle and/or its affiliates. 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, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
24
25*****************************************************************************/
26
27/** @file include/dict0boot.ic
28 Data dictionary creation and booting
29
30 Created 4/18/1996 Heikki Tuuri
31 *******************************************************/
32
33/** Returns a new row id.
34 @return the new id */
35UNIV_INLINE
36row_id_t dict_sys_get_new_row_id(void) {
37  row_id_t id;
38
39  mutex_enter(&dict_sys->mutex);
40
41  id = dict_sys->row_id;
42
43  if (0 == (id % DICT_HDR_ROW_ID_WRITE_MARGIN)) {
44    dict_hdr_flush_row_id();
45  }
46
47  dict_sys->row_id++;
48
49  mutex_exit(&dict_sys->mutex);
50
51  return (id);
52}
53
54/** Reads a row id from a record or other 6-byte stored form.
55 @return row id */
56UNIV_INLINE
57row_id_t dict_sys_read_row_id(const byte *field) /*!< in: record field */
58{
59#if DATA_ROW_ID_LEN != 6
60#error "DATA_ROW_ID_LEN != 6"
61#endif
62
63  return (mach_read_from_6(field));
64}
65
66/** Writes a row id to a record or other 6-byte stored form. */
67UNIV_INLINE
68void dict_sys_write_row_id(byte *field,     /*!< in: record field */
69                           row_id_t row_id) /*!< in: row id */
70{
71#if DATA_ROW_ID_LEN != 6
72#error "DATA_ROW_ID_LEN != 6"
73#endif
74
75  mach_write_to_6(field, row_id);
76}
77
78/** Check if a table id belongs to old innodb internal system table.
79@param[in]	id		table id
80@return true if the table id belongs to a system table. */
81UNIV_INLINE
82bool dict_is_old_sys_table(table_id_t id) {
83  if (srv_is_upgrade_mode) {
84    return (id < DICT_HDR_FIRST_ID);
85  }
86  return (false);
87}
88