1/*****************************************************************************
2
3Copyright (c) 2011, 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/row0log.ic
28 Modification log for online index creation and online table rebuild
29
30 Created 2012-10-18 Marko Makela
31 *******************************************************/
32
33#include "dict0dict.h"
34
35#ifndef UNIV_HOTBACKUP
36/** Free the row log for an index on which online creation was aborted. */
37UNIV_INLINE
38void row_log_abort_sec(dict_index_t *index) /*!< in/out: index (x-latched) */
39{
40  ut_ad(rw_lock_own(dict_index_get_lock(index), RW_LOCK_X));
41
42  ut_ad(!index->is_clustered());
43  dict_index_set_online_status(index, ONLINE_INDEX_ABORTED);
44  row_log_free(index->online_log);
45}
46
47/** Try to log an operation to a secondary index that is
48 (or was) being created.
49 @retval true if the operation was logged or can be ignored
50 @retval false if online index creation is not taking place */
51UNIV_INLINE
52bool row_log_online_op_try(
53    dict_index_t *index,   /*!< in/out: index, S or X latched */
54    const dtuple_t *tuple, /*!< in: index tuple */
55    trx_id_t trx_id)       /*!< in: transaction ID for insert,
56                           or 0 for delete */
57{
58  ut_ad(rw_lock_own_flagged(dict_index_get_lock(index),
59                            RW_LOCK_FLAG_S | RW_LOCK_FLAG_X | RW_LOCK_FLAG_SX));
60
61  switch (dict_index_get_online_status(index)) {
62    case ONLINE_INDEX_COMPLETE:
63      /* This is a normal index. Do not log anything.
64      The caller must perform the operation on the
65      index tree directly. */
66      return (false);
67    case ONLINE_INDEX_CREATION:
68      /* The index is being created online. Log the
69      operation. */
70      row_log_online_op(index, tuple, trx_id);
71      break;
72    case ONLINE_INDEX_ABORTED:
73    case ONLINE_INDEX_ABORTED_DROPPED:
74      /* The index was created online, but the operation was
75      aborted. Do not log the operation and tell the caller
76      to skip the operation. */
77      break;
78  }
79
80  return (true);
81}
82#endif /* !UNIV_HOTBACKUP */
83