mariadb/storage/maria/ma_loghandler_lsn.h
Guilhem Bichot 60b88ce475 Fix for BUG#37876 "Importing Maria table from other server via binary copy does not work":
- after auto-zerofill (ha_maria::check_and_repair()) kepts its state's LSNs unchanged, which could
be the same as the create_rename_lsn of another pre-existing table, which would break versioning as this LSN
serves as unique identifier in the versioning code (in maria_open()). Even the state pieces which
maria_zerofill() did change were lost (because they didn't go to disk).
- after this fix, if two tables were auto-zerofilled at the same time (by _ma_mark_changed())
they could receive the same create_rename_lsn, which would break versioning again. Fix is to write a log
record each time a table is imported.
- Print state's LSNs (create_rename_lsn, is_of_horizon, skip_redo_lsn) and UUID in maria_chk -dvv.

mysql-test/r/maria-autozerofill.result:
  result
mysql-test/t/maria-autozerofill.test:
  Test for auto-zerofilling
storage/maria/ha_maria.cc:
  The state changes done by auto-zerofilling never reached disk.
storage/maria/ma_check.c:
  When zerofilling a table, including its pages' LSNs, new state LSNs are needed next time the table
  is imported into a Maria instance.
storage/maria/ma_create.c:
  Write LOGREC_IMPORTED_TABLE when importing a table. This is informative and ensures
  that the table gets a unique create_rename_lsn even though multiple tables
  are imported by concurrent threads (it advances the log's end LSN).
storage/maria/ma_key_recover.c:
  comment
storage/maria/ma_locking.c:
  instead of using translog_get_horizon() for state's LSNs of imported table,
  use the LSN of to-be-written LOGREC_IMPORTED_TABLE.
storage/maria/ma_loghandler.c:
  New type of log record
storage/maria/ma_loghandler.h:
  New type of log record
storage/maria/ma_loghandler_lsn.h:
  New name for constant as can be used not only by maria_chk but auto-zerofill now too.
storage/maria/ma_open.c:
  instead of using translog_get_horizon() for state's LSNs of imported table,
  use the LSN of to-be-written LOGREC_IMPORTED_TABLE.
storage/maria/ma_recovery.c:
  print content of LOGREC_IMPORTED_TABLE in maria_read_log.
storage/maria/maria_chk.c:
  print info about LSNs of the table's state, and UUID, when maria_chk -dvv
storage/maria/maria_pack.c:
  new name for constant
storage/maria/unittest/ma_test_recovery.pl:
  Now that maria_chk -dvv shows state LSNs and UUID those need to be filtered out,
  as maria_read_log -a does not use the same as at original run.
2008-07-09 11:02:27 +02:00

111 lines
3.5 KiB
C

/* Copyright (C) 2007 MySQL AB & Sanja Belkin
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef _ma_loghandler_lsn_h
#define _ma_loghandler_lsn_h
/*
Transaction log record address:
file_no << 32 | offset
file_no is only 3 bytes so we can use signed integer to make
comparison simpler.
*/
typedef int64 TRANSLOG_ADDRESS;
/*
Compare addresses
A1 > A2 -> result > 0
A1 == A2 -> 0
A1 < A2 -> result < 0
*/
#define cmp_translog_addr(A1,A2) ((A1) - (A2))
/*
TRANSLOG_ADDRESS is just address of some byte in the log (usually some
chunk)
LSN used where address of some record in the log needed (not just any
address)
*/
typedef TRANSLOG_ADDRESS LSN;
/* Gets file number part of a LSN/log address */
#define LSN_FILE_NO(L) (uint32) ((L) >> 32)
/* Gets raw file number part of a LSN/log address */
#define LSN_FILE_NO_PART(L) ((L) & ((int64)0xFFFFFF00000000LL))
/* Parts of LSN for printing */
#define LSN_IN_PARTS(L) (ulong)LSN_FILE_NO(L),(ulong)LSN_OFFSET(L)
/* Gets record offset of a LSN/log address */
#define LSN_OFFSET(L) (ulong) ((L) & 0xFFFFFFFFL)
/* Makes lsn/log address from file number and record offset */
#define MAKE_LSN(F,S) ((LSN) ((((uint64)(F)) << 32) | (S)))
/* checks LSN */
#define LSN_VALID(L) \
((LSN_FILE_NO_PART(L) != FILENO_IMPOSSIBLE) && \
(LSN_OFFSET(L) != LOG_OFFSET_IMPOSSIBLE))
/* size of stored LSN on a disk, don't change it! */
#define LSN_STORE_SIZE 7
/* Puts LSN into buffer (dst) */
#define lsn_store(dst, lsn) \
do { \
int3store((dst), LSN_FILE_NO(lsn)); \
int4store((char*)(dst) + 3, LSN_OFFSET(lsn)); \
} while (0)
/* Unpacks LSN from the buffer (P) */
#define lsn_korr(P) MAKE_LSN(uint3korr(P), uint4korr((const char*)(P) + 3))
/* what we need to add to LSN to increase it on one file */
#define LSN_ONE_FILE ((int64)0x100000000LL)
#define LSN_REPLACE_OFFSET(L, S) (LSN_FILE_NO_PART(L) | (S))
/*
an 8-byte type whose most significant uchar is used for "flags"; 7
other bytes are a LSN.
*/
typedef LSN LSN_WITH_FLAGS;
#define LSN_WITH_FLAGS_TO_LSN(x) (x & ULL(0x00FFFFFFFFFFFFFF))
#define LSN_WITH_FLAGS_TO_FLAGS(x) (x & ULL(0xFF00000000000000))
#define FILENO_IMPOSSIBLE 0 /**< log file's numbering starts at 1 */
#define LOG_OFFSET_IMPOSSIBLE 0 /**< log always has a header */
#define LSN_IMPOSSIBLE ((LSN)0)
/* following LSN also is impossible */
#define LSN_ERROR ((LSN)1)
/** @brief some impossible LSN serve as markers */
/**
When table is modified by maria_chk, or auto-zerofilled, old REDOs don't
apply, table is freshly born again somehow: its state's LSNs need to be
updated to the new instance which receives this table.
*/
#define LSN_NEEDS_NEW_STATE_LSNS ((LSN)2)
/**
@brief the maximum valid LSN.
Unlike ULONGLONG_MAX, it can be safely used in comparison with valid LSNs
(ULONGLONG_MAX is too big for correctness of cmp_translog_addr()).
*/
#define LSN_MAX (LSN)ULL(0x00FFFFFFFFFFFFFF)
#endif