1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/******************************************************
Data dictionary creation and booting
(c) 1996 Innobase Oy
Created 4/18/1996 Heikki Tuuri
*******************************************************/
/**************************************************************************
Writes the current value of the row id counter to the dictionary header file
page. */
void
dict_hdr_flush_row_id(void);
/*=======================*/
/**************************************************************************
Gets a pointer to the dictionary header and x-latches its page. */
UNIV_INLINE
dict_hdr_t*
dict_hdr_get(
/*=========*/
/* out: pointer to the dictionary header,
page x-latched */
mtr_t* mtr) /* in: mtr */
{
dict_hdr_t* header;
ut_ad(mtr);
header = DICT_HDR + buf_page_get(DICT_HDR_SPACE, DICT_HDR_PAGE_NO,
RW_X_LATCH, mtr);
buf_page_dbg_add_level(header, SYNC_DICT_HEADER);
return(header);
}
/**************************************************************************
Returns a new table, index, or tree id. */
UNIV_INLINE
dulint
dict_hdr_get_new_id(
/*================*/
/* out: the new id */
ulint type) /* in: DICT_HDR_ROW_ID, ... */
{
dict_hdr_t* dict_hdr;
dulint id;
mtr_t mtr;
ut_ad((type == DICT_HDR_TABLE_ID) || (type == DICT_HDR_INDEX_ID)
|| (type == DICT_HDR_MIX_ID));
mtr_start(&mtr);
dict_hdr = dict_hdr_get(&mtr);
id = mtr_read_dulint(dict_hdr + type, MLOG_8BYTES, &mtr);
id = ut_dulint_add(id, 1);
mlog_write_dulint(dict_hdr + type, id, MLOG_8BYTES, &mtr);
mtr_commit(&mtr);
return(id);
}
/**************************************************************************
Returns a new row id. */
UNIV_INLINE
dulint
dict_sys_get_new_row_id(void)
/*=========================*/
/* out: the new id */
{
dulint id;
mutex_enter(&(dict_sys->mutex));
id = dict_sys->row_id;
if (0 == (ut_dulint_get_low(id) % DICT_HDR_ROW_ID_WRITE_MARGIN)) {
dict_hdr_flush_row_id();
}
UT_DULINT_INC(dict_sys->row_id);
mutex_exit(&(dict_sys->mutex));
return(id);
}
/**************************************************************************
Reads a row id from a record or other 6-byte stored form. */
UNIV_INLINE
dulint
dict_sys_read_row_id(
/*=================*/
/* out: row id */
byte* field) /* in: record field */
{
ut_ad(DATA_ROW_ID_LEN == 6);
return(mach_read_from_6(field));
}
/**************************************************************************
Writes a row id to a record or other 6-byte stored form. */
UNIV_INLINE
void
dict_sys_write_row_id(
/*==================*/
byte* field, /* in: record field */
dulint row_id) /* in: row id */
{
ut_ad(DATA_ROW_ID_LEN == 6);
mach_write_to_6(field, row_id);
}
|