1/*****************************************************************************
2
3Copyright (c) 1996, 2019, 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/trx0rec.ic
28 Transaction undo log record
29
30 Created 3/26/1996 Heikki Tuuri
31 *******************************************************/
32
33#ifndef UNIV_HOTBACKUP
34/** Reads from an undo log record the record type.
35 @return record type */
36UNIV_INLINE
37ulint trx_undo_rec_get_type(
38    const trx_undo_rec_t *undo_rec) /*!< in: undo log record */
39{
40  return (mach_read_from_1(undo_rec + 2) & (TRX_UNDO_CMPL_INFO_MULT - 1));
41}
42
43/** Reads from an undo log record the record compiler info.
44 @return compiler info */
45UNIV_INLINE
46ulint trx_undo_rec_get_cmpl_info(
47    const trx_undo_rec_t *undo_rec) /*!< in: undo log record */
48{
49  return (mach_read_from_1(undo_rec + 2) / TRX_UNDO_CMPL_INFO_MULT);
50}
51
52/** Returns TRUE if an undo log record contains an extern storage field.
53 @return true if extern */
54UNIV_INLINE
55ibool trx_undo_rec_get_extern_storage(
56    const trx_undo_rec_t *undo_rec) /*!< in: undo log record */
57{
58  if (mach_read_from_1(undo_rec + 2) & TRX_UNDO_UPD_EXTERN) {
59    return (TRUE);
60  }
61
62  return (FALSE);
63}
64
65/** Reads the undo log record number.
66 @return undo no */
67UNIV_INLINE
68undo_no_t trx_undo_rec_get_undo_no(
69    const trx_undo_rec_t *undo_rec) /*!< in: undo log record */
70{
71  const byte *ptr = undo_rec + 2;
72  uint8_t type_cmpl = mach_read_from_1(ptr);
73
74  const bool blob_undo = type_cmpl & TRX_UNDO_MODIFY_BLOB;
75
76  if (blob_undo) {
77    /* The next record offset takes 2 bytes + 1 byte for
78    type_cmpl flag + 1 byte for the new flag.  Total 4 bytes.*/
79    ptr = undo_rec + 4;
80  } else {
81    ptr = undo_rec + 3;
82  }
83  return (mach_u64_read_much_compressed(ptr));
84}
85
86UNIV_INLINE
87trx_undo_rec_t *trx_undo_rec_copy(const page_t *undo_page, uint32_t undo_offset,
88                                  mem_heap_t *heap) {
89  ut_ad(undo_offset < UNIV_PAGE_SIZE);
90  trx_undo_rec_t *undo_rec = (trx_undo_rec_t *)(undo_page + undo_offset);
91
92  /* Read the offset of next undo record from the current undo record
93  and subtract it from current undo log record offset to get the length
94  of undo record */
95  uint32_t next_undo_offset = mach_read_from_2(undo_rec);
96  ut_a(next_undo_offset > undo_offset);
97
98  uint32_t len = next_undo_offset - undo_offset;
99  ut_ad(len < UNIV_PAGE_SIZE);
100  return ((trx_undo_rec_t *)mem_heap_dup(heap, undo_rec, len));
101}
102#endif /* !UNIV_HOTBACKUP */
103