2009-02-17 10:01:41 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
|
|
|
Copyright (c) 2005, 2009, Innobase Oy. All Rights Reserved.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
/******************************************************
|
|
|
|
Compressed page interface
|
|
|
|
|
|
|
|
Created June 2005 by Marko Makela
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#define THIS_MODULE
|
|
|
|
#include "page0zip.h"
|
|
|
|
#ifdef UNIV_NONINL
|
|
|
|
# include "page0zip.ic"
|
|
|
|
#endif
|
|
|
|
#undef THIS_MODULE
|
|
|
|
#include "page0page.h"
|
|
|
|
#include "mtr0log.h"
|
2005-11-24 14:13:10 +00:00
|
|
|
#include "ut0sort.h"
|
2006-03-09 17:26:02 +00:00
|
|
|
#include "dict0dict.h"
|
2006-02-10 15:06:17 +00:00
|
|
|
#include "btr0cur.h"
|
|
|
|
#include "page0types.h"
|
2006-04-07 11:04:08 +00:00
|
|
|
#include "log0recv.h"
|
2005-10-27 11:48:10 +00:00
|
|
|
#include "zlib.h"
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
|
|
# include "buf0lru.h"
|
|
|
|
# include "btr0sea.h"
|
|
|
|
# include "dict0boot.h"
|
|
|
|
# include "lock0lock.h"
|
|
|
|
#else /* !UNIV_HOTBACKUP */
|
|
|
|
# define lock_move_reorganize_page(block, temp_block) ((void) 0)
|
|
|
|
# define buf_LRU_stat_inc_unzip() ((void) 0)
|
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2005-10-27 11:48:10 +00:00
|
|
|
|
branches/zip: Rename the INFORMATION_SCHEMA tables
INNODB_ZIP and INNODB_ZIP_RESET to
INNODB_COMPRESSION and INNODB_COMPRESSION_RESET,
and remove the statistics of the buddy system.
This change was discussed with Ken. It makes the tables shorter
and easier to understand. The removed data will be represented in
the tables INNODB_COMPRESSION_BUDDY and INNODB_COMPRESSION_BUDDY_RESET
that will be added later.
i_s_innodb_zip, i_s_innodb_zip_reset, i_s_zip_fields_info[],
i_s_zip_fill_low(), i_s_zip_fill(), i_s_zip_reset_fill(),
i_s_zip_init(), i_s_zip_reset_init(): Replace "zip" with "compression".
i_s_compression_fields_info[]: Remove "used", "free",
"relocated", "relocated_usec". In "compressed_usec" and "decompressed_usec",
replace microseconds with seconds ("usec" with "sec").
page_zip_decompress(): Correct a typo in the function comment.
PAGE_ZIP_SSIZE_BITS, PAGE_ZIP_NUM_SSIZE: New constants.
page_zip_stat_t, page_zip_stat: Statistics of the compression, grouped
by page size.
page_zip_simple_validate(): Assert that page_zip->ssize is reasonable.
2008-03-28 09:28:54 +00:00
|
|
|
/** Statistics on compression, indexed by page_zip_des_t::ssize - 1 */
|
|
|
|
UNIV_INTERN page_zip_stat_t page_zip_stat[PAGE_ZIP_NUM_SSIZE - 1];
|
2007-04-10 08:11:49 +00:00
|
|
|
|
2005-11-25 12:34:38 +00:00
|
|
|
/* Please refer to ../include/page0zip.ic for a description of the
|
|
|
|
compressed page format. */
|
|
|
|
|
2005-11-24 14:13:10 +00:00
|
|
|
/* The infimum and supremum records are omitted from the compressed page.
|
|
|
|
On compress, we compare that the records are there, and on uncompress we
|
|
|
|
restore the records. */
|
|
|
|
static const byte infimum_extra[] = {
|
|
|
|
0x01, /* info_bits=0, n_owned=1 */
|
|
|
|
0x00, 0x02 /* heap_no=0, status=2 */
|
|
|
|
/* ?, ? */ /* next=(first user rec, or supremum) */
|
|
|
|
};
|
|
|
|
static const byte infimum_data[] = {
|
|
|
|
0x69, 0x6e, 0x66, 0x69,
|
|
|
|
0x6d, 0x75, 0x6d, 0x00 /* "infimum\0" */
|
|
|
|
};
|
|
|
|
static const byte supremum_extra_data[] = {
|
|
|
|
/* 0x0?, */ /* info_bits=0, n_owned=1..8 */
|
|
|
|
0x00, 0x0b, /* heap_no=1, status=3 */
|
|
|
|
0x00, 0x00, /* next=0 */
|
|
|
|
0x73, 0x75, 0x70, 0x72,
|
|
|
|
0x65, 0x6d, 0x75, 0x6d /* "supremum" */
|
|
|
|
};
|
|
|
|
|
2007-12-13 13:04:47 +00:00
|
|
|
/** Assert that a block of memory is filled with zero bytes.
|
|
|
|
Compare at most sizeof(field_ref_zero) bytes. */
|
2007-12-13 10:57:30 +00:00
|
|
|
#define ASSERT_ZERO(b, s) \
|
|
|
|
ut_ad(!memcmp(b, field_ref_zero, ut_min(s, sizeof field_ref_zero)))
|
|
|
|
/** Assert that a BLOB pointer is filled with zero bytes. */
|
|
|
|
#define ASSERT_ZERO_BLOB(b) \
|
|
|
|
ut_ad(!memcmp(b, field_ref_zero, sizeof field_ref_zero))
|
2006-03-17 14:11:57 +00:00
|
|
|
|
2007-11-15 10:56:34 +00:00
|
|
|
/* Enable some extra debugging output. This code can be enabled
|
|
|
|
independently of any UNIV_ debugging conditions. */
|
|
|
|
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
|
|
|
|
# include <stdarg.h>
|
|
|
|
__attribute__((format (printf, 1, 2)))
|
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Report a failure to decompress or compress.
|
|
|
|
@return number of characters printed */
|
2007-11-15 10:56:34 +00:00
|
|
|
static
|
|
|
|
int
|
|
|
|
page_zip_fail_func(
|
|
|
|
/*===============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const char* fmt, /*!< in: printf(3) format string */
|
|
|
|
...) /*!< in: arguments corresponding to fmt */
|
2007-11-15 10:56:34 +00:00
|
|
|
{
|
|
|
|
int res;
|
|
|
|
va_list ap;
|
|
|
|
|
2008-10-06 12:26:27 +00:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fputs(" InnoDB: ", stderr);
|
2007-11-15 10:56:34 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
res = vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return(res);
|
|
|
|
}
|
|
|
|
# define page_zip_fail(fmt_args) page_zip_fail_func fmt_args
|
|
|
|
#else /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
|
|
|
|
# define page_zip_fail(fmt_args) /* empty */
|
|
|
|
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
|
|
|
|
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2006-09-20 14:26:53 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Determine the guaranteed free space on an empty page.
|
|
|
|
@return minimum payload size on the page */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-09-20 14:26:53 +00:00
|
|
|
ulint
|
|
|
|
page_zip_empty_size(
|
|
|
|
/*================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint n_fields, /*!< in: number of columns in the index */
|
|
|
|
ulint zip_size) /*!< in: compressed page size in bytes */
|
2006-09-20 14:26:53 +00:00
|
|
|
{
|
|
|
|
lint size = zip_size
|
|
|
|
/* subtract the page header and the longest
|
|
|
|
uncompressed data needed for one record */
|
|
|
|
- (PAGE_DATA
|
|
|
|
+ PAGE_ZIP_DIR_SLOT_SIZE
|
|
|
|
+ DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN
|
|
|
|
+ 1/* encoded heap_no==2 in page_zip_write_rec() */
|
|
|
|
+ 1/* end of modification log */
|
|
|
|
- REC_N_NEW_EXTRA_BYTES/* omitted bytes */)
|
|
|
|
/* subtract the space for page_zip_fields_encode() */
|
|
|
|
- compressBound(2 * (n_fields + 1));
|
|
|
|
return(size > 0 ? (ulint) size : 0);
|
|
|
|
}
|
2009-03-23 14:21:34 +00:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2006-09-20 14:26:53 +00:00
|
|
|
|
2006-03-01 11:38:25 +00:00
|
|
|
/*****************************************************************
|
|
|
|
Gets the size of the compressed page trailer (the dense page directory),
|
2009-05-25 05:30:14 +00:00
|
|
|
including deleted records (the free list).
|
|
|
|
@return length of dense page directory, in bytes */
|
2006-03-01 11:38:25 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
page_zip_dir_size(
|
|
|
|
/*==============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_zip_des_t* page_zip) /*!< in: compressed page */
|
2006-03-01 11:38:25 +00:00
|
|
|
{
|
|
|
|
/* Exclude the page infimum and supremum from the record count. */
|
|
|
|
ulint size = PAGE_ZIP_DIR_SLOT_SIZE
|
2006-10-20 12:45:53 +00:00
|
|
|
* (page_dir_get_n_heap(page_zip->data)
|
|
|
|
- PAGE_HEAP_NO_USER_LOW);
|
2006-03-01 11:38:25 +00:00
|
|
|
return(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
Gets the size of the compressed page trailer (the dense page directory),
|
2009-05-25 05:30:14 +00:00
|
|
|
only including user records (excluding the free list).
|
|
|
|
@return length of dense page directory comprising existing records, in bytes */
|
2006-03-01 11:38:25 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
page_zip_dir_user_size(
|
|
|
|
/*===================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_zip_des_t* page_zip) /*!< in: compressed page */
|
2006-03-01 11:38:25 +00:00
|
|
|
{
|
|
|
|
ulint size = PAGE_ZIP_DIR_SLOT_SIZE
|
2006-10-19 07:52:28 +00:00
|
|
|
* page_get_n_recs(page_zip->data);
|
2006-03-06 21:00:05 +00:00
|
|
|
ut_ad(size <= page_zip_dir_size(page_zip));
|
2006-03-01 11:38:25 +00:00
|
|
|
return(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Find the slot of the given record in the dense page directory.
|
|
|
|
@return dense directory slot, or NULL if record not found */
|
2006-03-01 11:38:25 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
byte*
|
2006-08-22 08:34:14 +00:00
|
|
|
page_zip_dir_find_low(
|
|
|
|
/*==================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
byte* slot, /*!< in: start of records */
|
|
|
|
byte* end, /*!< in: end of records */
|
|
|
|
ulint offset) /*!< in: offset of user record */
|
2006-03-01 11:38:25 +00:00
|
|
|
{
|
2006-08-22 08:34:14 +00:00
|
|
|
ut_ad(slot <= end);
|
2006-03-01 11:38:25 +00:00
|
|
|
|
|
|
|
for (; slot < end; slot += PAGE_ZIP_DIR_SLOT_SIZE) {
|
|
|
|
if ((mach_read_from_2(slot) & PAGE_ZIP_DIR_SLOT_MASK)
|
2006-08-29 09:30:31 +00:00
|
|
|
== offset) {
|
2006-03-01 11:38:25 +00:00
|
|
|
return(slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Find the slot of the given non-free record in the dense page directory.
|
|
|
|
@return dense directory slot, or NULL if record not found */
|
2006-03-01 11:38:25 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
byte*
|
2006-08-22 08:34:14 +00:00
|
|
|
page_zip_dir_find(
|
|
|
|
/*==============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip, /*!< in: compressed page */
|
|
|
|
ulint offset) /*!< in: offset of user record */
|
2006-03-01 11:38:25 +00:00
|
|
|
{
|
2006-11-27 13:44:32 +00:00
|
|
|
byte* end = page_zip->data + page_zip_get_size(page_zip);
|
2006-03-01 11:38:25 +00:00
|
|
|
|
2006-08-22 08:34:14 +00:00
|
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
2006-03-01 11:38:25 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
return(page_zip_dir_find_low(end - page_zip_dir_user_size(page_zip),
|
|
|
|
end,
|
|
|
|
offset));
|
2006-03-01 11:38:25 +00:00
|
|
|
}
|
|
|
|
|
2006-03-29 14:08:57 +00:00
|
|
|
/*****************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Find the slot of the given free record in the dense page directory.
|
|
|
|
@return dense directory slot, or NULL if record not found */
|
2006-03-29 14:08:57 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
byte*
|
|
|
|
page_zip_dir_find_free(
|
|
|
|
/*===================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip, /*!< in: compressed page */
|
|
|
|
ulint offset) /*!< in: offset of user record */
|
2006-03-29 14:08:57 +00:00
|
|
|
{
|
2006-11-27 13:44:32 +00:00
|
|
|
byte* end = page_zip->data + page_zip_get_size(page_zip);
|
2006-03-29 14:08:57 +00:00
|
|
|
|
|
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
return(page_zip_dir_find_low(end - page_zip_dir_size(page_zip),
|
|
|
|
end - page_zip_dir_user_size(page_zip),
|
|
|
|
offset));
|
2006-03-29 14:08:57 +00:00
|
|
|
}
|
|
|
|
|
2006-03-01 11:38:25 +00:00
|
|
|
/*****************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Read a given slot in the dense page directory.
|
|
|
|
@return record offset on the uncompressed page, possibly ORed with PAGE_ZIP_DIR_SLOT_DEL or PAGE_ZIP_DIR_SLOT_OWNED */
|
2006-03-01 11:38:25 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
page_zip_dir_get(
|
|
|
|
/*=============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_zip_des_t* page_zip, /*!< in: compressed page */
|
|
|
|
ulint slot) /*!< in: slot
|
2006-03-01 11:38:25 +00:00
|
|
|
(0=first user record) */
|
|
|
|
{
|
|
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
|
|
|
ut_ad(slot < page_zip_dir_size(page_zip) / PAGE_ZIP_DIR_SLOT_SIZE);
|
2006-11-27 13:44:32 +00:00
|
|
|
return(mach_read_from_2(page_zip->data + page_zip_get_size(page_zip)
|
2006-08-29 09:30:31 +00:00
|
|
|
- PAGE_ZIP_DIR_SLOT_SIZE * (slot + 1)));
|
2006-03-01 11:38:25 +00:00
|
|
|
}
|
|
|
|
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2006-05-16 14:17:43 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Write a log record of compressing an index page. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
page_zip_compress_write_log(
|
|
|
|
/*========================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_zip_des_t* page_zip,/*!< in: compressed page */
|
|
|
|
const page_t* page, /*!< in: uncompressed page */
|
|
|
|
dict_index_t* index, /*!< in: index of the B-tree node */
|
|
|
|
mtr_t* mtr) /*!< in: mini-transaction */
|
2006-05-16 14:17:43 +00:00
|
|
|
{
|
|
|
|
byte* log_ptr;
|
|
|
|
ulint trailer_size;
|
|
|
|
|
branches/zip: Write PAGE_MAX_TRX_ID to the redo log. Otherwise,
transactions that are started before the rollback of incomplete
transactions has finished may have an inconsistent view of the
secondary indexes.
dict_index_is_sec_or_ibuf(): Auxiliary function for controlling
updates and checks of PAGE_MAX_TRX_ID: check whether an index is a
secondary index or the insert buffer tree.
page_set_max_trx_id(), page_update_max_trx_id(),
lock_rec_insert_check_and_lock(),
lock_sec_rec_modify_check_and_lock(), btr_cur_ins_lock_and_undo(),
btr_cur_upd_lock_and_undo(): Add the parameter mtr.
page_set_max_trx_id(): Allow mtr to be NULL. When mtr==NULL, do not
attempt to write to the redo log. This only occurs when creating a
page or reorganizing a compressed page. In these cases, the
PAGE_MAX_TRX_ID will be set correctly during the application of redo
log records, even though there is no explicit log record about it.
btr_discard_only_page_on_level(): Preserve PAGE_MAX_TRX_ID. This
function should be unreachable, though.
btr_cur_pessimistic_update(): Update PAGE_MAX_TRX_ID.
Add some assertions for checking that PAGE_MAX_TRX_ID is set on all
secondary index leaf pages.
rb://115 tested by Michael, fixes Issue #211
2009-05-19 18:59:07 +00:00
|
|
|
ut_ad(!dict_index_is_ibuf(index));
|
|
|
|
|
2006-05-16 14:17:43 +00:00
|
|
|
log_ptr = mlog_open(mtr, 11 + 2 + 2);
|
|
|
|
|
|
|
|
if (!log_ptr) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
/* Read the number of user records. */
|
|
|
|
trailer_size = page_dir_get_n_heap(page_zip->data)
|
|
|
|
- PAGE_HEAP_NO_USER_LOW;
|
2006-05-16 14:17:43 +00:00
|
|
|
/* Multiply by uncompressed of size stored per record */
|
2006-05-30 09:04:57 +00:00
|
|
|
if (!page_is_leaf(page)) {
|
2006-05-16 14:17:43 +00:00
|
|
|
trailer_size *= PAGE_ZIP_DIR_SLOT_SIZE + REC_NODE_PTR_SIZE;
|
2006-05-30 09:04:57 +00:00
|
|
|
} else if (dict_index_is_clust(index)) {
|
|
|
|
trailer_size *= PAGE_ZIP_DIR_SLOT_SIZE
|
2006-08-29 09:30:31 +00:00
|
|
|
+ DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN;
|
2006-05-30 09:04:57 +00:00
|
|
|
} else {
|
|
|
|
trailer_size *= PAGE_ZIP_DIR_SLOT_SIZE;
|
2006-05-16 14:17:43 +00:00
|
|
|
}
|
|
|
|
/* Add the space occupied by BLOB pointers. */
|
|
|
|
trailer_size += page_zip->n_blobs * BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
ut_a(page_zip->m_end > PAGE_DATA);
|
|
|
|
#if FIL_PAGE_DATA > PAGE_DATA
|
|
|
|
# error "FIL_PAGE_DATA > PAGE_DATA"
|
|
|
|
#endif
|
2006-11-27 13:44:32 +00:00
|
|
|
ut_a(page_zip->m_end + trailer_size <= page_zip_get_size(page_zip));
|
2006-05-16 14:17:43 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
log_ptr = mlog_write_initial_log_record_fast((page_t*) page,
|
|
|
|
MLOG_ZIP_PAGE_COMPRESS,
|
|
|
|
log_ptr, mtr);
|
2006-05-16 14:17:43 +00:00
|
|
|
mach_write_to_2(log_ptr, page_zip->m_end - FIL_PAGE_TYPE);
|
|
|
|
log_ptr += 2;
|
|
|
|
mach_write_to_2(log_ptr, trailer_size);
|
|
|
|
log_ptr += 2;
|
|
|
|
mlog_close(mtr, log_ptr);
|
|
|
|
|
|
|
|
/* Write FIL_PAGE_PREV and FIL_PAGE_NEXT */
|
|
|
|
mlog_catenate_string(mtr, page_zip->data + FIL_PAGE_PREV, 4);
|
|
|
|
mlog_catenate_string(mtr, page_zip->data + FIL_PAGE_NEXT, 4);
|
|
|
|
/* Write most of the page header, the compressed stream and
|
|
|
|
the modification log. */
|
|
|
|
mlog_catenate_string(mtr, page_zip->data + FIL_PAGE_TYPE,
|
2006-08-29 09:30:31 +00:00
|
|
|
page_zip->m_end - FIL_PAGE_TYPE);
|
2006-05-16 14:17:43 +00:00
|
|
|
/* Write the uncompressed trailer of the compressed page. */
|
2006-11-27 13:44:32 +00:00
|
|
|
mlog_catenate_string(mtr, page_zip->data + page_zip_get_size(page_zip)
|
2006-08-29 09:30:31 +00:00
|
|
|
- trailer_size, trailer_size);
|
2006-05-16 14:17:43 +00:00
|
|
|
}
|
2009-03-23 14:21:34 +00:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2006-05-16 14:17:43 +00:00
|
|
|
|
2006-03-13 15:02:16 +00:00
|
|
|
/**********************************************************
|
|
|
|
Determine how many externally stored columns are contained
|
2006-03-30 11:47:10 +00:00
|
|
|
in existing records with smaller heap_no than rec. */
|
2006-03-16 14:02:22 +00:00
|
|
|
static
|
2006-03-13 15:02:16 +00:00
|
|
|
ulint
|
|
|
|
page_zip_get_n_prev_extern(
|
|
|
|
/*=======================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_zip_des_t* page_zip,/*!< in: dense page directory on
|
2006-03-16 14:02:22 +00:00
|
|
|
compressed page */
|
2009-05-25 05:30:14 +00:00
|
|
|
const rec_t* rec, /*!< in: compact physical record
|
2006-03-16 14:02:22 +00:00
|
|
|
on a B-tree leaf page */
|
2009-05-25 05:30:14 +00:00
|
|
|
dict_index_t* index) /*!< in: record descriptor */
|
2006-03-13 15:02:16 +00:00
|
|
|
{
|
2007-10-03 12:22:29 +00:00
|
|
|
const page_t* page = page_align(rec);
|
2006-10-19 07:52:28 +00:00
|
|
|
ulint n_ext = 0;
|
|
|
|
ulint i;
|
|
|
|
ulint left;
|
|
|
|
ulint heap_no;
|
|
|
|
ulint n_recs = page_get_n_recs(page_zip->data);
|
2006-03-13 15:02:16 +00:00
|
|
|
|
|
|
|
ut_ad(page_is_leaf(page));
|
|
|
|
ut_ad(page_is_comp(page));
|
|
|
|
ut_ad(dict_table_is_comp(index->table));
|
2006-08-21 10:27:15 +00:00
|
|
|
ut_ad(dict_index_is_clust(index));
|
branches/zip: Write PAGE_MAX_TRX_ID to the redo log. Otherwise,
transactions that are started before the rollback of incomplete
transactions has finished may have an inconsistent view of the
secondary indexes.
dict_index_is_sec_or_ibuf(): Auxiliary function for controlling
updates and checks of PAGE_MAX_TRX_ID: check whether an index is a
secondary index or the insert buffer tree.
page_set_max_trx_id(), page_update_max_trx_id(),
lock_rec_insert_check_and_lock(),
lock_sec_rec_modify_check_and_lock(), btr_cur_ins_lock_and_undo(),
btr_cur_upd_lock_and_undo(): Add the parameter mtr.
page_set_max_trx_id(): Allow mtr to be NULL. When mtr==NULL, do not
attempt to write to the redo log. This only occurs when creating a
page or reorganizing a compressed page. In these cases, the
PAGE_MAX_TRX_ID will be set correctly during the application of redo
log records, even though there is no explicit log record about it.
btr_discard_only_page_on_level(): Preserve PAGE_MAX_TRX_ID. This
function should be unreachable, though.
btr_cur_pessimistic_update(): Update PAGE_MAX_TRX_ID.
Add some assertions for checking that PAGE_MAX_TRX_ID is set on all
secondary index leaf pages.
rb://115 tested by Michael, fixes Issue #211
2009-05-19 18:59:07 +00:00
|
|
|
ut_ad(!dict_index_is_ibuf(index));
|
2006-03-13 15:02:16 +00:00
|
|
|
|
2006-10-16 11:42:46 +00:00
|
|
|
heap_no = rec_get_heap_no_new(rec);
|
2006-10-20 12:45:53 +00:00
|
|
|
ut_ad(heap_no >= PAGE_HEAP_NO_USER_LOW);
|
|
|
|
left = heap_no - PAGE_HEAP_NO_USER_LOW;
|
2006-03-16 14:02:22 +00:00
|
|
|
if (UNIV_UNLIKELY(!left)) {
|
|
|
|
return(0);
|
|
|
|
}
|
2006-03-13 15:02:16 +00:00
|
|
|
|
2006-03-16 14:02:22 +00:00
|
|
|
for (i = 0; i < n_recs; i++) {
|
2006-10-19 07:52:28 +00:00
|
|
|
const rec_t* r = page + (page_zip_dir_get(page_zip, i)
|
|
|
|
& PAGE_ZIP_DIR_SLOT_MASK);
|
2006-03-13 15:02:16 +00:00
|
|
|
|
2006-03-16 14:02:22 +00:00
|
|
|
if (rec_get_heap_no_new(r) < heap_no) {
|
2006-09-19 10:14:07 +00:00
|
|
|
n_ext += rec_get_n_extern_new(r, index,
|
|
|
|
ULINT_UNDEFINED);
|
2006-03-16 14:02:22 +00:00
|
|
|
if (!--left) {
|
|
|
|
break;
|
|
|
|
}
|
2006-03-13 15:02:16 +00:00
|
|
|
}
|
2006-03-16 14:02:22 +00:00
|
|
|
}
|
2006-03-13 15:02:16 +00:00
|
|
|
|
2006-03-16 14:02:22 +00:00
|
|
|
return(n_ext);
|
2006-03-13 15:02:16 +00:00
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Encode the length of a fixed-length column.
|
|
|
|
@return buf + length of encoded val */
|
2006-02-10 15:06:17 +00:00
|
|
|
static
|
|
|
|
byte*
|
|
|
|
page_zip_fixed_field_encode(
|
|
|
|
/*========================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
byte* buf, /*!< in: pointer to buffer where to write */
|
|
|
|
ulint val) /*!< in: value to write */
|
2006-02-10 15:06:17 +00:00
|
|
|
{
|
|
|
|
ut_ad(val >= 2);
|
|
|
|
|
|
|
|
if (UNIV_LIKELY(val < 126)) {
|
|
|
|
/*
|
|
|
|
0 = nullable variable field of at most 255 bytes length;
|
|
|
|
1 = not null variable field of at most 255 bytes length;
|
|
|
|
126 = nullable variable field with maximum length >255;
|
|
|
|
127 = not null variable field with maximum length >255
|
|
|
|
*/
|
branches/zip: Fix most MSVC (Windows) compilation warnings.
lock_get_table(), locks_row_eq_lock(), buf_page_get_mutex(): Add return
after ut_error. On Windows, ut_error is not declared as "noreturn".
Add explicit type casts when assigning ulint to byte to get rid of
"possible loss of precision" warnings.
struct i_s_table_cache_struct: Declare rows_used, rows_allocd as ulint
instead of ullint. 32 bits should be enough.
fill_innodb_trx_from_cache(), i_s_zip_fill_low(): Cast 64-bit unsigned
integers to longlong when calling Field::store(longlong, bool is_unsigned).
Otherwise, the compiler would implicitly convert them to double and
invoke Field::store(double) instead.
recv_truncate_group(), recv_copy_group(), recv_calc_lsn_on_data_add():
Cast ib_uint64_t expressions to ulint to get rid of "possible loss of
precision" warnings. (There should not be any loss of precision in
these cases.)
log_close(), log_checkpoint_margin(): Declare some variables as ib_uint64_t
instead of ulint, so that there won't be any potential loss of precision.
mach_write_ull(): Cast the second argument of mach_write_to_4() to ulint.
OS_FILE_FROM_FD(): Cast the return value of _get_osfhandle() to HANDLE.
row_merge_dict_table_get_index(): Cast the parameter of mem_free() to (void*)
in order to get rid of the bogus MSVC warning C4090, which has been reported
as MSVC bug 101661:
<http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101661>
row_mysql_read_blob_ref(): To get rid of a bogus MSVC warning C4090,
drop a const qualifier.
2008-03-04 08:57:07 +00:00
|
|
|
*buf++ = (byte) val;
|
2006-02-10 15:06:17 +00:00
|
|
|
} else {
|
branches/zip: Fix most MSVC (Windows) compilation warnings.
lock_get_table(), locks_row_eq_lock(), buf_page_get_mutex(): Add return
after ut_error. On Windows, ut_error is not declared as "noreturn".
Add explicit type casts when assigning ulint to byte to get rid of
"possible loss of precision" warnings.
struct i_s_table_cache_struct: Declare rows_used, rows_allocd as ulint
instead of ullint. 32 bits should be enough.
fill_innodb_trx_from_cache(), i_s_zip_fill_low(): Cast 64-bit unsigned
integers to longlong when calling Field::store(longlong, bool is_unsigned).
Otherwise, the compiler would implicitly convert them to double and
invoke Field::store(double) instead.
recv_truncate_group(), recv_copy_group(), recv_calc_lsn_on_data_add():
Cast ib_uint64_t expressions to ulint to get rid of "possible loss of
precision" warnings. (There should not be any loss of precision in
these cases.)
log_close(), log_checkpoint_margin(): Declare some variables as ib_uint64_t
instead of ulint, so that there won't be any potential loss of precision.
mach_write_ull(): Cast the second argument of mach_write_to_4() to ulint.
OS_FILE_FROM_FD(): Cast the return value of _get_osfhandle() to HANDLE.
row_merge_dict_table_get_index(): Cast the parameter of mem_free() to (void*)
in order to get rid of the bogus MSVC warning C4090, which has been reported
as MSVC bug 101661:
<http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101661>
row_mysql_read_blob_ref(): To get rid of a bogus MSVC warning C4090,
drop a const qualifier.
2008-03-04 08:57:07 +00:00
|
|
|
*buf++ = (byte) (0x80 | val >> 8);
|
|
|
|
*buf++ = (byte) val;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Write the index information for the compressed page.
|
|
|
|
@return used size of buf */
|
2006-02-10 15:06:17 +00:00
|
|
|
static
|
|
|
|
ulint
|
|
|
|
page_zip_fields_encode(
|
|
|
|
/*===================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint n, /*!< in: number of fields to compress */
|
|
|
|
dict_index_t* index, /*!< in: index comprising at least n fields */
|
|
|
|
ulint trx_id_pos,/*!< in: position of the trx_id column
|
2006-02-10 15:06:17 +00:00
|
|
|
in the index, or ULINT_UNDEFINED if
|
|
|
|
this is a non-leaf page */
|
2009-05-25 05:30:14 +00:00
|
|
|
byte* buf) /*!< out: buffer of (n + 1) * 2 bytes */
|
2006-02-10 15:06:17 +00:00
|
|
|
{
|
|
|
|
const byte* buf_start = buf;
|
|
|
|
ulint i;
|
|
|
|
ulint col;
|
|
|
|
ulint trx_id_col = 0;
|
|
|
|
/* sum of lengths of preceding non-nullable fixed fields, or 0 */
|
|
|
|
ulint fixed_sum = 0;
|
|
|
|
|
|
|
|
ut_ad(trx_id_pos == ULINT_UNDEFINED || trx_id_pos < n);
|
|
|
|
|
|
|
|
for (i = col = 0; i < n; i++) {
|
|
|
|
dict_field_t* field = dict_index_get_nth_field(index, i);
|
|
|
|
ulint val;
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
if (dict_field_get_col(field)->prtype & DATA_NOT_NULL) {
|
2006-02-10 15:06:17 +00:00
|
|
|
val = 1; /* set the "not nullable" flag */
|
|
|
|
} else {
|
|
|
|
val = 0; /* nullable field */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!field->fixed_len) {
|
|
|
|
/* variable-length field */
|
2006-09-19 10:14:07 +00:00
|
|
|
const dict_col_t* column
|
|
|
|
= dict_field_get_col(field);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
if (UNIV_UNLIKELY(column->len > 255)
|
|
|
|
|| UNIV_UNLIKELY(column->mtype == DATA_BLOB)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
val |= 0x7e; /* max > 255 bytes */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fixed_sum) {
|
|
|
|
/* write out the length of any
|
|
|
|
preceding non-nullable fields */
|
2006-09-19 10:14:07 +00:00
|
|
|
buf = page_zip_fixed_field_encode(
|
|
|
|
buf, fixed_sum << 1 | 1);
|
2006-02-10 15:06:17 +00:00
|
|
|
fixed_sum = 0;
|
|
|
|
col++;
|
|
|
|
}
|
|
|
|
|
branches/zip: Fix most MSVC (Windows) compilation warnings.
lock_get_table(), locks_row_eq_lock(), buf_page_get_mutex(): Add return
after ut_error. On Windows, ut_error is not declared as "noreturn".
Add explicit type casts when assigning ulint to byte to get rid of
"possible loss of precision" warnings.
struct i_s_table_cache_struct: Declare rows_used, rows_allocd as ulint
instead of ullint. 32 bits should be enough.
fill_innodb_trx_from_cache(), i_s_zip_fill_low(): Cast 64-bit unsigned
integers to longlong when calling Field::store(longlong, bool is_unsigned).
Otherwise, the compiler would implicitly convert them to double and
invoke Field::store(double) instead.
recv_truncate_group(), recv_copy_group(), recv_calc_lsn_on_data_add():
Cast ib_uint64_t expressions to ulint to get rid of "possible loss of
precision" warnings. (There should not be any loss of precision in
these cases.)
log_close(), log_checkpoint_margin(): Declare some variables as ib_uint64_t
instead of ulint, so that there won't be any potential loss of precision.
mach_write_ull(): Cast the second argument of mach_write_to_4() to ulint.
OS_FILE_FROM_FD(): Cast the return value of _get_osfhandle() to HANDLE.
row_merge_dict_table_get_index(): Cast the parameter of mem_free() to (void*)
in order to get rid of the bogus MSVC warning C4090, which has been reported
as MSVC bug 101661:
<http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101661>
row_mysql_read_blob_ref(): To get rid of a bogus MSVC warning C4090,
drop a const qualifier.
2008-03-04 08:57:07 +00:00
|
|
|
*buf++ = (byte) val;
|
2006-02-10 15:06:17 +00:00
|
|
|
col++;
|
|
|
|
} else if (val) {
|
|
|
|
/* fixed-length non-nullable field */
|
2006-07-06 11:40:28 +00:00
|
|
|
|
2006-08-29 09:30:31 +00:00
|
|
|
if (fixed_sum && UNIV_UNLIKELY
|
|
|
|
(fixed_sum + field->fixed_len
|
|
|
|
> DICT_MAX_INDEX_COL_LEN)) {
|
2006-07-06 11:40:28 +00:00
|
|
|
/* Write out the length of the
|
|
|
|
preceding non-nullable fields,
|
|
|
|
to avoid exceeding the maximum
|
|
|
|
length of a fixed-length column. */
|
2006-09-19 10:14:07 +00:00
|
|
|
buf = page_zip_fixed_field_encode(
|
|
|
|
buf, fixed_sum << 1 | 1);
|
2006-07-06 11:40:28 +00:00
|
|
|
fixed_sum = 0;
|
|
|
|
col++;
|
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
if (i && UNIV_UNLIKELY(i == trx_id_pos)) {
|
|
|
|
if (fixed_sum) {
|
|
|
|
/* Write out the length of any
|
|
|
|
preceding non-nullable fields,
|
|
|
|
and start a new trx_id column. */
|
2006-09-19 10:14:07 +00:00
|
|
|
buf = page_zip_fixed_field_encode(
|
|
|
|
buf, fixed_sum << 1 | 1);
|
2006-07-06 08:31:26 +00:00
|
|
|
col++;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2006-07-06 10:39:09 +00:00
|
|
|
trx_id_col = col;
|
2006-02-10 15:06:17 +00:00
|
|
|
fixed_sum = field->fixed_len;
|
|
|
|
} else {
|
|
|
|
/* add to the sum */
|
|
|
|
fixed_sum += field->fixed_len;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* fixed-length nullable field */
|
|
|
|
|
|
|
|
if (fixed_sum) {
|
|
|
|
/* write out the length of any
|
|
|
|
preceding non-nullable fields */
|
2006-09-19 10:14:07 +00:00
|
|
|
buf = page_zip_fixed_field_encode(
|
|
|
|
buf, fixed_sum << 1 | 1);
|
2006-02-10 15:06:17 +00:00
|
|
|
fixed_sum = 0;
|
|
|
|
col++;
|
|
|
|
}
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
buf = page_zip_fixed_field_encode(
|
|
|
|
buf, field->fixed_len << 1);
|
2006-02-10 15:06:17 +00:00
|
|
|
col++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fixed_sum) {
|
|
|
|
/* Write out the lengths of last fixed-length columns. */
|
|
|
|
buf = page_zip_fixed_field_encode(buf, fixed_sum << 1 | 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trx_id_pos != ULINT_UNDEFINED) {
|
|
|
|
/* Write out the position of the trx_id column */
|
2006-03-08 22:19:20 +00:00
|
|
|
i = trx_id_col;
|
|
|
|
} else {
|
|
|
|
/* Write out the number of nullable fields */
|
|
|
|
i = index->n_nullable;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2006-03-08 22:19:20 +00:00
|
|
|
if (i < 128) {
|
branches/zip: Fix most MSVC (Windows) compilation warnings.
lock_get_table(), locks_row_eq_lock(), buf_page_get_mutex(): Add return
after ut_error. On Windows, ut_error is not declared as "noreturn".
Add explicit type casts when assigning ulint to byte to get rid of
"possible loss of precision" warnings.
struct i_s_table_cache_struct: Declare rows_used, rows_allocd as ulint
instead of ullint. 32 bits should be enough.
fill_innodb_trx_from_cache(), i_s_zip_fill_low(): Cast 64-bit unsigned
integers to longlong when calling Field::store(longlong, bool is_unsigned).
Otherwise, the compiler would implicitly convert them to double and
invoke Field::store(double) instead.
recv_truncate_group(), recv_copy_group(), recv_calc_lsn_on_data_add():
Cast ib_uint64_t expressions to ulint to get rid of "possible loss of
precision" warnings. (There should not be any loss of precision in
these cases.)
log_close(), log_checkpoint_margin(): Declare some variables as ib_uint64_t
instead of ulint, so that there won't be any potential loss of precision.
mach_write_ull(): Cast the second argument of mach_write_to_4() to ulint.
OS_FILE_FROM_FD(): Cast the return value of _get_osfhandle() to HANDLE.
row_merge_dict_table_get_index(): Cast the parameter of mem_free() to (void*)
in order to get rid of the bogus MSVC warning C4090, which has been reported
as MSVC bug 101661:
<http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101661>
row_mysql_read_blob_ref(): To get rid of a bogus MSVC warning C4090,
drop a const qualifier.
2008-03-04 08:57:07 +00:00
|
|
|
*buf++ = (byte) i;
|
2006-03-08 22:19:20 +00:00
|
|
|
} else {
|
branches/zip: Fix most MSVC (Windows) compilation warnings.
lock_get_table(), locks_row_eq_lock(), buf_page_get_mutex(): Add return
after ut_error. On Windows, ut_error is not declared as "noreturn".
Add explicit type casts when assigning ulint to byte to get rid of
"possible loss of precision" warnings.
struct i_s_table_cache_struct: Declare rows_used, rows_allocd as ulint
instead of ullint. 32 bits should be enough.
fill_innodb_trx_from_cache(), i_s_zip_fill_low(): Cast 64-bit unsigned
integers to longlong when calling Field::store(longlong, bool is_unsigned).
Otherwise, the compiler would implicitly convert them to double and
invoke Field::store(double) instead.
recv_truncate_group(), recv_copy_group(), recv_calc_lsn_on_data_add():
Cast ib_uint64_t expressions to ulint to get rid of "possible loss of
precision" warnings. (There should not be any loss of precision in
these cases.)
log_close(), log_checkpoint_margin(): Declare some variables as ib_uint64_t
instead of ulint, so that there won't be any potential loss of precision.
mach_write_ull(): Cast the second argument of mach_write_to_4() to ulint.
OS_FILE_FROM_FD(): Cast the return value of _get_osfhandle() to HANDLE.
row_merge_dict_table_get_index(): Cast the parameter of mem_free() to (void*)
in order to get rid of the bogus MSVC warning C4090, which has been reported
as MSVC bug 101661:
<http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101661>
row_mysql_read_blob_ref(): To get rid of a bogus MSVC warning C4090,
drop a const qualifier.
2008-03-04 08:57:07 +00:00
|
|
|
*buf++ = (byte) (0x80 | i >> 8);
|
|
|
|
*buf++ = (byte) i;
|
2006-03-08 22:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad((ulint) (buf - buf_start) <= (n + 2) * 2);
|
2006-02-10 15:06:17 +00:00
|
|
|
return((ulint) (buf - buf_start));
|
|
|
|
}
|
|
|
|
|
2005-11-24 14:13:10 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Populate the dense page directory from the sparse directory. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
page_zip_dir_encode(
|
|
|
|
/*================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_t* page, /*!< in: compact page */
|
|
|
|
byte* buf, /*!< in: pointer to dense page directory[-1];
|
2006-02-28 20:37:29 +00:00
|
|
|
out: dense directory on compressed page */
|
2009-05-25 05:30:14 +00:00
|
|
|
const rec_t** recs) /*!< in: pointer to an array of 0, or NULL;
|
2006-02-10 15:06:17 +00:00
|
|
|
out: dense page directory sorted by ascending
|
|
|
|
address (and heap_no) */
|
2005-11-24 14:13:10 +00:00
|
|
|
{
|
2006-10-19 07:52:28 +00:00
|
|
|
const byte* rec;
|
|
|
|
ulint status;
|
|
|
|
ulint min_mark;
|
|
|
|
ulint heap_no;
|
|
|
|
ulint i;
|
|
|
|
ulint n_heap;
|
|
|
|
ulint offs;
|
2005-11-24 14:13:10 +00:00
|
|
|
|
|
|
|
min_mark = 0;
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
if (page_is_leaf(page)) {
|
|
|
|
status = REC_STATUS_ORDINARY;
|
|
|
|
} else {
|
2005-11-24 14:13:10 +00:00
|
|
|
status = REC_STATUS_NODE_PTR;
|
2006-08-29 09:30:31 +00:00
|
|
|
if (UNIV_UNLIKELY
|
2006-09-26 07:39:02 +00:00
|
|
|
(mach_read_from_4(page + FIL_PAGE_PREV) == FIL_NULL)) {
|
2005-11-24 14:13:10 +00:00
|
|
|
min_mark = REC_INFO_MIN_REC_FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-19 07:52:28 +00:00
|
|
|
n_heap = page_dir_get_n_heap(page);
|
2005-11-24 14:13:10 +00:00
|
|
|
|
|
|
|
/* Traverse the list of stored records in the collation order,
|
|
|
|
starting from the first user record. */
|
|
|
|
|
2006-10-19 07:52:28 +00:00
|
|
|
rec = page + PAGE_NEW_INFIMUM, TRUE;
|
2005-11-24 14:13:10 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
ulint info_bits;
|
|
|
|
offs = rec_get_next_offs(rec, TRUE);
|
|
|
|
if (UNIV_UNLIKELY(offs == PAGE_NEW_SUPREMUM)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-10-19 07:52:28 +00:00
|
|
|
rec = page + offs;
|
2005-11-24 14:13:10 +00:00
|
|
|
heap_no = rec_get_heap_no_new(rec);
|
2006-10-20 12:45:53 +00:00
|
|
|
ut_a(heap_no >= PAGE_HEAP_NO_USER_LOW);
|
2005-11-24 14:13:10 +00:00
|
|
|
ut_a(heap_no < n_heap);
|
2006-02-28 20:37:29 +00:00
|
|
|
ut_a(offs < UNIV_PAGE_SIZE - PAGE_DIR);
|
|
|
|
ut_a(offs >= PAGE_ZIP_START);
|
2007-12-20 13:23:23 +00:00
|
|
|
#if PAGE_ZIP_DIR_SLOT_MASK & (PAGE_ZIP_DIR_SLOT_MASK + 1)
|
|
|
|
# error "PAGE_ZIP_DIR_SLOT_MASK is not 1 less than a power of 2"
|
|
|
|
#endif
|
|
|
|
#if PAGE_ZIP_DIR_SLOT_MASK < UNIV_PAGE_SIZE - 1
|
|
|
|
# error "PAGE_ZIP_DIR_SLOT_MASK < UNIV_PAGE_SIZE - 1"
|
2006-02-28 20:37:29 +00:00
|
|
|
#endif
|
2005-11-24 14:13:10 +00:00
|
|
|
if (UNIV_UNLIKELY(rec_get_n_owned_new(rec))) {
|
|
|
|
offs |= PAGE_ZIP_DIR_SLOT_OWNED;
|
|
|
|
}
|
|
|
|
|
|
|
|
info_bits = rec_get_info_bits(rec, TRUE);
|
|
|
|
if (UNIV_UNLIKELY(info_bits & REC_INFO_DELETED_FLAG)) {
|
|
|
|
info_bits &= ~REC_INFO_DELETED_FLAG;
|
|
|
|
offs |= PAGE_ZIP_DIR_SLOT_DEL;
|
|
|
|
}
|
|
|
|
ut_a(info_bits == min_mark);
|
|
|
|
/* Only the smallest user record can have
|
|
|
|
REC_INFO_MIN_REC_FLAG set. */
|
|
|
|
min_mark = 0;
|
|
|
|
|
2006-02-28 20:37:29 +00:00
|
|
|
mach_write_to_2(buf - PAGE_ZIP_DIR_SLOT_SIZE * ++i, offs);
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
if (UNIV_LIKELY_NULL(recs)) {
|
|
|
|
/* Ensure that each heap_no occurs at most once. */
|
2006-10-20 12:45:53 +00:00
|
|
|
ut_a(!recs[heap_no - PAGE_HEAP_NO_USER_LOW]);
|
2006-02-10 15:06:17 +00:00
|
|
|
/* exclude infimum and supremum */
|
2006-10-20 12:45:53 +00:00
|
|
|
recs[heap_no - PAGE_HEAP_NO_USER_LOW] = rec;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
|
|
|
|
ut_a(rec_get_status(rec) == status);
|
|
|
|
}
|
|
|
|
|
2006-10-19 07:52:28 +00:00
|
|
|
offs = page_header_get_field(page, PAGE_FREE);
|
2005-11-24 14:13:10 +00:00
|
|
|
|
|
|
|
/* Traverse the free list (of deleted records). */
|
|
|
|
while (offs) {
|
|
|
|
ut_ad(!(offs & ~PAGE_ZIP_DIR_SLOT_MASK));
|
2006-10-19 07:52:28 +00:00
|
|
|
rec = page + offs;
|
2005-11-24 14:13:10 +00:00
|
|
|
|
|
|
|
heap_no = rec_get_heap_no_new(rec);
|
2006-10-20 12:45:53 +00:00
|
|
|
ut_a(heap_no >= PAGE_HEAP_NO_USER_LOW);
|
2005-11-24 14:13:10 +00:00
|
|
|
ut_a(heap_no < n_heap);
|
|
|
|
|
|
|
|
ut_a(!rec[-REC_N_NEW_EXTRA_BYTES]); /* info_bits and n_owned */
|
|
|
|
ut_a(rec_get_status(rec) == status);
|
|
|
|
|
2006-02-28 20:37:29 +00:00
|
|
|
mach_write_to_2(buf - PAGE_ZIP_DIR_SLOT_SIZE * ++i, offs);
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
if (UNIV_LIKELY_NULL(recs)) {
|
|
|
|
/* Ensure that each heap_no occurs at most once. */
|
2006-10-20 12:45:53 +00:00
|
|
|
ut_a(!recs[heap_no - PAGE_HEAP_NO_USER_LOW]);
|
2006-02-10 15:06:17 +00:00
|
|
|
/* exclude infimum and supremum */
|
2006-10-20 12:45:53 +00:00
|
|
|
recs[heap_no - PAGE_HEAP_NO_USER_LOW] = rec;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
|
|
|
|
offs = rec_get_next_offs(rec, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure that each heap no occurs at least once. */
|
2006-10-20 12:45:53 +00:00
|
|
|
ut_a(i + PAGE_HEAP_NO_USER_LOW == n_heap);
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 12:27:53 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Allocate memory for zlib. */
|
|
|
|
static
|
|
|
|
void*
|
2006-03-27 12:30:25 +00:00
|
|
|
page_zip_malloc(
|
|
|
|
/*============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
void* opaque, /*!< in/out: memory heap */
|
|
|
|
uInt items, /*!< in: number of items to allocate */
|
|
|
|
uInt size) /*!< in: size of an item in bytes */
|
2006-03-27 12:27:53 +00:00
|
|
|
{
|
2007-01-05 21:15:05 +00:00
|
|
|
return(mem_heap_alloc(opaque, items * size));
|
2006-03-27 12:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Deallocate memory for zlib. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
page_zip_free(
|
|
|
|
/*==========*/
|
2009-05-25 05:30:14 +00:00
|
|
|
void* opaque __attribute__((unused)), /*!< in: memory heap */
|
|
|
|
void* address __attribute__((unused)))/*!< in: object to free */
|
2006-03-27 12:27:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-01-29 08:51:20 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Configure the zlib allocator to use the given memory heap. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2007-01-29 08:51:20 +00:00
|
|
|
void
|
|
|
|
page_zip_set_alloc(
|
|
|
|
/*===============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
void* stream, /*!< in/out: zlib stream */
|
|
|
|
mem_heap_t* heap) /*!< in: memory heap to use */
|
2007-01-29 08:51:20 +00:00
|
|
|
{
|
|
|
|
z_stream* strm = stream;
|
|
|
|
|
|
|
|
strm->zalloc = page_zip_malloc;
|
|
|
|
strm->zfree = page_zip_free;
|
|
|
|
strm->opaque = heap;
|
|
|
|
}
|
|
|
|
|
2008-02-19 14:42:52 +00:00
|
|
|
#if 0 || defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
|
|
|
|
# define PAGE_ZIP_COMPRESS_DBG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PAGE_ZIP_COMPRESS_DBG
|
2006-05-09 16:09:09 +00:00
|
|
|
/* Set this variable in a debugger to enable
|
|
|
|
excessive logging in page_zip_compress(). */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN ibool page_zip_compress_dbg;
|
2008-02-19 14:42:52 +00:00
|
|
|
/* Set this variable in a debugger to enable
|
|
|
|
binary logging of the data passed to deflate().
|
|
|
|
When this variable is nonzero, it will act
|
|
|
|
as a log file name generator. */
|
2008-02-22 21:03:31 +00:00
|
|
|
UNIV_INTERN unsigned page_zip_compress_log;
|
2006-05-09 16:09:09 +00:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Wrapper for deflate(). Log the operation if page_zip_compress_dbg is set. */
|
|
|
|
static
|
|
|
|
ibool
|
|
|
|
page_zip_compress_deflate(
|
|
|
|
/*======================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
FILE* logfile,/*!< in: log file, or NULL */
|
|
|
|
z_streamp strm, /*!< in/out: compressed stream for deflate() */
|
|
|
|
int flush) /*!< in: deflate() flushing method */
|
2006-05-09 16:09:09 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
if (UNIV_UNLIKELY(page_zip_compress_dbg)) {
|
|
|
|
ut_print_buf(stderr, strm->next_in, strm->avail_in);
|
|
|
|
}
|
2008-02-19 14:42:52 +00:00
|
|
|
if (UNIV_LIKELY_NULL(logfile)) {
|
|
|
|
fwrite(strm->next_in, 1, strm->avail_in, logfile);
|
|
|
|
}
|
2006-05-09 16:09:09 +00:00
|
|
|
status = deflate(strm, flush);
|
|
|
|
if (UNIV_UNLIKELY(page_zip_compress_dbg)) {
|
|
|
|
fprintf(stderr, " -> %d\n", status);
|
|
|
|
}
|
|
|
|
return(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Redefine deflate(). */
|
|
|
|
# undef deflate
|
2008-02-19 14:42:52 +00:00
|
|
|
# define deflate(strm, flush) page_zip_compress_deflate(logfile, strm, flush)
|
|
|
|
# define FILE_LOGFILE FILE* logfile,
|
|
|
|
# define LOGFILE logfile,
|
|
|
|
#else /* PAGE_ZIP_COMPRESS_DBG */
|
|
|
|
# define FILE_LOGFILE
|
|
|
|
# define LOGFILE
|
|
|
|
#endif /* PAGE_ZIP_COMPRESS_DBG */
|
2006-05-09 16:09:09 +00:00
|
|
|
|
2006-09-21 07:27:35 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Compress the records of a node pointer page.
|
|
|
|
@return Z_OK, or a zlib error code */
|
2006-09-21 07:27:35 +00:00
|
|
|
static
|
|
|
|
int
|
|
|
|
page_zip_compress_node_ptrs(
|
|
|
|
/*========================*/
|
2008-02-19 14:42:52 +00:00
|
|
|
FILE_LOGFILE
|
2009-05-25 05:30:14 +00:00
|
|
|
z_stream* c_stream, /*!< in/out: compressed page stream */
|
|
|
|
const rec_t** recs, /*!< in: dense page directory
|
2006-09-21 07:27:35 +00:00
|
|
|
sorted by address */
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint n_dense, /*!< in: size of recs[] */
|
|
|
|
dict_index_t* index, /*!< in: the index of the page */
|
|
|
|
byte* storage, /*!< in: end of dense page directory */
|
|
|
|
mem_heap_t* heap) /*!< in: temporary memory heap */
|
2006-09-21 07:27:35 +00:00
|
|
|
{
|
|
|
|
int err = Z_OK;
|
|
|
|
ulint* offsets = NULL;
|
|
|
|
|
|
|
|
do {
|
2006-10-19 07:52:28 +00:00
|
|
|
const rec_t* rec = *recs++;
|
2006-09-21 07:27:35 +00:00
|
|
|
|
|
|
|
offsets = rec_get_offsets(rec, index, offsets,
|
|
|
|
ULINT_UNDEFINED, &heap);
|
|
|
|
/* Only leaf nodes may contain externally stored columns. */
|
|
|
|
ut_ad(!rec_offs_any_extern(offsets));
|
|
|
|
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets));
|
|
|
|
UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets),
|
|
|
|
rec_offs_extra_size(offsets));
|
2007-10-30 08:19:48 +00:00
|
|
|
|
2006-09-21 07:27:35 +00:00
|
|
|
/* Compress the extra bytes. */
|
|
|
|
c_stream->avail_in = rec - REC_N_NEW_EXTRA_BYTES
|
|
|
|
- c_stream->next_in;
|
|
|
|
|
|
|
|
if (c_stream->avail_in) {
|
|
|
|
err = deflate(c_stream, Z_NO_FLUSH);
|
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ut_ad(!c_stream->avail_in);
|
|
|
|
|
|
|
|
/* Compress the data bytes, except node_ptr. */
|
2006-10-19 07:52:28 +00:00
|
|
|
c_stream->next_in = (byte*) rec;
|
2006-09-21 07:27:35 +00:00
|
|
|
c_stream->avail_in = rec_offs_data_size(offsets)
|
|
|
|
- REC_NODE_PTR_SIZE;
|
|
|
|
ut_ad(c_stream->avail_in);
|
|
|
|
|
|
|
|
err = deflate(c_stream, Z_NO_FLUSH);
|
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(!c_stream->avail_in);
|
|
|
|
|
|
|
|
memcpy(storage - REC_NODE_PTR_SIZE
|
|
|
|
* (rec_get_heap_no_new(rec) - 1),
|
|
|
|
c_stream->next_in, REC_NODE_PTR_SIZE);
|
|
|
|
c_stream->next_in += REC_NODE_PTR_SIZE;
|
|
|
|
} while (--n_dense);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Compress the records of a leaf node of a secondary index.
|
|
|
|
@return Z_OK, or a zlib error code */
|
2006-09-21 07:27:35 +00:00
|
|
|
static
|
|
|
|
int
|
|
|
|
page_zip_compress_sec(
|
|
|
|
/*==================*/
|
2008-02-19 14:42:52 +00:00
|
|
|
FILE_LOGFILE
|
2009-05-25 05:30:14 +00:00
|
|
|
z_stream* c_stream, /*!< in/out: compressed page stream */
|
|
|
|
const rec_t** recs, /*!< in: dense page directory
|
2006-09-21 07:27:35 +00:00
|
|
|
sorted by address */
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint n_dense) /*!< in: size of recs[] */
|
2006-09-21 07:27:35 +00:00
|
|
|
{
|
|
|
|
int err = Z_OK;
|
|
|
|
|
|
|
|
ut_ad(n_dense > 0);
|
|
|
|
|
|
|
|
do {
|
|
|
|
const rec_t* rec = *recs++;
|
|
|
|
|
|
|
|
/* Compress everything up to this record. */
|
|
|
|
c_stream->avail_in = rec - REC_N_NEW_EXTRA_BYTES
|
|
|
|
- c_stream->next_in;
|
|
|
|
|
|
|
|
if (UNIV_LIKELY(c_stream->avail_in)) {
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(c_stream->next_in,
|
|
|
|
c_stream->avail_in);
|
2006-09-21 07:27:35 +00:00
|
|
|
err = deflate(c_stream, Z_NO_FLUSH);
|
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(!c_stream->avail_in);
|
|
|
|
ut_ad(c_stream->next_in == rec - REC_N_NEW_EXTRA_BYTES);
|
|
|
|
|
|
|
|
/* Skip the REC_N_NEW_EXTRA_BYTES. */
|
|
|
|
|
|
|
|
c_stream->next_in = (byte*) rec;
|
|
|
|
} while (--n_dense);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Compress a record of a leaf node of a clustered index that contains
|
2009-05-25 05:30:14 +00:00
|
|
|
externally stored columns.
|
|
|
|
@return Z_OK, or a zlib error code */
|
2007-02-05 11:19:25 +00:00
|
|
|
static
|
|
|
|
int
|
|
|
|
page_zip_compress_clust_ext(
|
|
|
|
/*========================*/
|
2008-02-19 14:42:52 +00:00
|
|
|
FILE_LOGFILE
|
2009-05-25 05:30:14 +00:00
|
|
|
z_stream* c_stream, /*!< in/out: compressed page stream */
|
|
|
|
const rec_t* rec, /*!< in: record */
|
|
|
|
const ulint* offsets, /*!< in: rec_get_offsets(rec) */
|
|
|
|
ulint trx_id_col, /*!< in: position of of DB_TRX_ID */
|
|
|
|
byte* deleted, /*!< in: dense directory entry pointing
|
2007-02-05 11:19:25 +00:00
|
|
|
to the head of the free list */
|
2009-05-25 05:30:14 +00:00
|
|
|
byte* storage, /*!< in: end of dense page directory */
|
|
|
|
byte** externs, /*!< in/out: pointer to the next
|
2007-02-05 11:19:25 +00:00
|
|
|
available BLOB pointer */
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint* n_blobs) /*!< in/out: number of
|
2007-02-05 11:19:25 +00:00
|
|
|
externally stored columns */
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
ulint i;
|
|
|
|
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets));
|
|
|
|
UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets),
|
|
|
|
rec_offs_extra_size(offsets));
|
2007-10-30 08:19:48 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
for (i = 0; i < rec_offs_n_fields(offsets); i++) {
|
|
|
|
ulint len;
|
|
|
|
const byte* src;
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(i == trx_id_col)) {
|
|
|
|
ut_ad(!rec_offs_nth_extern(offsets, i));
|
|
|
|
/* Store trx_id and roll_ptr
|
|
|
|
in uncompressed form. */
|
|
|
|
src = rec_get_nth_field(rec, offsets, i, &len);
|
|
|
|
ut_ad(src + DATA_TRX_ID_LEN
|
|
|
|
== rec_get_nth_field(rec, offsets,
|
|
|
|
i + 1, &len));
|
|
|
|
ut_ad(len == DATA_ROLL_PTR_LEN);
|
|
|
|
|
|
|
|
/* Compress any preceding bytes. */
|
|
|
|
c_stream->avail_in
|
|
|
|
= src - c_stream->next_in;
|
|
|
|
|
|
|
|
if (c_stream->avail_in) {
|
|
|
|
err = deflate(c_stream, Z_NO_FLUSH);
|
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(!c_stream->avail_in);
|
|
|
|
ut_ad(c_stream->next_in == src);
|
|
|
|
|
|
|
|
memcpy(storage
|
|
|
|
- (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN)
|
|
|
|
* (rec_get_heap_no_new(rec) - 1),
|
|
|
|
c_stream->next_in,
|
|
|
|
DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
|
|
|
|
|
|
|
c_stream->next_in
|
|
|
|
+= DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN;
|
|
|
|
|
|
|
|
/* Skip also roll_ptr */
|
|
|
|
i++;
|
|
|
|
} else if (rec_offs_nth_extern(offsets, i)) {
|
|
|
|
src = rec_get_nth_field(rec, offsets, i, &len);
|
|
|
|
ut_ad(len >= BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
src += len - BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
c_stream->avail_in = src
|
|
|
|
- c_stream->next_in;
|
|
|
|
if (UNIV_LIKELY(c_stream->avail_in)) {
|
|
|
|
err = deflate(c_stream, Z_NO_FLUSH);
|
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(!c_stream->avail_in);
|
|
|
|
ut_ad(c_stream->next_in == src);
|
|
|
|
|
|
|
|
/* Reserve space for the data at
|
|
|
|
the end of the space reserved for
|
|
|
|
the compressed data and the page
|
|
|
|
modification log. */
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY
|
|
|
|
(c_stream->avail_out
|
|
|
|
<= BTR_EXTERN_FIELD_REF_SIZE)) {
|
|
|
|
/* out of space */
|
|
|
|
return(Z_BUF_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(*externs == c_stream->next_out
|
|
|
|
+ c_stream->avail_out
|
|
|
|
+ 1/* end of modif. log */);
|
|
|
|
|
|
|
|
c_stream->next_in
|
|
|
|
+= BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
/* Skip deleted records. */
|
|
|
|
if (UNIV_LIKELY_NULL
|
|
|
|
(page_zip_dir_find_low(
|
|
|
|
storage, deleted,
|
|
|
|
page_offset(rec)))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*n_blobs)++;
|
|
|
|
c_stream->avail_out
|
|
|
|
-= BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
*externs -= BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
/* Copy the BLOB pointer */
|
|
|
|
memcpy(*externs, c_stream->next_in
|
|
|
|
- BTR_EXTERN_FIELD_REF_SIZE,
|
|
|
|
BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(Z_OK);
|
|
|
|
}
|
|
|
|
|
2006-09-21 07:27:35 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Compress the records of a leaf node of a clustered index.
|
|
|
|
@return Z_OK, or a zlib error code */
|
2006-09-21 07:27:35 +00:00
|
|
|
static
|
|
|
|
int
|
|
|
|
page_zip_compress_clust(
|
|
|
|
/*====================*/
|
2008-02-19 14:42:52 +00:00
|
|
|
FILE_LOGFILE
|
2009-05-25 05:30:14 +00:00
|
|
|
z_stream* c_stream, /*!< in/out: compressed page stream */
|
|
|
|
const rec_t** recs, /*!< in: dense page directory
|
2006-09-21 07:27:35 +00:00
|
|
|
sorted by address */
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint n_dense, /*!< in: size of recs[] */
|
|
|
|
dict_index_t* index, /*!< in: the index of the page */
|
|
|
|
ulint* n_blobs, /*!< in: 0; out: number of
|
2006-09-21 07:27:35 +00:00
|
|
|
externally stored columns */
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint trx_id_col, /*!< index of the trx_id column */
|
|
|
|
byte* deleted, /*!< in: dense directory entry pointing
|
2006-09-21 07:27:35 +00:00
|
|
|
to the head of the free list */
|
2009-05-25 05:30:14 +00:00
|
|
|
byte* storage, /*!< in: end of dense page directory */
|
|
|
|
mem_heap_t* heap) /*!< in: temporary memory heap */
|
2006-09-21 07:27:35 +00:00
|
|
|
{
|
|
|
|
int err = Z_OK;
|
|
|
|
ulint* offsets = NULL;
|
|
|
|
/* BTR_EXTERN_FIELD_REF storage */
|
|
|
|
byte* externs = storage - n_dense
|
|
|
|
* (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
2007-02-05 11:19:25 +00:00
|
|
|
|
|
|
|
ut_ad(*n_blobs == 0);
|
2006-09-21 07:27:35 +00:00
|
|
|
|
|
|
|
do {
|
2006-10-19 07:52:28 +00:00
|
|
|
const rec_t* rec = *recs++;
|
2006-09-21 07:27:35 +00:00
|
|
|
|
|
|
|
offsets = rec_get_offsets(rec, index, offsets,
|
|
|
|
ULINT_UNDEFINED, &heap);
|
2007-02-05 11:19:25 +00:00
|
|
|
ut_ad(rec_offs_n_fields(offsets)
|
|
|
|
== dict_index_get_n_fields(index));
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets));
|
|
|
|
UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets),
|
|
|
|
rec_offs_extra_size(offsets));
|
2006-09-21 07:27:35 +00:00
|
|
|
|
|
|
|
/* Compress the extra bytes. */
|
|
|
|
c_stream->avail_in = rec - REC_N_NEW_EXTRA_BYTES
|
|
|
|
- c_stream->next_in;
|
|
|
|
|
|
|
|
if (c_stream->avail_in) {
|
|
|
|
err = deflate(c_stream, Z_NO_FLUSH);
|
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
|
|
|
|
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ut_ad(!c_stream->avail_in);
|
|
|
|
ut_ad(c_stream->next_in == rec - REC_N_NEW_EXTRA_BYTES);
|
|
|
|
|
|
|
|
/* Compress the data bytes. */
|
|
|
|
|
2006-10-19 07:52:28 +00:00
|
|
|
c_stream->next_in = (byte*) rec;
|
2006-09-21 07:27:35 +00:00
|
|
|
|
|
|
|
/* Check if there are any externally stored columns.
|
|
|
|
For each externally stored column, store the
|
|
|
|
BTR_EXTERN_FIELD_REF separately. */
|
2007-02-05 11:19:25 +00:00
|
|
|
if (UNIV_UNLIKELY(rec_offs_any_extern(offsets))) {
|
|
|
|
ut_ad(dict_index_is_clust(index));
|
2006-09-21 07:27:35 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
err = page_zip_compress_clust_ext(
|
2008-02-19 14:42:52 +00:00
|
|
|
LOGFILE
|
2007-02-05 11:19:25 +00:00
|
|
|
c_stream, rec, offsets, trx_id_col,
|
|
|
|
deleted, storage, &externs, n_blobs);
|
2006-09-21 07:27:35 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
2006-09-21 07:27:35 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ulint len;
|
|
|
|
const byte* src;
|
2006-09-21 07:27:35 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
/* Store trx_id and roll_ptr in uncompressed form. */
|
|
|
|
src = rec_get_nth_field(rec, offsets,
|
|
|
|
trx_id_col, &len);
|
|
|
|
ut_ad(src + DATA_TRX_ID_LEN
|
|
|
|
== rec_get_nth_field(rec, offsets,
|
|
|
|
trx_id_col + 1, &len));
|
|
|
|
ut_ad(len == DATA_ROLL_PTR_LEN);
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets));
|
|
|
|
UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets),
|
|
|
|
rec_offs_extra_size(offsets));
|
2006-09-21 07:27:35 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
/* Compress any preceding bytes. */
|
|
|
|
c_stream->avail_in = src - c_stream->next_in;
|
2006-09-21 07:27:35 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
if (c_stream->avail_in) {
|
|
|
|
err = deflate(c_stream, Z_NO_FLUSH);
|
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
2006-09-21 07:27:35 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
return(err);
|
2006-09-21 07:27:35 +00:00
|
|
|
}
|
2007-02-05 11:19:25 +00:00
|
|
|
}
|
2006-09-21 07:27:35 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
ut_ad(!c_stream->avail_in);
|
|
|
|
ut_ad(c_stream->next_in == src);
|
2006-09-21 07:27:35 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
memcpy(storage
|
|
|
|
- (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN)
|
|
|
|
* (rec_get_heap_no_new(rec) - 1),
|
|
|
|
c_stream->next_in,
|
|
|
|
DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
2006-09-21 07:27:35 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
c_stream->next_in
|
|
|
|
+= DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN;
|
2006-09-21 07:27:35 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
/* Skip also roll_ptr */
|
|
|
|
ut_ad(trx_id_col + 1 < rec_offs_n_fields(offsets));
|
2006-09-21 07:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Compress the last bytes of the record. */
|
2006-10-19 07:52:28 +00:00
|
|
|
c_stream->avail_in = rec + rec_offs_data_size(offsets)
|
2006-09-21 07:27:35 +00:00
|
|
|
- c_stream->next_in;
|
|
|
|
|
|
|
|
if (c_stream->avail_in) {
|
|
|
|
err = deflate(c_stream, Z_NO_FLUSH);
|
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
|
|
|
|
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ut_ad(!c_stream->avail_in);
|
|
|
|
} while (--n_dense);
|
|
|
|
|
|
|
|
func_exit:
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Compress a page.
|
|
|
|
@return TRUE on success, FALSE on failure; page_zip will be left intact on failure. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 11:48:10 +00:00
|
|
|
ibool
|
|
|
|
page_zip_compress(
|
|
|
|
/*==============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip,/*!< in: size; out: data, n_blobs,
|
2006-11-30 14:09:29 +00:00
|
|
|
m_start, m_end, m_nonempty */
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_t* page, /*!< in: uncompressed page */
|
|
|
|
dict_index_t* index, /*!< in: index of the B-tree node */
|
|
|
|
mtr_t* mtr) /*!< in: mini-transaction, or NULL */
|
2005-10-27 11:48:10 +00:00
|
|
|
{
|
|
|
|
z_stream c_stream;
|
|
|
|
int err;
|
2006-02-10 15:06:17 +00:00
|
|
|
ulint n_fields;/* number of index fields needed */
|
|
|
|
byte* fields; /* index field information */
|
|
|
|
byte* buf; /* compressed payload of the page */
|
2006-02-28 20:37:29 +00:00
|
|
|
byte* buf_end;/* end of buf */
|
2005-11-25 12:34:38 +00:00
|
|
|
ulint n_dense;
|
2006-05-10 07:15:07 +00:00
|
|
|
ulint slot_size;/* amount of uncompressed bytes per record */
|
2006-02-10 15:06:17 +00:00
|
|
|
const rec_t** recs; /* dense page directory, sorted by address */
|
2005-11-24 14:13:10 +00:00
|
|
|
mem_heap_t* heap;
|
2006-02-10 15:06:17 +00:00
|
|
|
ulint trx_id_col;
|
|
|
|
ulint* offsets = NULL;
|
|
|
|
ulint n_blobs = 0;
|
|
|
|
byte* storage;/* storage of uncompressed columns */
|
2008-02-27 14:34:44 +00:00
|
|
|
ullint usec = ut_time_us(NULL);
|
2008-02-19 14:42:52 +00:00
|
|
|
#ifdef PAGE_ZIP_COMPRESS_DBG
|
|
|
|
FILE* logfile = NULL;
|
|
|
|
#endif
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-10-19 07:52:28 +00:00
|
|
|
ut_a(page_is_comp(page));
|
|
|
|
ut_a(fil_page_get_type(page) == FIL_PAGE_INDEX);
|
2006-09-20 12:23:25 +00:00
|
|
|
ut_ad(page_simple_validate_new((page_t*) page));
|
2005-11-25 07:51:28 +00:00
|
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
branches/zip: Write PAGE_MAX_TRX_ID to the redo log. Otherwise,
transactions that are started before the rollback of incomplete
transactions has finished may have an inconsistent view of the
secondary indexes.
dict_index_is_sec_or_ibuf(): Auxiliary function for controlling
updates and checks of PAGE_MAX_TRX_ID: check whether an index is a
secondary index or the insert buffer tree.
page_set_max_trx_id(), page_update_max_trx_id(),
lock_rec_insert_check_and_lock(),
lock_sec_rec_modify_check_and_lock(), btr_cur_ins_lock_and_undo(),
btr_cur_upd_lock_and_undo(): Add the parameter mtr.
page_set_max_trx_id(): Allow mtr to be NULL. When mtr==NULL, do not
attempt to write to the redo log. This only occurs when creating a
page or reorganizing a compressed page. In these cases, the
PAGE_MAX_TRX_ID will be set correctly during the application of redo
log records, even though there is no explicit log record about it.
btr_discard_only_page_on_level(): Preserve PAGE_MAX_TRX_ID. This
function should be unreachable, though.
btr_cur_pessimistic_update(): Update PAGE_MAX_TRX_ID.
Add some assertions for checking that PAGE_MAX_TRX_ID is set on all
secondary index leaf pages.
rb://115 tested by Michael, fixes Issue #211
2009-05-19 18:59:07 +00:00
|
|
|
ut_ad(dict_table_is_comp(index->table));
|
|
|
|
ut_ad(!dict_index_is_ibuf(index));
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2007-10-31 12:42:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page, UNIV_PAGE_SIZE);
|
|
|
|
|
2005-11-24 14:13:10 +00:00
|
|
|
/* Check the data that will be omitted. */
|
|
|
|
ut_a(!memcmp(page + (PAGE_NEW_INFIMUM - REC_N_NEW_EXTRA_BYTES),
|
|
|
|
infimum_extra, sizeof infimum_extra));
|
|
|
|
ut_a(!memcmp(page + PAGE_NEW_INFIMUM,
|
|
|
|
infimum_data, sizeof infimum_data));
|
|
|
|
ut_a(page[PAGE_NEW_SUPREMUM - REC_N_NEW_EXTRA_BYTES]
|
2006-08-29 09:30:31 +00:00
|
|
|
/* info_bits == 0, n_owned <= max */
|
|
|
|
<= PAGE_DIR_SLOT_MAX_N_OWNED);
|
2005-11-24 14:13:10 +00:00
|
|
|
ut_a(!memcmp(page + (PAGE_NEW_SUPREMUM - REC_N_NEW_EXTRA_BYTES + 1),
|
|
|
|
supremum_extra_data, sizeof supremum_extra_data));
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-10-19 07:52:28 +00:00
|
|
|
if (UNIV_UNLIKELY(!page_get_n_recs(page))) {
|
|
|
|
ut_a(rec_get_next_offs(page + PAGE_NEW_INFIMUM, TRUE)
|
2006-08-29 09:30:31 +00:00
|
|
|
== PAGE_NEW_SUPREMUM);
|
2005-11-25 07:51:28 +00:00
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
if (page_is_leaf(page)) {
|
|
|
|
n_fields = dict_index_get_n_fields(index);
|
|
|
|
} else {
|
|
|
|
n_fields = dict_index_get_n_unique_in_tree(index);
|
|
|
|
}
|
|
|
|
|
2005-11-25 12:34:38 +00:00
|
|
|
/* The dense directory excludes the infimum and supremum records. */
|
2006-10-20 12:45:53 +00:00
|
|
|
n_dense = page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW;
|
2008-02-19 14:42:52 +00:00
|
|
|
#ifdef PAGE_ZIP_COMPRESS_DBG
|
2006-05-09 16:09:09 +00:00
|
|
|
if (UNIV_UNLIKELY(page_zip_compress_dbg)) {
|
|
|
|
fprintf(stderr, "compress %p %p %lu %lu %lu\n",
|
|
|
|
(void*) page_zip, (void*) page,
|
|
|
|
page_is_leaf(page),
|
|
|
|
n_fields, n_dense);
|
|
|
|
}
|
2008-02-19 14:42:52 +00:00
|
|
|
if (UNIV_UNLIKELY(page_zip_compress_log)) {
|
|
|
|
/* Create a log file for every compression attempt. */
|
|
|
|
char logfilename[9];
|
|
|
|
ut_snprintf(logfilename, sizeof logfilename,
|
|
|
|
"%08x", page_zip_compress_log++);
|
|
|
|
logfile = fopen(logfilename, "wb");
|
|
|
|
|
|
|
|
if (logfile) {
|
|
|
|
/* Write the uncompressed page to the log. */
|
|
|
|
fwrite(page, 1, UNIV_PAGE_SIZE, logfile);
|
|
|
|
/* Record the compressed size as zero.
|
|
|
|
This will be overwritten at successful exit. */
|
|
|
|
putc(0, logfile);
|
|
|
|
putc(0, logfile);
|
|
|
|
putc(0, logfile);
|
|
|
|
putc(0, logfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* PAGE_ZIP_COMPRESS_DBG */
|
branches/zip: Rename the INFORMATION_SCHEMA tables
INNODB_ZIP and INNODB_ZIP_RESET to
INNODB_COMPRESSION and INNODB_COMPRESSION_RESET,
and remove the statistics of the buddy system.
This change was discussed with Ken. It makes the tables shorter
and easier to understand. The removed data will be represented in
the tables INNODB_COMPRESSION_BUDDY and INNODB_COMPRESSION_BUDDY_RESET
that will be added later.
i_s_innodb_zip, i_s_innodb_zip_reset, i_s_zip_fields_info[],
i_s_zip_fill_low(), i_s_zip_fill(), i_s_zip_reset_fill(),
i_s_zip_init(), i_s_zip_reset_init(): Replace "zip" with "compression".
i_s_compression_fields_info[]: Remove "used", "free",
"relocated", "relocated_usec". In "compressed_usec" and "decompressed_usec",
replace microseconds with seconds ("usec" with "sec").
page_zip_decompress(): Correct a typo in the function comment.
PAGE_ZIP_SSIZE_BITS, PAGE_ZIP_NUM_SSIZE: New constants.
page_zip_stat_t, page_zip_stat: Statistics of the compression, grouped
by page size.
page_zip_simple_validate(): Assert that page_zip->ssize is reasonable.
2008-03-28 09:28:54 +00:00
|
|
|
page_zip_stat[page_zip->ssize - 1].compressed++;
|
2007-04-10 08:11:49 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
if (UNIV_UNLIKELY(n_dense * PAGE_ZIP_DIR_SLOT_SIZE
|
2006-11-27 13:44:32 +00:00
|
|
|
>= page_zip_get_size(page_zip))) {
|
2008-02-27 14:34:44 +00:00
|
|
|
|
|
|
|
goto err_exit;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-11-27 13:44:32 +00:00
|
|
|
heap = mem_heap_create(page_zip_get_size(page_zip)
|
2006-08-29 09:30:31 +00:00
|
|
|
+ n_fields * (2 + sizeof *offsets)
|
|
|
|
+ n_dense * ((sizeof *recs)
|
2007-01-05 21:15:05 +00:00
|
|
|
- PAGE_ZIP_DIR_SLOT_SIZE)
|
|
|
|
+ UNIV_PAGE_SIZE * 4
|
|
|
|
+ (512 << MAX_MEM_LEVEL));
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2007-08-16 13:25:56 +00:00
|
|
|
recs = mem_heap_zalloc(heap, n_dense * sizeof *recs);
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
fields = mem_heap_alloc(heap, (n_fields + 1) * 2);
|
|
|
|
|
2006-11-27 13:44:32 +00:00
|
|
|
buf = mem_heap_alloc(heap, page_zip_get_size(page_zip) - PAGE_DATA);
|
|
|
|
buf_end = buf + page_zip_get_size(page_zip) - PAGE_DATA;
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
/* Compress the data payload. */
|
2007-01-29 08:51:20 +00:00
|
|
|
page_zip_set_alloc(&c_stream, heap);
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2007-01-05 21:15:05 +00:00
|
|
|
err = deflateInit2(&c_stream, Z_DEFAULT_COMPRESSION,
|
|
|
|
Z_DEFLATED, UNIV_PAGE_SIZE_SHIFT,
|
|
|
|
MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
|
2005-10-27 11:48:10 +00:00
|
|
|
ut_a(err == Z_OK);
|
|
|
|
|
|
|
|
c_stream.next_out = buf;
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Subtract the space reserved for uncompressed data. */
|
2006-03-01 13:39:56 +00:00
|
|
|
/* Page header and the end marker of the modification log */
|
|
|
|
c_stream.avail_out = buf_end - buf - 1;
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Dense page directory and uncompressed columns, if any */
|
|
|
|
if (page_is_leaf(page)) {
|
2006-03-09 17:26:02 +00:00
|
|
|
if (dict_index_is_clust(index)) {
|
2006-09-19 10:14:07 +00:00
|
|
|
trx_id_col = dict_index_get_sys_col_pos(
|
|
|
|
index, DATA_TRX_ID);
|
2006-03-09 17:26:02 +00:00
|
|
|
ut_ad(trx_id_col > 0);
|
|
|
|
ut_ad(trx_id_col != ULINT_UNDEFINED);
|
|
|
|
|
2006-05-10 07:15:07 +00:00
|
|
|
slot_size = PAGE_ZIP_DIR_SLOT_SIZE
|
2006-08-29 09:30:31 +00:00
|
|
|
+ DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN;
|
2006-03-09 17:26:02 +00:00
|
|
|
} else {
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Signal the absence of trx_id
|
|
|
|
in page_zip_fields_encode() */
|
2006-08-29 09:30:31 +00:00
|
|
|
ut_ad(dict_index_get_sys_col_pos(index, DATA_TRX_ID)
|
|
|
|
== ULINT_UNDEFINED);
|
2006-02-10 15:06:17 +00:00
|
|
|
trx_id_col = 0;
|
2006-05-10 07:15:07 +00:00
|
|
|
slot_size = PAGE_ZIP_DIR_SLOT_SIZE;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
} else {
|
2006-05-10 07:15:07 +00:00
|
|
|
slot_size = PAGE_ZIP_DIR_SLOT_SIZE + REC_NODE_PTR_SIZE;
|
2006-02-10 15:06:17 +00:00
|
|
|
trx_id_col = ULINT_UNDEFINED;
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
2007-11-05 12:12:28 +00:00
|
|
|
if (UNIV_UNLIKELY(c_stream.avail_out <= n_dense * slot_size
|
|
|
|
+ 6/* sizeof(zlib header and footer) */)) {
|
2006-05-10 07:15:07 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
c_stream.avail_out -= n_dense * slot_size;
|
2006-09-19 10:14:07 +00:00
|
|
|
c_stream.avail_in = page_zip_fields_encode(n_fields, index,
|
|
|
|
trx_id_col, fields);
|
2006-02-10 15:06:17 +00:00
|
|
|
c_stream.next_in = fields;
|
2006-09-21 07:27:35 +00:00
|
|
|
if (UNIV_LIKELY(!trx_id_col)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
trx_id_col = ULINT_UNDEFINED;
|
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(c_stream.next_in, c_stream.avail_in);
|
2006-02-10 15:06:17 +00:00
|
|
|
err = deflate(&c_stream, Z_FULL_FLUSH);
|
|
|
|
if (err != Z_OK) {
|
|
|
|
goto zlib_error;
|
|
|
|
}
|
|
|
|
|
2006-02-27 09:53:58 +00:00
|
|
|
ut_ad(!c_stream.avail_in);
|
|
|
|
|
2006-02-28 20:37:29 +00:00
|
|
|
page_zip_dir_encode(page, buf_end, recs);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
c_stream.next_in = (byte*) page + PAGE_ZIP_START;
|
|
|
|
|
2006-02-28 20:37:29 +00:00
|
|
|
storage = buf_end - n_dense * PAGE_ZIP_DIR_SLOT_SIZE;
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-08-21 18:36:00 +00:00
|
|
|
/* Compress the records in heap_no order. */
|
2006-03-16 14:02:22 +00:00
|
|
|
if (UNIV_UNLIKELY(!n_dense)) {
|
2006-08-21 18:36:00 +00:00
|
|
|
} else if (!page_is_leaf(page)) {
|
|
|
|
/* This is a node pointer page. */
|
2008-02-19 14:42:52 +00:00
|
|
|
err = page_zip_compress_node_ptrs(LOGFILE
|
|
|
|
&c_stream, recs, n_dense,
|
2006-09-21 07:27:35 +00:00
|
|
|
index, storage, heap);
|
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
|
|
|
goto zlib_error;
|
|
|
|
}
|
2006-08-21 18:36:00 +00:00
|
|
|
} else if (UNIV_LIKELY(trx_id_col == ULINT_UNDEFINED)) {
|
2006-09-21 07:27:35 +00:00
|
|
|
/* This is a leaf page in a secondary index. */
|
2008-02-19 14:42:52 +00:00
|
|
|
err = page_zip_compress_sec(LOGFILE
|
|
|
|
&c_stream, recs, n_dense);
|
2006-09-21 07:27:35 +00:00
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
|
|
|
goto zlib_error;
|
|
|
|
}
|
2006-08-21 18:36:00 +00:00
|
|
|
} else {
|
|
|
|
/* This is a leaf page in a clustered index. */
|
2008-02-19 14:42:52 +00:00
|
|
|
err = page_zip_compress_clust(LOGFILE
|
|
|
|
&c_stream, recs, n_dense,
|
2006-09-21 07:27:35 +00:00
|
|
|
index, &n_blobs, trx_id_col,
|
2006-08-29 09:30:31 +00:00
|
|
|
buf_end - PAGE_ZIP_DIR_SLOT_SIZE
|
2006-10-19 07:52:28 +00:00
|
|
|
* page_get_n_recs(page),
|
2006-09-21 07:27:35 +00:00
|
|
|
storage, heap);
|
|
|
|
if (UNIV_UNLIKELY(err != Z_OK)) {
|
|
|
|
goto zlib_error;
|
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Finish the compression. */
|
|
|
|
ut_ad(!c_stream.avail_in);
|
2006-02-27 09:53:58 +00:00
|
|
|
/* Compress any trailing garbage, in case the last record was
|
2006-09-21 07:27:35 +00:00
|
|
|
allocated from an originally longer space on the free list,
|
|
|
|
or the data of the last record from page_zip_compress_sec(). */
|
2006-09-19 10:14:07 +00:00
|
|
|
c_stream.avail_in
|
2006-10-19 07:52:28 +00:00
|
|
|
= page_header_get_field(page, PAGE_HEAP_TOP)
|
2006-09-19 10:14:07 +00:00
|
|
|
- (c_stream.next_in - page);
|
2006-02-27 09:53:58 +00:00
|
|
|
ut_a(c_stream.avail_in <= UNIV_PAGE_SIZE - PAGE_ZIP_START - PAGE_DIR);
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(c_stream.next_in, c_stream.avail_in);
|
2005-10-27 11:48:10 +00:00
|
|
|
err = deflate(&c_stream, Z_FINISH);
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-02-27 09:53:58 +00:00
|
|
|
if (UNIV_UNLIKELY(err != Z_STREAM_END)) {
|
2005-11-24 14:13:10 +00:00
|
|
|
zlib_error:
|
2005-10-27 11:48:10 +00:00
|
|
|
deflateEnd(&c_stream);
|
2005-11-24 14:13:10 +00:00
|
|
|
mem_heap_free(heap);
|
2008-02-27 14:34:44 +00:00
|
|
|
err_exit:
|
2008-02-19 14:42:52 +00:00
|
|
|
#ifdef PAGE_ZIP_COMPRESS_DBG
|
|
|
|
if (logfile) {
|
|
|
|
fclose(logfile);
|
|
|
|
}
|
|
|
|
#endif /* PAGE_ZIP_COMPRESS_DBG */
|
branches/zip: Rename the INFORMATION_SCHEMA tables
INNODB_ZIP and INNODB_ZIP_RESET to
INNODB_COMPRESSION and INNODB_COMPRESSION_RESET,
and remove the statistics of the buddy system.
This change was discussed with Ken. It makes the tables shorter
and easier to understand. The removed data will be represented in
the tables INNODB_COMPRESSION_BUDDY and INNODB_COMPRESSION_BUDDY_RESET
that will be added later.
i_s_innodb_zip, i_s_innodb_zip_reset, i_s_zip_fields_info[],
i_s_zip_fill_low(), i_s_zip_fill(), i_s_zip_reset_fill(),
i_s_zip_init(), i_s_zip_reset_init(): Replace "zip" with "compression".
i_s_compression_fields_info[]: Remove "used", "free",
"relocated", "relocated_usec". In "compressed_usec" and "decompressed_usec",
replace microseconds with seconds ("usec" with "sec").
page_zip_decompress(): Correct a typo in the function comment.
PAGE_ZIP_SSIZE_BITS, PAGE_ZIP_NUM_SSIZE: New constants.
page_zip_stat_t, page_zip_stat: Statistics of the compression, grouped
by page size.
page_zip_simple_validate(): Assert that page_zip->ssize is reasonable.
2008-03-28 09:28:54 +00:00
|
|
|
page_zip_stat[page_zip->ssize - 1].compressed_usec
|
2008-02-27 14:34:44 +00:00
|
|
|
+= ut_time_us(NULL) - usec;
|
2005-10-27 11:48:10 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deflateEnd(&c_stream);
|
|
|
|
ut_a(err == Z_OK);
|
|
|
|
|
2006-02-27 09:53:58 +00:00
|
|
|
ut_ad(buf + c_stream.total_out == c_stream.next_out);
|
2006-02-28 20:37:29 +00:00
|
|
|
ut_ad((ulint) (storage - c_stream.next_out) >= c_stream.avail_out);
|
|
|
|
|
2007-10-31 20:49:16 +00:00
|
|
|
/* Valgrind believes that zlib does not initialize some bits
|
|
|
|
in the last 7 or 8 bytes of the stream. Make Valgrind happy. */
|
|
|
|
UNIV_MEM_VALID(buf, c_stream.total_out);
|
|
|
|
|
2006-03-01 13:39:56 +00:00
|
|
|
/* Zero out the area reserved for the modification log.
|
|
|
|
Space for the end marker of the modification log is not
|
|
|
|
included in avail_out. */
|
|
|
|
memset(c_stream.next_out, 0, c_stream.avail_out + 1/* end marker */);
|
2006-02-27 09:53:58 +00:00
|
|
|
|
2006-11-30 14:09:29 +00:00
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
page_zip->m_start =
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
page_zip->m_end = PAGE_DATA + c_stream.total_out;
|
|
|
|
page_zip->m_nonempty = FALSE;
|
2006-02-10 15:06:17 +00:00
|
|
|
page_zip->n_blobs = n_blobs;
|
2006-05-02 11:44:39 +00:00
|
|
|
/* Copy those header fields that will not be written
|
|
|
|
in buf_flush_init_for_writing() */
|
|
|
|
memcpy(page_zip->data + FIL_PAGE_PREV, page + FIL_PAGE_PREV,
|
2006-08-29 09:30:31 +00:00
|
|
|
FIL_PAGE_LSN - FIL_PAGE_PREV);
|
2006-05-02 11:44:39 +00:00
|
|
|
memcpy(page_zip->data + FIL_PAGE_TYPE, page + FIL_PAGE_TYPE, 2);
|
|
|
|
memcpy(page_zip->data + FIL_PAGE_DATA, page + FIL_PAGE_DATA,
|
2006-08-29 09:30:31 +00:00
|
|
|
PAGE_DATA - FIL_PAGE_DATA);
|
2006-02-28 20:37:29 +00:00
|
|
|
/* Copy the rest of the compressed page */
|
2006-11-27 13:44:32 +00:00
|
|
|
memcpy(page_zip->data + PAGE_DATA, buf,
|
|
|
|
page_zip_get_size(page_zip) - PAGE_DATA);
|
2005-11-24 14:13:10 +00:00
|
|
|
mem_heap_free(heap);
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2005-11-30 13:57:54 +00:00
|
|
|
ut_a(page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-05-16 14:17:43 +00:00
|
|
|
if (mtr) {
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2006-05-16 14:17:43 +00:00
|
|
|
page_zip_compress_write_log(page_zip, page, index, mtr);
|
2009-03-23 14:21:34 +00:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2006-05-16 14:17:43 +00:00
|
|
|
}
|
|
|
|
|
2007-10-31 16:14:18 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2007-10-31 14:27:59 +00:00
|
|
|
|
2008-02-19 14:42:52 +00:00
|
|
|
#ifdef PAGE_ZIP_COMPRESS_DBG
|
|
|
|
if (logfile) {
|
|
|
|
/* Record the compressed size of the block. */
|
|
|
|
byte sz[4];
|
|
|
|
mach_write_to_4(sz, c_stream.total_out);
|
|
|
|
fseek(logfile, UNIV_PAGE_SIZE, SEEK_SET);
|
|
|
|
fwrite(sz, 1, sizeof sz, logfile);
|
|
|
|
fclose(logfile);
|
|
|
|
}
|
|
|
|
#endif /* PAGE_ZIP_COMPRESS_DBG */
|
branches/zip: Rename the INFORMATION_SCHEMA tables
INNODB_ZIP and INNODB_ZIP_RESET to
INNODB_COMPRESSION and INNODB_COMPRESSION_RESET,
and remove the statistics of the buddy system.
This change was discussed with Ken. It makes the tables shorter
and easier to understand. The removed data will be represented in
the tables INNODB_COMPRESSION_BUDDY and INNODB_COMPRESSION_BUDDY_RESET
that will be added later.
i_s_innodb_zip, i_s_innodb_zip_reset, i_s_zip_fields_info[],
i_s_zip_fill_low(), i_s_zip_fill(), i_s_zip_reset_fill(),
i_s_zip_init(), i_s_zip_reset_init(): Replace "zip" with "compression".
i_s_compression_fields_info[]: Remove "used", "free",
"relocated", "relocated_usec". In "compressed_usec" and "decompressed_usec",
replace microseconds with seconds ("usec" with "sec").
page_zip_decompress(): Correct a typo in the function comment.
PAGE_ZIP_SSIZE_BITS, PAGE_ZIP_NUM_SSIZE: New constants.
page_zip_stat_t, page_zip_stat: Statistics of the compression, grouped
by page size.
page_zip_simple_validate(): Assert that page_zip->ssize is reasonable.
2008-03-28 09:28:54 +00:00
|
|
|
{
|
|
|
|
page_zip_stat_t* zip_stat
|
|
|
|
= &page_zip_stat[page_zip->ssize - 1];
|
|
|
|
zip_stat->compressed_ok++;
|
|
|
|
zip_stat->compressed_usec += ut_time_us(NULL) - usec;
|
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
return(TRUE);
|
2005-10-27 11:48:10 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 14:13:10 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Compare two page directory entries.
|
|
|
|
@return positive if rec1 > rec2 */
|
2005-11-24 14:13:10 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
page_zip_dir_cmp(
|
|
|
|
/*=============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const rec_t* rec1, /*!< in: rec1 */
|
|
|
|
const rec_t* rec2) /*!< in: rec2 */
|
2005-11-24 14:13:10 +00:00
|
|
|
{
|
|
|
|
return(rec1 > rec2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Sort the dense page directory by address (heap_no). */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
page_zip_dir_sort(
|
|
|
|
/*==============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
rec_t** arr, /*!< in/out: dense page directory */
|
|
|
|
rec_t** aux_arr,/*!< in/out: work area */
|
|
|
|
ulint low, /*!< in: lower bound of the sorting area, inclusive */
|
|
|
|
ulint high) /*!< in: upper bound of the sorting area, exclusive */
|
2005-11-24 14:13:10 +00:00
|
|
|
{
|
2007-05-28 07:42:28 +00:00
|
|
|
UT_SORT_FUNCTION_BODY(page_zip_dir_sort, arr, aux_arr, low, high,
|
|
|
|
page_zip_dir_cmp);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Deallocate the index information initialized by page_zip_fields_decode(). */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
page_zip_fields_free(
|
|
|
|
/*=================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
dict_index_t* index) /*!< in: dummy index to be freed */
|
2006-02-10 15:06:17 +00:00
|
|
|
{
|
|
|
|
if (index) {
|
|
|
|
dict_table_t* table = index->table;
|
|
|
|
mem_heap_free(index->heap);
|
|
|
|
mutex_free(&(table->autoinc_mutex));
|
|
|
|
mem_heap_free(table->heap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Read the index information for the compressed page.
|
|
|
|
@return own: dummy index describing the page, or NULL on error */
|
2006-02-10 15:06:17 +00:00
|
|
|
static
|
|
|
|
dict_index_t*
|
|
|
|
page_zip_fields_decode(
|
|
|
|
/*===================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const byte* buf, /*!< in: index information */
|
|
|
|
const byte* end, /*!< in: end of buf */
|
|
|
|
ulint* trx_id_col)/*!< in: NULL for non-leaf pages;
|
2006-02-10 15:06:17 +00:00
|
|
|
for leaf pages, pointer to where to store
|
|
|
|
the position of the trx_id column */
|
|
|
|
{
|
|
|
|
const byte* b;
|
|
|
|
ulint n;
|
|
|
|
ulint i;
|
2006-03-08 22:19:20 +00:00
|
|
|
ulint val;
|
2006-02-10 15:06:17 +00:00
|
|
|
dict_table_t* table;
|
|
|
|
dict_index_t* index;
|
|
|
|
|
|
|
|
/* Determine the number of fields. */
|
|
|
|
for (b = buf, n = 0; b < end; n++) {
|
|
|
|
if (*b++ & 0x80) {
|
|
|
|
b++; /* skip the second byte */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-08 22:19:20 +00:00
|
|
|
n--; /* n_nullable or trx_id */
|
|
|
|
|
2008-01-03 10:13:11 +00:00
|
|
|
if (UNIV_UNLIKELY(n > REC_MAX_N_FIELDS)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_fields_decode: n = %lu\n",
|
|
|
|
(ulong) n));
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(b > end)) {
|
|
|
|
|
|
|
|
page_zip_fail(("page_zip_fields_decode: %p > %p\n",
|
|
|
|
(const void*) b, (const void*) end));
|
2006-02-10 15:06:17 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2006-04-05 13:41:12 +00:00
|
|
|
table = dict_mem_table_create("ZIP_DUMMY", DICT_HDR_SPACE, n,
|
2006-08-29 09:30:31 +00:00
|
|
|
DICT_TF_COMPACT);
|
2006-02-10 15:06:17 +00:00
|
|
|
index = dict_mem_index_create("ZIP_DUMMY", "ZIP_DUMMY",
|
2006-08-29 09:30:31 +00:00
|
|
|
DICT_HDR_SPACE, 0, n);
|
2006-02-10 15:06:17 +00:00
|
|
|
index->table = table;
|
|
|
|
index->n_uniq = n;
|
|
|
|
/* avoid ut_ad(index->cached) in dict_index_get_n_unique_in_tree */
|
|
|
|
index->cached = TRUE;
|
|
|
|
|
|
|
|
/* Initialize the fields. */
|
|
|
|
for (b = buf, i = 0; i < n; i++) {
|
|
|
|
ulint mtype;
|
|
|
|
ulint len;
|
|
|
|
|
2006-03-08 22:19:20 +00:00
|
|
|
val = *b++;
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
if (UNIV_UNLIKELY(val & 0x80)) {
|
2006-02-27 09:53:58 +00:00
|
|
|
/* fixed length > 62 bytes */
|
2006-03-07 11:41:56 +00:00
|
|
|
val = (val & 0x7f) << 8 | *b++;
|
2006-02-27 09:53:58 +00:00
|
|
|
len = val >> 1;
|
|
|
|
mtype = DATA_FIXBINARY;
|
|
|
|
} else if (UNIV_UNLIKELY(val >= 126)) {
|
|
|
|
/* variable length with max > 255 bytes */
|
2006-02-10 15:06:17 +00:00
|
|
|
len = 0x7fff;
|
|
|
|
mtype = DATA_BINARY;
|
2006-02-27 09:53:58 +00:00
|
|
|
} else if (val <= 1) {
|
|
|
|
/* variable length with max <= 255 bytes */
|
|
|
|
len = 0;
|
|
|
|
mtype = DATA_BINARY;
|
|
|
|
} else {
|
|
|
|
/* fixed length < 62 bytes */
|
|
|
|
len = val >> 1;
|
2006-02-10 15:06:17 +00:00
|
|
|
mtype = DATA_FIXBINARY;
|
|
|
|
}
|
2006-02-27 09:53:58 +00:00
|
|
|
|
2007-01-30 09:24:18 +00:00
|
|
|
dict_mem_table_add_col(table, NULL, NULL, mtype,
|
2006-09-19 10:14:07 +00:00
|
|
|
val & 1 ? DATA_NOT_NULL : 0, len);
|
2006-10-19 07:27:26 +00:00
|
|
|
dict_index_add_col(index, table,
|
2006-08-29 09:30:31 +00:00
|
|
|
dict_table_get_nth_col(table, i), 0);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2006-03-08 22:19:20 +00:00
|
|
|
val = *b++;
|
|
|
|
if (UNIV_UNLIKELY(val & 0x80)) {
|
|
|
|
val = (val & 0x7f) << 8 | *b++;
|
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Decode the position of the trx_id column. */
|
|
|
|
if (trx_id_col) {
|
|
|
|
if (!val) {
|
|
|
|
val = ULINT_UNDEFINED;
|
2007-01-08 12:32:31 +00:00
|
|
|
} else if (UNIV_UNLIKELY(val >= n)) {
|
|
|
|
page_zip_fields_free(index);
|
|
|
|
index = NULL;
|
2006-08-21 09:30:48 +00:00
|
|
|
} else {
|
|
|
|
index->type = DICT_CLUSTERED;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*trx_id_col = val;
|
2006-03-08 22:19:20 +00:00
|
|
|
} else {
|
|
|
|
/* Decode the number of nullable fields. */
|
|
|
|
if (UNIV_UNLIKELY(index->n_nullable > val)) {
|
|
|
|
page_zip_fields_free(index);
|
|
|
|
index = NULL;
|
|
|
|
} else {
|
|
|
|
index->n_nullable = val;
|
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(b == end);
|
|
|
|
|
|
|
|
return(index);
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Populate the sparse page directory from the dense directory.
|
|
|
|
@return TRUE on success, FALSE on failure */
|
2005-11-24 14:13:10 +00:00
|
|
|
static
|
|
|
|
ibool
|
|
|
|
page_zip_dir_decode(
|
|
|
|
/*================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_zip_des_t* page_zip,/*!< in: dense page directory on
|
2005-11-24 14:13:10 +00:00
|
|
|
compressed page */
|
2009-05-25 05:30:14 +00:00
|
|
|
page_t* page, /*!< in: compact page with valid header;
|
2005-11-24 14:13:10 +00:00
|
|
|
out: trailer and sparse page directory
|
|
|
|
filled in */
|
2009-05-25 05:30:14 +00:00
|
|
|
rec_t** recs, /*!< out: dense page directory sorted by
|
2005-11-24 14:13:10 +00:00
|
|
|
ascending address (and heap_no) */
|
2009-05-25 05:30:14 +00:00
|
|
|
rec_t** recs_aux,/*!< in/out: scratch area */
|
|
|
|
ulint n_dense)/*!< in: number of user records, and
|
2005-11-24 14:13:10 +00:00
|
|
|
size of recs[] and recs_aux[] */
|
|
|
|
{
|
|
|
|
ulint i;
|
|
|
|
ulint n_recs;
|
|
|
|
byte* slot;
|
|
|
|
|
|
|
|
n_recs = page_get_n_recs(page);
|
|
|
|
|
2005-11-28 11:32:52 +00:00
|
|
|
if (UNIV_UNLIKELY(n_recs > n_dense)) {
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_dir_decode 1: %lu > %lu\n",
|
|
|
|
(ulong) n_recs, (ulong) n_dense));
|
2005-11-28 11:32:52 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2005-11-24 14:13:10 +00:00
|
|
|
/* Traverse the list of stored records in the sorting order,
|
|
|
|
starting from the first user record. */
|
|
|
|
|
|
|
|
slot = page + (UNIV_PAGE_SIZE - PAGE_DIR - PAGE_DIR_SLOT_SIZE);
|
|
|
|
UNIV_PREFETCH_RW(slot);
|
|
|
|
|
|
|
|
/* Zero out the page trailer. */
|
|
|
|
memset(slot + PAGE_DIR_SLOT_SIZE, 0, PAGE_DIR);
|
|
|
|
|
|
|
|
mach_write_to_2(slot, PAGE_NEW_INFIMUM);
|
|
|
|
slot -= PAGE_DIR_SLOT_SIZE;
|
|
|
|
UNIV_PREFETCH_RW(slot);
|
|
|
|
|
|
|
|
/* Initialize the sparse directory and copy the dense directory. */
|
|
|
|
for (i = 0; i < n_recs; i++) {
|
|
|
|
ulint offs = page_zip_dir_get(page_zip, i);
|
|
|
|
|
|
|
|
if (offs & PAGE_ZIP_DIR_SLOT_OWNED) {
|
|
|
|
mach_write_to_2(slot, offs & PAGE_ZIP_DIR_SLOT_MASK);
|
|
|
|
slot -= PAGE_DIR_SLOT_SIZE;
|
|
|
|
UNIV_PREFETCH_RW(slot);
|
|
|
|
}
|
|
|
|
|
2006-03-13 15:02:16 +00:00
|
|
|
if (UNIV_UNLIKELY((offs & PAGE_ZIP_DIR_SLOT_MASK)
|
2006-08-29 09:30:31 +00:00
|
|
|
< PAGE_ZIP_START + REC_N_NEW_EXTRA_BYTES)) {
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_dir_decode 2: %u %u %lx\n",
|
|
|
|
(unsigned) i, (unsigned) n_recs,
|
|
|
|
(ulong) offs));
|
2006-03-13 15:02:16 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2005-11-24 14:13:10 +00:00
|
|
|
recs[i] = page + (offs & PAGE_ZIP_DIR_SLOT_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
mach_write_to_2(slot, PAGE_NEW_SUPREMUM);
|
2007-11-15 10:56:34 +00:00
|
|
|
{
|
|
|
|
const page_dir_slot_t* last_slot = page_dir_get_nth_slot(
|
|
|
|
page, page_dir_get_n_slots(page) - 1);
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(slot != last_slot)) {
|
|
|
|
page_zip_fail(("page_zip_dir_decode 3: %p != %p\n",
|
|
|
|
(const void*) slot,
|
|
|
|
(const void*) last_slot));
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the rest of the dense directory. */
|
2005-11-28 11:32:52 +00:00
|
|
|
for (; i < n_dense; i++) {
|
2005-11-24 14:13:10 +00:00
|
|
|
ulint offs = page_zip_dir_get(page_zip, i);
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(offs & ~PAGE_ZIP_DIR_SLOT_MASK)) {
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_dir_decode 4: %u %u %lx\n",
|
|
|
|
(unsigned) i, (unsigned) n_dense,
|
|
|
|
(ulong) offs));
|
2005-11-24 14:13:10 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
recs[i] = page + offs;
|
|
|
|
}
|
|
|
|
|
2005-11-25 12:34:38 +00:00
|
|
|
if (UNIV_LIKELY(n_dense > 1)) {
|
2005-11-25 14:17:40 +00:00
|
|
|
page_zip_dir_sort(recs, recs_aux, 0, n_dense);
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Initialize the REC_N_NEW_EXTRA_BYTES of each record.
|
|
|
|
@return TRUE on success, FALSE on failure */
|
2005-11-24 14:13:10 +00:00
|
|
|
static
|
|
|
|
ibool
|
|
|
|
page_zip_set_extra_bytes(
|
|
|
|
/*=====================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_zip_des_t* page_zip,/*!< in: compressed page */
|
|
|
|
page_t* page, /*!< in/out: uncompressed page */
|
|
|
|
ulint info_bits)/*!< in: REC_INFO_MIN_REC_FLAG or 0 */
|
2005-11-24 14:13:10 +00:00
|
|
|
{
|
|
|
|
ulint n;
|
|
|
|
ulint i;
|
|
|
|
ulint n_owned = 1;
|
|
|
|
ulint offs;
|
|
|
|
rec_t* rec;
|
|
|
|
|
|
|
|
n = page_get_n_recs(page);
|
|
|
|
rec = page + PAGE_NEW_INFIMUM;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
offs = page_zip_dir_get(page_zip, i);
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(offs & PAGE_ZIP_DIR_SLOT_DEL)) {
|
|
|
|
info_bits |= REC_INFO_DELETED_FLAG;
|
|
|
|
}
|
|
|
|
if (UNIV_UNLIKELY(offs & PAGE_ZIP_DIR_SLOT_OWNED)) {
|
|
|
|
info_bits |= n_owned;
|
|
|
|
n_owned = 1;
|
|
|
|
} else {
|
|
|
|
n_owned++;
|
|
|
|
}
|
|
|
|
offs &= PAGE_ZIP_DIR_SLOT_MASK;
|
2005-11-25 12:34:38 +00:00
|
|
|
if (UNIV_UNLIKELY(offs < PAGE_ZIP_START
|
2006-08-29 09:30:31 +00:00
|
|
|
+ REC_N_NEW_EXTRA_BYTES)) {
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_set_extra_bytes 1:"
|
|
|
|
" %u %u %lx\n",
|
|
|
|
(unsigned) i, (unsigned) n,
|
|
|
|
(ulong) offs));
|
2005-11-24 14:13:10 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2005-11-25 12:34:38 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
rec_set_next_offs_new(rec, offs);
|
2005-11-28 11:32:52 +00:00
|
|
|
rec = page + offs;
|
branches/zip: Fix most MSVC (Windows) compilation warnings.
lock_get_table(), locks_row_eq_lock(), buf_page_get_mutex(): Add return
after ut_error. On Windows, ut_error is not declared as "noreturn".
Add explicit type casts when assigning ulint to byte to get rid of
"possible loss of precision" warnings.
struct i_s_table_cache_struct: Declare rows_used, rows_allocd as ulint
instead of ullint. 32 bits should be enough.
fill_innodb_trx_from_cache(), i_s_zip_fill_low(): Cast 64-bit unsigned
integers to longlong when calling Field::store(longlong, bool is_unsigned).
Otherwise, the compiler would implicitly convert them to double and
invoke Field::store(double) instead.
recv_truncate_group(), recv_copy_group(), recv_calc_lsn_on_data_add():
Cast ib_uint64_t expressions to ulint to get rid of "possible loss of
precision" warnings. (There should not be any loss of precision in
these cases.)
log_close(), log_checkpoint_margin(): Declare some variables as ib_uint64_t
instead of ulint, so that there won't be any potential loss of precision.
mach_write_ull(): Cast the second argument of mach_write_to_4() to ulint.
OS_FILE_FROM_FD(): Cast the return value of _get_osfhandle() to HANDLE.
row_merge_dict_table_get_index(): Cast the parameter of mem_free() to (void*)
in order to get rid of the bogus MSVC warning C4090, which has been reported
as MSVC bug 101661:
<http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101661>
row_mysql_read_blob_ref(): To get rid of a bogus MSVC warning C4090,
drop a const qualifier.
2008-03-04 08:57:07 +00:00
|
|
|
rec[-REC_N_NEW_EXTRA_BYTES] = (byte) info_bits;
|
2005-11-25 12:34:38 +00:00
|
|
|
info_bits = 0;
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the next pointer of the last user record. */
|
2006-02-10 15:06:17 +00:00
|
|
|
rec_set_next_offs_new(rec, PAGE_NEW_SUPREMUM);
|
2005-11-24 14:13:10 +00:00
|
|
|
|
|
|
|
/* Set n_owned of the supremum record. */
|
branches/zip: Fix most MSVC (Windows) compilation warnings.
lock_get_table(), locks_row_eq_lock(), buf_page_get_mutex(): Add return
after ut_error. On Windows, ut_error is not declared as "noreturn".
Add explicit type casts when assigning ulint to byte to get rid of
"possible loss of precision" warnings.
struct i_s_table_cache_struct: Declare rows_used, rows_allocd as ulint
instead of ullint. 32 bits should be enough.
fill_innodb_trx_from_cache(), i_s_zip_fill_low(): Cast 64-bit unsigned
integers to longlong when calling Field::store(longlong, bool is_unsigned).
Otherwise, the compiler would implicitly convert them to double and
invoke Field::store(double) instead.
recv_truncate_group(), recv_copy_group(), recv_calc_lsn_on_data_add():
Cast ib_uint64_t expressions to ulint to get rid of "possible loss of
precision" warnings. (There should not be any loss of precision in
these cases.)
log_close(), log_checkpoint_margin(): Declare some variables as ib_uint64_t
instead of ulint, so that there won't be any potential loss of precision.
mach_write_ull(): Cast the second argument of mach_write_to_4() to ulint.
OS_FILE_FROM_FD(): Cast the return value of _get_osfhandle() to HANDLE.
row_merge_dict_table_get_index(): Cast the parameter of mem_free() to (void*)
in order to get rid of the bogus MSVC warning C4090, which has been reported
as MSVC bug 101661:
<http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101661>
row_mysql_read_blob_ref(): To get rid of a bogus MSVC warning C4090,
drop a const qualifier.
2008-03-04 08:57:07 +00:00
|
|
|
page[PAGE_NEW_SUPREMUM - REC_N_NEW_EXTRA_BYTES] = (byte) n_owned;
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2005-11-25 14:17:40 +00:00
|
|
|
/* The dense directory excludes the infimum and supremum records. */
|
2006-10-20 12:45:53 +00:00
|
|
|
n = page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW;
|
2005-11-25 14:17:40 +00:00
|
|
|
|
|
|
|
if (i >= n) {
|
2007-11-15 10:56:34 +00:00
|
|
|
if (UNIV_LIKELY(i == n)) {
|
|
|
|
return(TRUE);
|
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_set_extra_bytes 2: %u != %u\n",
|
|
|
|
(unsigned) i, (unsigned) n));
|
|
|
|
return(FALSE);
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
offs = page_zip_dir_get(page_zip, i);
|
|
|
|
|
|
|
|
/* Set the extra bytes of deleted records on the free list. */
|
|
|
|
for (;;) {
|
|
|
|
if (UNIV_UNLIKELY(!offs)
|
|
|
|
|| UNIV_UNLIKELY(offs & ~PAGE_ZIP_DIR_SLOT_MASK)) {
|
2007-11-15 10:56:34 +00:00
|
|
|
|
|
|
|
page_zip_fail(("page_zip_set_extra_bytes 3: %lx\n",
|
|
|
|
(ulong) offs));
|
2005-11-24 14:13:10 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
rec = page + offs;
|
|
|
|
rec[-REC_N_NEW_EXTRA_BYTES] = 0; /* info_bits and n_owned */
|
|
|
|
|
2005-11-25 14:17:40 +00:00
|
|
|
if (++i == n) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
offs = page_zip_dir_get(page_zip, i);
|
2006-02-10 15:06:17 +00:00
|
|
|
rec_set_next_offs_new(rec, offs);
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate the free list. */
|
|
|
|
rec[-REC_N_NEW_EXTRA_BYTES] = 0; /* info_bits and n_owned */
|
2006-02-10 15:06:17 +00:00
|
|
|
rec_set_next_offs_new(rec, 0);
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2005-11-25 14:17:40 +00:00
|
|
|
return(TRUE);
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Apply the modification log to a record containing externally stored
|
2009-05-25 05:30:14 +00:00
|
|
|
columns. Do not copy the fields that are stored separately.
|
|
|
|
@return pointer to modification log, or NULL on failure */
|
2007-02-05 11:19:25 +00:00
|
|
|
static
|
|
|
|
const byte*
|
|
|
|
page_zip_apply_log_ext(
|
|
|
|
/*===================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
rec_t* rec, /*!< in/out: record */
|
|
|
|
const ulint* offsets, /*!< in: rec_get_offsets(rec) */
|
|
|
|
ulint trx_id_col, /*!< in: position of of DB_TRX_ID */
|
|
|
|
const byte* data, /*!< in: modification log */
|
|
|
|
const byte* end) /*!< in: end of modification log */
|
2007-02-05 11:19:25 +00:00
|
|
|
{
|
|
|
|
ulint i;
|
|
|
|
ulint len;
|
|
|
|
byte* next_out = rec;
|
|
|
|
|
|
|
|
/* Check if there are any externally stored columns.
|
|
|
|
For each externally stored column, skip the
|
|
|
|
BTR_EXTERN_FIELD_REF. */
|
|
|
|
|
|
|
|
for (i = 0; i < rec_offs_n_fields(offsets); i++) {
|
|
|
|
byte* dst;
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(i == trx_id_col)) {
|
|
|
|
/* Skip trx_id and roll_ptr */
|
|
|
|
dst = rec_get_nth_field(rec, offsets,
|
|
|
|
i, &len);
|
2007-12-13 11:32:11 +00:00
|
|
|
if (UNIV_UNLIKELY(dst - next_out >= end - data)
|
2007-02-05 11:19:25 +00:00
|
|
|
|| UNIV_UNLIKELY
|
2007-12-13 11:32:11 +00:00
|
|
|
(len < (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN))
|
|
|
|
|| rec_offs_nth_extern(offsets, i)) {
|
|
|
|
page_zip_fail(("page_zip_apply_log_ext:"
|
|
|
|
" trx_id len %lu,"
|
|
|
|
" %p - %p >= %p - %p\n",
|
|
|
|
(ulong) len,
|
|
|
|
(const void*) dst,
|
|
|
|
(const void*) next_out,
|
|
|
|
(const void*) end,
|
|
|
|
(const void*) data));
|
2007-02-05 11:19:25 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(next_out, data, dst - next_out);
|
|
|
|
data += dst - next_out;
|
|
|
|
next_out = dst + (DATA_TRX_ID_LEN
|
|
|
|
+ DATA_ROLL_PTR_LEN);
|
|
|
|
} else if (rec_offs_nth_extern(offsets, i)) {
|
|
|
|
dst = rec_get_nth_field(rec, offsets,
|
|
|
|
i, &len);
|
|
|
|
ut_ad(len
|
|
|
|
>= BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
|
|
|
|
len += dst - next_out
|
|
|
|
- BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(data + len >= end)) {
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log_ext: "
|
|
|
|
"ext %p+%lu >= %p\n",
|
|
|
|
(const void*) data,
|
|
|
|
(ulong) len,
|
|
|
|
(const void*) end));
|
2007-02-05 11:19:25 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(next_out, data, len);
|
|
|
|
data += len;
|
|
|
|
next_out += len
|
|
|
|
+ BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the last bytes of the record. */
|
|
|
|
len = rec_get_end(rec, offsets) - next_out;
|
|
|
|
if (UNIV_UNLIKELY(data + len >= end)) {
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log_ext: "
|
|
|
|
"last %p+%lu >= %p\n",
|
|
|
|
(const void*) data,
|
|
|
|
(ulong) len,
|
|
|
|
(const void*) end));
|
2007-02-05 11:19:25 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
memcpy(next_out, data, len);
|
|
|
|
data += len;
|
|
|
|
|
|
|
|
return(data);
|
|
|
|
}
|
|
|
|
|
2005-11-18 07:42:02 +00:00
|
|
|
/**************************************************************************
|
2006-03-06 21:00:05 +00:00
|
|
|
Apply the modification log to an uncompressed page.
|
2009-05-25 05:30:14 +00:00
|
|
|
Do not copy the fields that are stored separately.
|
|
|
|
@return pointer to end of modification log, or NULL on failure */
|
2005-11-18 07:42:02 +00:00
|
|
|
static
|
|
|
|
const byte*
|
|
|
|
page_zip_apply_log(
|
|
|
|
/*===============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const byte* data, /*!< in: modification log */
|
|
|
|
ulint size, /*!< in: maximum length of the log, in bytes */
|
|
|
|
rec_t** recs, /*!< in: dense page directory,
|
2006-10-20 12:45:53 +00:00
|
|
|
sorted by address (indexed by
|
|
|
|
heap_no - PAGE_HEAP_NO_USER_LOW) */
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint n_dense,/*!< in: size of recs[] */
|
|
|
|
ulint trx_id_col,/*!< in: column number of trx_id in the index,
|
2006-03-16 14:02:22 +00:00
|
|
|
or ULINT_UNDEFINED if none */
|
2006-02-10 15:06:17 +00:00
|
|
|
ulint heap_status,
|
2009-05-25 05:30:14 +00:00
|
|
|
/*!< in: heap_no and status bits for
|
2006-02-10 15:06:17 +00:00
|
|
|
the next record to uncompress */
|
2009-05-25 05:30:14 +00:00
|
|
|
dict_index_t* index, /*!< in: index of the page */
|
|
|
|
ulint* offsets)/*!< in/out: work area for
|
2006-02-10 15:06:17 +00:00
|
|
|
rec_get_offsets_reverse() */
|
2005-11-18 07:42:02 +00:00
|
|
|
{
|
2005-11-28 11:32:52 +00:00
|
|
|
const byte* const end = data + size;
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
for (;;) {
|
2006-03-01 13:39:56 +00:00
|
|
|
ulint val;
|
2006-02-10 15:06:17 +00:00
|
|
|
rec_t* rec;
|
|
|
|
ulint len;
|
|
|
|
ulint hs;
|
|
|
|
|
2006-03-01 13:39:56 +00:00
|
|
|
val = *data++;
|
|
|
|
if (UNIV_UNLIKELY(!val)) {
|
2006-03-06 21:00:05 +00:00
|
|
|
return(data - 1);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2006-03-01 13:39:56 +00:00
|
|
|
if (val & 0x80) {
|
2006-03-07 11:41:56 +00:00
|
|
|
val = (val & 0x7f) << 8 | *data++;
|
2006-03-09 17:26:02 +00:00
|
|
|
if (UNIV_UNLIKELY(!val)) {
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log:"
|
|
|
|
" invalid val %x%x\n",
|
|
|
|
data[-2], data[-1]));
|
2006-03-09 17:26:02 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
2006-03-01 13:39:56 +00:00
|
|
|
}
|
|
|
|
if (UNIV_UNLIKELY(data >= end)) {
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log: %p >= %p\n",
|
|
|
|
(const void*) data,
|
|
|
|
(const void*) end));
|
2005-11-18 07:42:02 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
2006-03-14 14:38:45 +00:00
|
|
|
if (UNIV_UNLIKELY((val >> 1) > n_dense)) {
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log: %lu>>1 > %lu\n",
|
|
|
|
(ulong) val, (ulong) n_dense));
|
2005-11-18 07:42:02 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
2006-03-01 13:39:56 +00:00
|
|
|
|
|
|
|
/* Determine the heap number and status bits of the record. */
|
2006-03-14 14:38:45 +00:00
|
|
|
rec = recs[(val >> 1) - 1];
|
|
|
|
|
|
|
|
hs = ((val >> 1) + 1) << REC_HEAP_NO_SHIFT;
|
2006-02-10 15:06:17 +00:00
|
|
|
hs |= heap_status & ((1 << REC_HEAP_NO_SHIFT) - 1);
|
|
|
|
|
|
|
|
/* This may either be an old record that is being
|
|
|
|
overwritten (updated in place, or allocated from
|
|
|
|
the free list), or a new record, with the next
|
|
|
|
available_heap_no. */
|
|
|
|
if (UNIV_UNLIKELY(hs > heap_status)) {
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log: %lu > %lu\n",
|
|
|
|
(ulong) hs, (ulong) heap_status));
|
2006-02-10 15:06:17 +00:00
|
|
|
return(NULL);
|
|
|
|
} else if (hs == heap_status) {
|
|
|
|
/* A new record was allocated from the heap. */
|
2007-11-07 13:50:53 +00:00
|
|
|
if (UNIV_UNLIKELY(val & 1)) {
|
|
|
|
/* Only existing records may be cleared. */
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log:"
|
|
|
|
" attempting to create"
|
|
|
|
" deleted rec %lu\n",
|
|
|
|
(ulong) hs));
|
2007-11-07 13:50:53 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
2006-03-03 14:32:27 +00:00
|
|
|
heap_status += 1 << REC_HEAP_NO_SHIFT;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2006-03-08 22:19:20 +00:00
|
|
|
mach_write_to_2(rec - REC_NEW_HEAP_NO, hs);
|
2007-11-07 13:50:53 +00:00
|
|
|
|
|
|
|
if (val & 1) {
|
|
|
|
/* Clear the data bytes of the record. */
|
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
ulint* offs;
|
|
|
|
offs = rec_get_offsets(rec, index, offsets,
|
|
|
|
ULINT_UNDEFINED, &heap);
|
|
|
|
memset(rec, 0, rec_offs_data_size(offs));
|
|
|
|
|
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-03-08 22:19:20 +00:00
|
|
|
#if REC_STATUS_NODE_PTR != TRUE
|
|
|
|
# error "REC_STATUS_NODE_PTR != TRUE"
|
|
|
|
#endif
|
2006-02-10 15:06:17 +00:00
|
|
|
rec_get_offsets_reverse(data, index,
|
2006-08-29 09:30:31 +00:00
|
|
|
hs & REC_STATUS_NODE_PTR,
|
|
|
|
offsets);
|
2006-03-03 14:32:27 +00:00
|
|
|
rec_offs_make_valid(rec, index, offsets);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
/* Copy the extra bytes (backwards). */
|
|
|
|
{
|
2006-03-07 09:41:31 +00:00
|
|
|
byte* start = rec_get_start(rec, offsets);
|
|
|
|
byte* b = rec - REC_N_NEW_EXTRA_BYTES;
|
|
|
|
while (b != start) {
|
|
|
|
*--b = *data++;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the data bytes. */
|
2007-02-05 11:19:25 +00:00
|
|
|
if (UNIV_UNLIKELY(rec_offs_any_extern(offsets))) {
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Non-leaf nodes should not contain any
|
|
|
|
externally stored columns. */
|
2007-02-05 11:19:25 +00:00
|
|
|
if (UNIV_UNLIKELY(hs & REC_STATUS_NODE_PTR)) {
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log: "
|
|
|
|
"%lu&REC_STATUS_NODE_PTR\n",
|
|
|
|
(ulong) hs));
|
2006-02-10 15:06:17 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
2005-11-18 07:42:02 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
data = page_zip_apply_log_ext(
|
|
|
|
rec, offsets, trx_id_col, data, end);
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(!data)) {
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
} else if (UNIV_UNLIKELY(hs & REC_STATUS_NODE_PTR)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
len = rec_offs_data_size(offsets)
|
2006-08-29 09:30:31 +00:00
|
|
|
- REC_NODE_PTR_SIZE;
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Copy the data bytes, except node_ptr. */
|
|
|
|
if (UNIV_UNLIKELY(data + len >= end)) {
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log: "
|
2008-01-03 10:13:11 +00:00
|
|
|
"node_ptr %p+%lu >= %p\n",
|
2007-12-13 11:32:11 +00:00
|
|
|
(const void*) data,
|
|
|
|
(ulong) len,
|
|
|
|
(const void*) end));
|
2006-02-10 15:06:17 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
memcpy(rec, data, len);
|
|
|
|
data += len;
|
2007-02-05 11:19:25 +00:00
|
|
|
} else if (UNIV_LIKELY(trx_id_col == ULINT_UNDEFINED)) {
|
|
|
|
len = rec_offs_data_size(offsets);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
/* Copy all data bytes of
|
|
|
|
a record in a secondary index. */
|
|
|
|
if (UNIV_UNLIKELY(data + len >= end)) {
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log: "
|
2008-01-03 10:13:11 +00:00
|
|
|
"sec %p+%lu >= %p\n",
|
2007-12-13 11:32:11 +00:00
|
|
|
(const void*) data,
|
|
|
|
(ulong) len,
|
|
|
|
(const void*) end));
|
2007-02-05 11:19:25 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
2006-03-06 21:00:05 +00:00
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
memcpy(rec, data, len);
|
|
|
|
data += len;
|
|
|
|
} else {
|
|
|
|
/* Skip DB_TRX_ID and DB_ROLL_PTR. */
|
|
|
|
ulint l = rec_get_nth_field_offs(offsets,
|
|
|
|
trx_id_col, &len);
|
|
|
|
byte* b;
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(data + l >= end)
|
|
|
|
|| UNIV_UNLIKELY(len < (DATA_TRX_ID_LEN
|
|
|
|
+ DATA_ROLL_PTR_LEN))) {
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log: "
|
2008-01-03 10:13:11 +00:00
|
|
|
"trx_id %p+%lu >= %p\n",
|
2007-12-13 11:32:11 +00:00
|
|
|
(const void*) data,
|
|
|
|
(ulong) l,
|
|
|
|
(const void*) end));
|
2007-02-05 11:19:25 +00:00
|
|
|
return(NULL);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2007-02-05 11:19:25 +00:00
|
|
|
/* Copy any preceding data bytes. */
|
|
|
|
memcpy(rec, data, l);
|
|
|
|
data += l;
|
|
|
|
|
|
|
|
/* Copy any bytes following DB_TRX_ID, DB_ROLL_PTR. */
|
|
|
|
b = rec + l + (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
|
|
|
len = rec_get_end(rec, offsets) - b;
|
2006-02-10 15:06:17 +00:00
|
|
|
if (UNIV_UNLIKELY(data + len >= end)) {
|
2007-12-13 11:32:11 +00:00
|
|
|
page_zip_fail(("page_zip_apply_log: "
|
2008-01-03 10:13:11 +00:00
|
|
|
"clust %p+%lu >= %p\n",
|
2007-12-13 11:32:11 +00:00
|
|
|
(const void*) data,
|
|
|
|
(ulong) len,
|
|
|
|
(const void*) end));
|
2006-02-10 15:06:17 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
2007-02-05 11:19:25 +00:00
|
|
|
memcpy(b, data, len);
|
2006-02-10 15:06:17 +00:00
|
|
|
data += len;
|
|
|
|
}
|
2005-11-18 07:42:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Decompress the records of a node pointer page.
|
|
|
|
@return TRUE on success, FALSE on failure */
|
2006-09-21 19:09:25 +00:00
|
|
|
static
|
2005-10-27 11:48:10 +00:00
|
|
|
ibool
|
2006-09-21 19:09:25 +00:00
|
|
|
page_zip_decompress_node_ptrs(
|
|
|
|
/*==========================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip, /*!< in/out: compressed page */
|
|
|
|
z_stream* d_stream, /*!< in/out: compressed page stream */
|
|
|
|
rec_t** recs, /*!< in: dense page directory
|
2006-09-21 19:09:25 +00:00
|
|
|
sorted by address */
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint n_dense, /*!< in: size of recs[] */
|
|
|
|
dict_index_t* index, /*!< in: the index of the page */
|
|
|
|
ulint* offsets, /*!< in/out: temporary offsets */
|
|
|
|
mem_heap_t* heap) /*!< in: temporary memory heap */
|
2005-10-27 11:48:10 +00:00
|
|
|
{
|
2006-09-21 19:09:25 +00:00
|
|
|
ulint heap_status = REC_STATUS_NODE_PTR
|
2006-10-20 12:45:53 +00:00
|
|
|
| PAGE_HEAP_NO_USER_LOW << REC_HEAP_NO_SHIFT;
|
2006-03-16 14:02:22 +00:00
|
|
|
ulint slot;
|
2006-02-10 15:06:17 +00:00
|
|
|
const byte* storage;
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Subtract the space reserved for uncompressed data. */
|
|
|
|
d_stream->avail_in -= n_dense
|
|
|
|
* (PAGE_ZIP_DIR_SLOT_SIZE + REC_NODE_PTR_SIZE);
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Decompress the records in heap_no order. */
|
|
|
|
for (slot = 0; slot < n_dense; slot++) {
|
|
|
|
rec_t* rec = recs[slot];
|
|
|
|
|
|
|
|
d_stream->avail_out = rec - REC_N_NEW_EXTRA_BYTES
|
|
|
|
- d_stream->next_out;
|
|
|
|
|
|
|
|
ut_ad(d_stream->avail_out < UNIV_PAGE_SIZE
|
|
|
|
- PAGE_ZIP_START - PAGE_DIR);
|
|
|
|
switch (inflate(d_stream, Z_SYNC_FLUSH)) {
|
|
|
|
case Z_STREAM_END:
|
|
|
|
/* Apparently, n_dense has grown
|
|
|
|
since the time the page was last compressed. */
|
|
|
|
goto zlib_done;
|
|
|
|
case Z_OK:
|
|
|
|
case Z_BUF_ERROR:
|
|
|
|
if (!d_stream->avail_out) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
default:
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_node_ptrs:"
|
|
|
|
" 1 inflate(Z_SYNC_FLUSH)=%s\n",
|
|
|
|
d_stream->msg));
|
2006-09-21 19:09:25 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(d_stream->next_out == rec - REC_N_NEW_EXTRA_BYTES);
|
|
|
|
/* Prepare to decompress the data bytes. */
|
|
|
|
d_stream->next_out = rec;
|
|
|
|
/* Set heap_no and the status bits. */
|
|
|
|
mach_write_to_2(rec - REC_NEW_HEAP_NO, heap_status);
|
|
|
|
heap_status += 1 << REC_HEAP_NO_SHIFT;
|
|
|
|
|
|
|
|
/* Read the offsets. The status bits are needed here. */
|
|
|
|
offsets = rec_get_offsets(rec, index, offsets,
|
|
|
|
ULINT_UNDEFINED, &heap);
|
|
|
|
|
|
|
|
/* Non-leaf nodes should not have any externally
|
|
|
|
stored columns. */
|
|
|
|
ut_ad(!rec_offs_any_extern(offsets));
|
|
|
|
|
|
|
|
/* Decompress the data bytes, except node_ptr. */
|
|
|
|
d_stream->avail_out = rec_offs_data_size(offsets)
|
|
|
|
- REC_NODE_PTR_SIZE;
|
|
|
|
|
|
|
|
switch (inflate(d_stream, Z_SYNC_FLUSH)) {
|
|
|
|
case Z_STREAM_END:
|
|
|
|
goto zlib_done;
|
|
|
|
case Z_OK:
|
|
|
|
case Z_BUF_ERROR:
|
|
|
|
if (!d_stream->avail_out) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
default:
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_node_ptrs:"
|
|
|
|
" 2 inflate(Z_SYNC_FLUSH)=%s\n",
|
|
|
|
d_stream->msg));
|
2006-09-21 19:09:25 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the node pointer in case the record
|
|
|
|
will be deleted and the space will be reallocated
|
|
|
|
to a smaller record. */
|
|
|
|
memset(d_stream->next_out, 0, REC_NODE_PTR_SIZE);
|
|
|
|
d_stream->next_out += REC_NODE_PTR_SIZE;
|
|
|
|
|
|
|
|
ut_ad(d_stream->next_out == rec_get_end(rec, offsets));
|
2006-03-01 13:39:56 +00:00
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Decompress any trailing garbage, in case the last record was
|
|
|
|
allocated from an originally longer space on the free list. */
|
|
|
|
d_stream->avail_out = page_header_get_field(page_zip->data,
|
|
|
|
PAGE_HEAP_TOP)
|
|
|
|
- page_offset(d_stream->next_out);
|
|
|
|
if (UNIV_UNLIKELY(d_stream->avail_out > UNIV_PAGE_SIZE
|
|
|
|
- PAGE_ZIP_START - PAGE_DIR)) {
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_node_ptrs:"
|
|
|
|
" avail_out = %u\n",
|
|
|
|
d_stream->avail_out));
|
2006-09-21 19:09:25 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
if (UNIV_UNLIKELY(inflate(d_stream, Z_FINISH) != Z_STREAM_END)) {
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_node_ptrs:"
|
|
|
|
" inflate(Z_FINISH)=%s\n",
|
|
|
|
d_stream->msg));
|
2006-09-21 19:09:25 +00:00
|
|
|
zlib_error:
|
|
|
|
inflateEnd(d_stream);
|
2005-11-24 14:13:10 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Note that d_stream->avail_out > 0 may hold here
|
|
|
|
if the modification log is nonempty. */
|
|
|
|
|
|
|
|
zlib_done:
|
|
|
|
if (UNIV_UNLIKELY(inflateEnd(d_stream) != Z_OK)) {
|
|
|
|
ut_error;
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
{
|
|
|
|
page_t* page = page_align(d_stream->next_out);
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Clear the unused heap space on the uncompressed page. */
|
|
|
|
memset(d_stream->next_out, 0,
|
|
|
|
page_dir_get_nth_slot(page,
|
|
|
|
page_dir_get_n_slots(page) - 1)
|
|
|
|
- d_stream->next_out);
|
2006-03-03 14:32:27 +00:00
|
|
|
}
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-11-30 14:09:29 +00:00
|
|
|
#ifdef UNIV_DEBUG
|
2006-09-21 19:09:25 +00:00
|
|
|
page_zip->m_start = PAGE_DATA + d_stream->total_in;
|
2006-11-30 14:09:29 +00:00
|
|
|
#endif /* UNIV_DEBUG */
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Apply the modification log. */
|
|
|
|
{
|
|
|
|
const byte* mod_log_ptr;
|
2006-11-30 14:09:29 +00:00
|
|
|
mod_log_ptr = page_zip_apply_log(d_stream->next_in,
|
2006-09-21 19:09:25 +00:00
|
|
|
d_stream->avail_in + 1,
|
|
|
|
recs, n_dense,
|
|
|
|
ULINT_UNDEFINED, heap_status,
|
|
|
|
index, offsets);
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
if (UNIV_UNLIKELY(!mod_log_ptr)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
page_zip->m_end = mod_log_ptr - page_zip->data;
|
2006-11-30 14:09:29 +00:00
|
|
|
page_zip->m_nonempty = mod_log_ptr != d_stream->next_in;
|
2007-12-13 11:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY
|
|
|
|
(page_zip_get_trailer_len(page_zip,
|
|
|
|
dict_index_is_clust(index), NULL)
|
|
|
|
+ page_zip->m_end >= page_zip_get_size(page_zip))) {
|
|
|
|
page_zip_fail(("page_zip_decompress_node_ptrs:"
|
|
|
|
" %lu + %lu >= %lu, %lu\n",
|
|
|
|
(ulong) page_zip_get_trailer_len(
|
2007-12-13 12:45:43 +00:00
|
|
|
page_zip, dict_index_is_clust(index),
|
|
|
|
NULL),
|
2007-12-13 11:32:11 +00:00
|
|
|
(ulong) page_zip->m_end,
|
|
|
|
(ulong) page_zip_get_size(page_zip),
|
2007-12-13 12:45:43 +00:00
|
|
|
(ulong) dict_index_is_clust(index)));
|
2007-12-13 11:32:11 +00:00
|
|
|
return(FALSE);
|
2006-09-21 19:09:25 +00:00
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Restore the uncompressed columns in heap_no order. */
|
2006-11-27 13:44:32 +00:00
|
|
|
storage = page_zip->data + page_zip_get_size(page_zip)
|
2006-09-21 19:09:25 +00:00
|
|
|
- n_dense * PAGE_ZIP_DIR_SLOT_SIZE;
|
|
|
|
|
|
|
|
for (slot = 0; slot < n_dense; slot++) {
|
|
|
|
rec_t* rec = recs[slot];
|
|
|
|
|
|
|
|
offsets = rec_get_offsets(rec, index, offsets,
|
|
|
|
ULINT_UNDEFINED, &heap);
|
|
|
|
/* Non-leaf nodes should not have any externally
|
|
|
|
stored columns. */
|
|
|
|
ut_ad(!rec_offs_any_extern(offsets));
|
|
|
|
storage -= REC_NODE_PTR_SIZE;
|
|
|
|
|
|
|
|
memcpy(rec_get_end(rec, offsets) - REC_NODE_PTR_SIZE,
|
|
|
|
storage, REC_NODE_PTR_SIZE);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
return(TRUE);
|
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Decompress the records of a leaf node of a secondary index.
|
|
|
|
@return TRUE on success, FALSE on failure */
|
2006-09-21 19:09:25 +00:00
|
|
|
static
|
|
|
|
ibool
|
|
|
|
page_zip_decompress_sec(
|
|
|
|
/*====================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip, /*!< in/out: compressed page */
|
|
|
|
z_stream* d_stream, /*!< in/out: compressed page stream */
|
|
|
|
rec_t** recs, /*!< in: dense page directory
|
2006-09-21 19:09:25 +00:00
|
|
|
sorted by address */
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint n_dense, /*!< in: size of recs[] */
|
|
|
|
dict_index_t* index, /*!< in: the index of the page */
|
|
|
|
ulint* offsets) /*!< in/out: temporary offsets */
|
2006-09-21 19:09:25 +00:00
|
|
|
{
|
2006-10-20 12:45:53 +00:00
|
|
|
ulint heap_status = REC_STATUS_ORDINARY
|
|
|
|
| PAGE_HEAP_NO_USER_LOW << REC_HEAP_NO_SHIFT;
|
2006-09-21 19:09:25 +00:00
|
|
|
ulint slot;
|
|
|
|
|
2007-02-19 14:51:44 +00:00
|
|
|
ut_a(!dict_index_is_clust(index));
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Subtract the space reserved for uncompressed data. */
|
|
|
|
d_stream->avail_in -= n_dense * PAGE_ZIP_DIR_SLOT_SIZE;
|
|
|
|
|
|
|
|
for (slot = 0; slot < n_dense; slot++) {
|
|
|
|
rec_t* rec = recs[slot];
|
|
|
|
|
|
|
|
/* Decompress everything up to this record. */
|
|
|
|
d_stream->avail_out = rec - REC_N_NEW_EXTRA_BYTES
|
|
|
|
- d_stream->next_out;
|
|
|
|
|
|
|
|
if (UNIV_LIKELY(d_stream->avail_out)) {
|
|
|
|
switch (inflate(d_stream, Z_SYNC_FLUSH)) {
|
|
|
|
case Z_STREAM_END:
|
|
|
|
/* Apparently, n_dense has grown
|
|
|
|
since the time the page was last compressed. */
|
|
|
|
goto zlib_done;
|
|
|
|
case Z_OK:
|
|
|
|
case Z_BUF_ERROR:
|
|
|
|
if (!d_stream->avail_out) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
default:
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_sec:"
|
|
|
|
" inflate(Z_SYNC_FLUSH)=%s\n",
|
|
|
|
d_stream->msg));
|
2006-09-21 19:09:25 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(d_stream->next_out == rec - REC_N_NEW_EXTRA_BYTES);
|
|
|
|
|
|
|
|
/* Skip the REC_N_NEW_EXTRA_BYTES. */
|
|
|
|
|
|
|
|
d_stream->next_out = rec;
|
|
|
|
|
|
|
|
/* Set heap_no and the status bits. */
|
|
|
|
mach_write_to_2(rec - REC_NEW_HEAP_NO, heap_status);
|
|
|
|
heap_status += 1 << REC_HEAP_NO_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decompress the data of the last record and any trailing garbage,
|
|
|
|
in case the last record was allocated from an originally longer space
|
|
|
|
on the free list. */
|
|
|
|
d_stream->avail_out = page_header_get_field(page_zip->data,
|
|
|
|
PAGE_HEAP_TOP)
|
|
|
|
- page_offset(d_stream->next_out);
|
|
|
|
if (UNIV_UNLIKELY(d_stream->avail_out > UNIV_PAGE_SIZE
|
|
|
|
- PAGE_ZIP_START - PAGE_DIR)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_sec:"
|
|
|
|
" avail_out = %u\n",
|
|
|
|
d_stream->avail_out));
|
2006-02-10 15:06:17 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
if (UNIV_UNLIKELY(inflate(d_stream, Z_FINISH) != Z_STREAM_END)) {
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_sec:"
|
|
|
|
" inflate(Z_FINISH)=%s\n",
|
|
|
|
d_stream->msg));
|
2006-09-21 19:09:25 +00:00
|
|
|
zlib_error:
|
|
|
|
inflateEnd(d_stream);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that d_stream->avail_out > 0 may hold here
|
|
|
|
if the modification log is nonempty. */
|
|
|
|
|
|
|
|
zlib_done:
|
|
|
|
if (UNIV_UNLIKELY(inflateEnd(d_stream) != Z_OK)) {
|
|
|
|
ut_error;
|
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
{
|
2006-09-21 19:09:25 +00:00
|
|
|
page_t* page = page_align(d_stream->next_out);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Clear the unused heap space on the uncompressed page. */
|
|
|
|
memset(d_stream->next_out, 0,
|
|
|
|
page_dir_get_nth_slot(page,
|
|
|
|
page_dir_get_n_slots(page) - 1)
|
|
|
|
- d_stream->next_out);
|
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-11-30 14:09:29 +00:00
|
|
|
#ifdef UNIV_DEBUG
|
2006-09-21 19:09:25 +00:00
|
|
|
page_zip->m_start = PAGE_DATA + d_stream->total_in;
|
2006-11-30 14:09:29 +00:00
|
|
|
#endif /* UNIV_DEBUG */
|
2006-09-21 19:09:25 +00:00
|
|
|
|
|
|
|
/* Apply the modification log. */
|
|
|
|
{
|
|
|
|
const byte* mod_log_ptr;
|
2006-11-30 14:09:29 +00:00
|
|
|
mod_log_ptr = page_zip_apply_log(d_stream->next_in,
|
2006-09-21 19:09:25 +00:00
|
|
|
d_stream->avail_in + 1,
|
|
|
|
recs, n_dense,
|
|
|
|
ULINT_UNDEFINED, heap_status,
|
|
|
|
index, offsets);
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(!mod_log_ptr)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
page_zip->m_end = mod_log_ptr - page_zip->data;
|
2006-11-30 14:09:29 +00:00
|
|
|
page_zip->m_nonempty = mod_log_ptr != d_stream->next_in;
|
2007-12-13 11:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(page_zip_get_trailer_len(page_zip, FALSE, NULL)
|
|
|
|
+ page_zip->m_end >= page_zip_get_size(page_zip))) {
|
|
|
|
|
|
|
|
page_zip_fail(("page_zip_decompress_sec: %lu + %lu >= %lu\n",
|
|
|
|
(ulong) page_zip_get_trailer_len(
|
|
|
|
page_zip, FALSE, NULL),
|
|
|
|
(ulong) page_zip->m_end,
|
|
|
|
(ulong) page_zip_get_size(page_zip)));
|
|
|
|
return(FALSE);
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* There are no uncompressed columns on leaf pages of
|
|
|
|
secondary indexes. */
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2007-02-05 13:20:00 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Decompress a record of a leaf node of a clustered index that contains
|
2009-05-25 05:30:14 +00:00
|
|
|
externally stored columns.
|
|
|
|
@return TRUE on success */
|
2007-02-05 13:20:00 +00:00
|
|
|
static
|
|
|
|
ibool
|
|
|
|
page_zip_decompress_clust_ext(
|
|
|
|
/*==========================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
z_stream* d_stream, /*!< in/out: compressed page stream */
|
|
|
|
rec_t* rec, /*!< in/out: record */
|
|
|
|
const ulint* offsets, /*!< in: rec_get_offsets(rec) */
|
|
|
|
ulint trx_id_col) /*!< in: position of of DB_TRX_ID */
|
2007-02-05 13:20:00 +00:00
|
|
|
{
|
|
|
|
ulint i;
|
|
|
|
|
|
|
|
for (i = 0; i < rec_offs_n_fields(offsets); i++) {
|
|
|
|
ulint len;
|
|
|
|
byte* dst;
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(i == trx_id_col)) {
|
|
|
|
/* Skip trx_id and roll_ptr */
|
|
|
|
dst = rec_get_nth_field(rec, offsets, i, &len);
|
|
|
|
if (UNIV_UNLIKELY(len < DATA_TRX_ID_LEN
|
2008-01-03 10:13:11 +00:00
|
|
|
+ DATA_ROLL_PTR_LEN)) {
|
2007-02-05 13:20:00 +00:00
|
|
|
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_clust_ext:"
|
|
|
|
" len[%lu] = %lu\n",
|
|
|
|
(ulong) i, (ulong) len));
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rec_offs_nth_extern(offsets, i)) {
|
|
|
|
|
|
|
|
page_zip_fail(("page_zip_decompress_clust_ext:"
|
|
|
|
" DB_TRX_ID at %lu is ext\n",
|
|
|
|
(ulong) i));
|
2007-02-05 13:20:00 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
d_stream->avail_out = dst - d_stream->next_out;
|
|
|
|
|
|
|
|
switch (inflate(d_stream, Z_SYNC_FLUSH)) {
|
|
|
|
case Z_STREAM_END:
|
|
|
|
case Z_OK:
|
|
|
|
case Z_BUF_ERROR:
|
|
|
|
if (!d_stream->avail_out) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
default:
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_clust_ext:"
|
|
|
|
" 1 inflate(Z_SYNC_FLUSH)=%s\n",
|
|
|
|
d_stream->msg));
|
2007-02-05 13:20:00 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(d_stream->next_out == dst);
|
|
|
|
|
2007-11-09 15:32:37 +00:00
|
|
|
/* Clear DB_TRX_ID and DB_ROLL_PTR in order to
|
|
|
|
avoid uninitialized bytes in case the record
|
|
|
|
is affected by page_zip_apply_log(). */
|
|
|
|
memset(dst, 0, DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
|
|
|
|
2007-02-05 13:20:00 +00:00
|
|
|
d_stream->next_out += DATA_TRX_ID_LEN
|
|
|
|
+ DATA_ROLL_PTR_LEN;
|
|
|
|
} else if (rec_offs_nth_extern(offsets, i)) {
|
|
|
|
dst = rec_get_nth_field(rec, offsets, i, &len);
|
|
|
|
ut_ad(len >= BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
dst += len - BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
d_stream->avail_out = dst - d_stream->next_out;
|
2008-01-03 10:13:11 +00:00
|
|
|
switch (inflate(d_stream, Z_SYNC_FLUSH)) {
|
2007-02-05 13:20:00 +00:00
|
|
|
case Z_STREAM_END:
|
|
|
|
case Z_OK:
|
|
|
|
case Z_BUF_ERROR:
|
|
|
|
if (!d_stream->avail_out) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
default:
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_clust_ext:"
|
|
|
|
" 2 inflate(Z_SYNC_FLUSH)=%s\n",
|
|
|
|
d_stream->msg));
|
2007-02-05 13:20:00 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(d_stream->next_out == dst);
|
|
|
|
|
|
|
|
/* Clear the BLOB pointer in case
|
|
|
|
the record will be deleted and the
|
|
|
|
space will not be reused. Note that
|
|
|
|
the final initialization of the BLOB
|
|
|
|
pointers (copying from "externs"
|
|
|
|
or clearing) will have to take place
|
|
|
|
only after the page modification log
|
|
|
|
has been applied. Otherwise, we
|
|
|
|
could end up with an uninitialized
|
|
|
|
BLOB pointer when a record is deleted,
|
|
|
|
reallocated and deleted. */
|
|
|
|
memset(d_stream->next_out, 0,
|
|
|
|
BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
d_stream->next_out
|
|
|
|
+= BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Compress the records of a leaf node of a clustered index.
|
|
|
|
@return TRUE on success, FALSE on failure */
|
2006-09-21 19:09:25 +00:00
|
|
|
static
|
|
|
|
ibool
|
|
|
|
page_zip_decompress_clust(
|
|
|
|
/*======================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip, /*!< in/out: compressed page */
|
|
|
|
z_stream* d_stream, /*!< in/out: compressed page stream */
|
|
|
|
rec_t** recs, /*!< in: dense page directory
|
2006-09-21 19:09:25 +00:00
|
|
|
sorted by address */
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint n_dense, /*!< in: size of recs[] */
|
|
|
|
dict_index_t* index, /*!< in: the index of the page */
|
|
|
|
ulint trx_id_col, /*!< index of the trx_id column */
|
|
|
|
ulint* offsets, /*!< in/out: temporary offsets */
|
|
|
|
mem_heap_t* heap) /*!< in: temporary memory heap */
|
2006-09-21 19:09:25 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
ulint slot;
|
|
|
|
ulint heap_status = REC_STATUS_ORDINARY
|
2006-10-20 12:45:53 +00:00
|
|
|
| PAGE_HEAP_NO_USER_LOW << REC_HEAP_NO_SHIFT;
|
2006-09-21 19:09:25 +00:00
|
|
|
const byte* storage;
|
|
|
|
const byte* externs;
|
|
|
|
|
2007-02-19 14:51:44 +00:00
|
|
|
ut_a(dict_index_is_clust(index));
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Subtract the space reserved for uncompressed data. */
|
|
|
|
d_stream->avail_in -= n_dense * (PAGE_ZIP_DIR_SLOT_SIZE
|
|
|
|
+ DATA_TRX_ID_LEN
|
|
|
|
+ DATA_ROLL_PTR_LEN);
|
|
|
|
|
2006-03-29 14:08:57 +00:00
|
|
|
/* Decompress the records in heap_no order. */
|
2006-03-16 14:02:22 +00:00
|
|
|
for (slot = 0; slot < n_dense; slot++) {
|
2006-09-21 19:09:25 +00:00
|
|
|
rec_t* rec = recs[slot];
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
d_stream->avail_out = rec - REC_N_NEW_EXTRA_BYTES
|
|
|
|
- d_stream->next_out;
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
ut_ad(d_stream->avail_out < UNIV_PAGE_SIZE
|
2006-08-29 09:30:31 +00:00
|
|
|
- PAGE_ZIP_START - PAGE_DIR);
|
2006-09-21 19:09:25 +00:00
|
|
|
err = inflate(d_stream, Z_SYNC_FLUSH);
|
|
|
|
switch (err) {
|
2006-02-10 15:06:17 +00:00
|
|
|
case Z_STREAM_END:
|
|
|
|
/* Apparently, n_dense has grown
|
2006-08-04 08:25:39 +00:00
|
|
|
since the time the page was last compressed. */
|
2006-02-10 15:06:17 +00:00
|
|
|
goto zlib_done;
|
2006-02-27 09:53:58 +00:00
|
|
|
case Z_OK:
|
2005-11-24 14:13:10 +00:00
|
|
|
case Z_BUF_ERROR:
|
2006-09-21 19:09:25 +00:00
|
|
|
if (UNIV_LIKELY(!d_stream->avail_out)) {
|
2005-11-24 14:13:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-09-21 19:09:25 +00:00
|
|
|
/* fall through */
|
2005-11-24 14:13:10 +00:00
|
|
|
default:
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_clust:"
|
|
|
|
" 1 inflate(Z_SYNC_FLUSH)=%s\n",
|
|
|
|
d_stream->msg));
|
2005-11-24 14:13:10 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
ut_ad(d_stream->next_out == rec - REC_N_NEW_EXTRA_BYTES);
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Prepare to decompress the data bytes. */
|
2006-09-21 19:09:25 +00:00
|
|
|
d_stream->next_out = rec;
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Set heap_no and the status bits. */
|
|
|
|
mach_write_to_2(rec - REC_NEW_HEAP_NO, heap_status);
|
|
|
|
heap_status += 1 << REC_HEAP_NO_SHIFT;
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Read the offsets. The status bits are needed here. */
|
|
|
|
offsets = rec_get_offsets(rec, index, offsets,
|
2006-08-29 09:30:31 +00:00
|
|
|
ULINT_UNDEFINED, &heap);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* This is a leaf page in a clustered index. */
|
2006-08-21 18:36:00 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Check if there are any externally stored columns.
|
|
|
|
For each externally stored column, restore the
|
|
|
|
BTR_EXTERN_FIELD_REF separately. */
|
2006-08-21 18:36:00 +00:00
|
|
|
|
2007-02-05 13:20:00 +00:00
|
|
|
if (UNIV_UNLIKELY(rec_offs_any_extern(offsets))) {
|
|
|
|
if (UNIV_UNLIKELY
|
|
|
|
(!page_zip_decompress_clust_ext(
|
|
|
|
d_stream, rec, offsets, trx_id_col))) {
|
2006-08-21 18:36:00 +00:00
|
|
|
|
2007-02-05 13:20:00 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Skip trx_id and roll_ptr */
|
|
|
|
ulint len;
|
|
|
|
byte* dst = rec_get_nth_field(rec, offsets,
|
|
|
|
trx_id_col, &len);
|
|
|
|
if (UNIV_UNLIKELY(len < DATA_TRX_ID_LEN
|
|
|
|
+ DATA_ROLL_PTR_LEN)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_clust:"
|
|
|
|
" len = %lu\n", (ulong) len));
|
2007-02-05 13:20:00 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2007-02-05 13:20:00 +00:00
|
|
|
d_stream->avail_out = dst - d_stream->next_out;
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2007-02-05 13:20:00 +00:00
|
|
|
switch (inflate(d_stream, Z_SYNC_FLUSH)) {
|
|
|
|
case Z_STREAM_END:
|
|
|
|
case Z_OK:
|
|
|
|
case Z_BUF_ERROR:
|
|
|
|
if (!d_stream->avail_out) {
|
|
|
|
break;
|
2006-09-21 19:09:25 +00:00
|
|
|
}
|
2007-02-05 13:20:00 +00:00
|
|
|
/* fall through */
|
|
|
|
default:
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_clust:"
|
|
|
|
" 2 inflate(Z_SYNC_FLUSH)=%s\n",
|
|
|
|
d_stream->msg));
|
2007-02-05 13:20:00 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2007-02-05 13:20:00 +00:00
|
|
|
ut_ad(d_stream->next_out == dst);
|
2006-09-21 19:09:25 +00:00
|
|
|
|
2007-11-09 15:32:37 +00:00
|
|
|
/* Clear DB_TRX_ID and DB_ROLL_PTR in order to
|
|
|
|
avoid uninitialized bytes in case the record
|
|
|
|
is affected by page_zip_apply_log(). */
|
|
|
|
memset(dst, 0, DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
|
|
|
|
2007-02-05 13:20:00 +00:00
|
|
|
d_stream->next_out += DATA_TRX_ID_LEN
|
|
|
|
+ DATA_ROLL_PTR_LEN;
|
2006-09-21 19:09:25 +00:00
|
|
|
}
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Decompress the last bytes of the record. */
|
|
|
|
d_stream->avail_out = rec_get_end(rec, offsets)
|
|
|
|
- d_stream->next_out;
|
2005-11-25 12:34:38 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
switch (inflate(d_stream, Z_SYNC_FLUSH)) {
|
|
|
|
case Z_STREAM_END:
|
|
|
|
case Z_OK:
|
|
|
|
case Z_BUF_ERROR:
|
|
|
|
if (!d_stream->avail_out) {
|
|
|
|
break;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2006-09-21 19:09:25 +00:00
|
|
|
/* fall through */
|
|
|
|
default:
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_clust:"
|
|
|
|
" 3 inflate(Z_SYNC_FLUSH)=%s\n",
|
|
|
|
d_stream->msg));
|
2006-09-21 19:09:25 +00:00
|
|
|
goto zlib_error;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
}
|
|
|
|
|
2006-02-27 09:53:58 +00:00
|
|
|
/* Decompress any trailing garbage, in case the last record was
|
|
|
|
allocated from an originally longer space on the free list. */
|
2006-09-21 19:09:25 +00:00
|
|
|
d_stream->avail_out = page_header_get_field(page_zip->data,
|
|
|
|
PAGE_HEAP_TOP)
|
|
|
|
- page_offset(d_stream->next_out);
|
|
|
|
if (UNIV_UNLIKELY(d_stream->avail_out > UNIV_PAGE_SIZE
|
2006-08-29 09:30:31 +00:00
|
|
|
- PAGE_ZIP_START - PAGE_DIR)) {
|
2006-02-27 09:53:58 +00:00
|
|
|
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_clust:"
|
|
|
|
" avail_out = %u\n",
|
|
|
|
d_stream->avail_out));
|
2006-02-27 09:53:58 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
if (UNIV_UNLIKELY(inflate(d_stream, Z_FINISH) != Z_STREAM_END)) {
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress_clust:"
|
|
|
|
" inflate(Z_FINISH)=%s\n",
|
|
|
|
d_stream->msg));
|
2006-02-10 15:06:17 +00:00
|
|
|
zlib_error:
|
2006-09-21 19:09:25 +00:00
|
|
|
inflateEnd(d_stream);
|
|
|
|
return(FALSE);
|
2006-02-27 09:53:58 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Note that d_stream->avail_out > 0 may hold here
|
2006-02-27 09:53:58 +00:00
|
|
|
if the modification log is nonempty. */
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
zlib_done:
|
2006-09-21 19:09:25 +00:00
|
|
|
if (UNIV_UNLIKELY(inflateEnd(d_stream) != Z_OK)) {
|
2006-03-03 14:32:27 +00:00
|
|
|
ut_error;
|
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
{
|
|
|
|
page_t* page = page_align(d_stream->next_out);
|
2005-11-29 10:24:45 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Clear the unused heap space on the uncompressed page. */
|
|
|
|
memset(d_stream->next_out, 0,
|
|
|
|
page_dir_get_nth_slot(page,
|
|
|
|
page_dir_get_n_slots(page) - 1)
|
|
|
|
- d_stream->next_out);
|
|
|
|
}
|
2005-11-24 14:13:10 +00:00
|
|
|
|
2006-11-30 14:09:29 +00:00
|
|
|
#ifdef UNIV_DEBUG
|
2006-09-21 19:09:25 +00:00
|
|
|
page_zip->m_start = PAGE_DATA + d_stream->total_in;
|
2006-11-30 14:09:29 +00:00
|
|
|
#endif /* UNIV_DEBUG */
|
2005-10-27 11:48:10 +00:00
|
|
|
|
|
|
|
/* Apply the modification log. */
|
2005-11-18 07:42:02 +00:00
|
|
|
{
|
|
|
|
const byte* mod_log_ptr;
|
2006-11-30 14:09:29 +00:00
|
|
|
mod_log_ptr = page_zip_apply_log(d_stream->next_in,
|
2006-09-21 19:09:25 +00:00
|
|
|
d_stream->avail_in + 1,
|
2006-09-19 10:14:07 +00:00
|
|
|
recs, n_dense,
|
|
|
|
trx_id_col, heap_status,
|
|
|
|
index, offsets);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2005-11-18 07:42:02 +00:00
|
|
|
if (UNIV_UNLIKELY(!mod_log_ptr)) {
|
2006-09-21 19:09:25 +00:00
|
|
|
return(FALSE);
|
2005-10-27 11:48:10 +00:00
|
|
|
}
|
2005-11-18 07:42:02 +00:00
|
|
|
page_zip->m_end = mod_log_ptr - page_zip->data;
|
2006-11-30 14:09:29 +00:00
|
|
|
page_zip->m_nonempty = mod_log_ptr != d_stream->next_in;
|
2007-12-13 11:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(page_zip_get_trailer_len(page_zip, TRUE, NULL)
|
|
|
|
+ page_zip->m_end >= page_zip_get_size(page_zip))) {
|
|
|
|
|
|
|
|
page_zip_fail(("page_zip_decompress_clust: %lu + %lu >= %lu\n",
|
|
|
|
(ulong) page_zip_get_trailer_len(
|
|
|
|
page_zip, TRUE, NULL),
|
|
|
|
(ulong) page_zip->m_end,
|
|
|
|
(ulong) page_zip_get_size(page_zip)));
|
|
|
|
return(FALSE);
|
2005-10-27 11:48:10 +00:00
|
|
|
}
|
|
|
|
|
2006-11-27 13:44:32 +00:00
|
|
|
storage = page_zip->data + page_zip_get_size(page_zip)
|
2006-09-21 19:09:25 +00:00
|
|
|
- n_dense * PAGE_ZIP_DIR_SLOT_SIZE;
|
|
|
|
|
|
|
|
externs = storage - n_dense
|
|
|
|
* (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
|
|
|
|
|
|
|
/* Restore the uncompressed columns in heap_no order. */
|
|
|
|
|
|
|
|
for (slot = 0; slot < n_dense; slot++) {
|
|
|
|
ulint i;
|
|
|
|
ulint len;
|
|
|
|
byte* dst;
|
|
|
|
rec_t* rec = recs[slot];
|
|
|
|
ibool exists = !page_zip_dir_find_free(
|
|
|
|
page_zip, page_offset(rec));
|
|
|
|
offsets = rec_get_offsets(rec, index, offsets,
|
|
|
|
ULINT_UNDEFINED, &heap);
|
|
|
|
|
|
|
|
dst = rec_get_nth_field(rec, offsets,
|
|
|
|
trx_id_col, &len);
|
|
|
|
ut_ad(len >= DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
|
|
|
storage -= DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN;
|
|
|
|
memcpy(dst, storage,
|
|
|
|
DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
|
|
|
|
|
|
|
/* Check if there are any externally stored
|
|
|
|
columns in this record. For each externally
|
|
|
|
stored column, restore or clear the
|
|
|
|
BTR_EXTERN_FIELD_REF. */
|
2007-02-02 16:20:48 +00:00
|
|
|
if (!rec_offs_any_extern(offsets)) {
|
|
|
|
continue;
|
|
|
|
}
|
2006-09-21 19:09:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < rec_offs_n_fields(offsets); i++) {
|
|
|
|
if (!rec_offs_nth_extern(offsets, i)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dst = rec_get_nth_field(rec, offsets, i, &len);
|
2007-12-13 13:12:20 +00:00
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(len < BTR_EXTERN_FIELD_REF_SIZE)) {
|
|
|
|
page_zip_fail(("page_zip_decompress_clust:"
|
|
|
|
" %lu < 20\n",
|
|
|
|
(ulong) len));
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
dst += len - BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
if (UNIV_LIKELY(exists)) {
|
|
|
|
/* Existing record:
|
|
|
|
restore the BLOB pointer */
|
|
|
|
externs -= BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
2007-12-13 13:12:20 +00:00
|
|
|
if (UNIV_UNLIKELY
|
|
|
|
(externs < page_zip->data
|
|
|
|
+ page_zip->m_end)) {
|
|
|
|
page_zip_fail(("page_zip_"
|
|
|
|
"decompress_clust: "
|
|
|
|
"%p < %p + %lu\n",
|
|
|
|
(const void*) externs,
|
|
|
|
(const void*)
|
|
|
|
page_zip->data,
|
|
|
|
(ulong)
|
|
|
|
page_zip->m_end));
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
memcpy(dst, externs,
|
|
|
|
BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
|
|
|
|
page_zip->n_blobs++;
|
|
|
|
} else {
|
|
|
|
/* Deleted record:
|
|
|
|
clear the BLOB pointer */
|
|
|
|
memset(dst, 0,
|
|
|
|
BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Decompress a page. This function should tolerate errors on the compressed
|
|
|
|
page. Instead of letting assertions fail, it will return FALSE if an
|
2009-05-25 05:30:14 +00:00
|
|
|
inconsistency is detected.
|
|
|
|
@return TRUE on success, FALSE on failure */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-09-21 19:09:25 +00:00
|
|
|
ibool
|
|
|
|
page_zip_decompress(
|
|
|
|
/*================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip,/*!< in: data, ssize;
|
2006-11-30 14:09:29 +00:00
|
|
|
out: m_start, m_end, m_nonempty, n_blobs */
|
2009-05-25 05:30:14 +00:00
|
|
|
page_t* page) /*!< out: uncompressed page, may be trashed */
|
2006-09-21 19:09:25 +00:00
|
|
|
{
|
|
|
|
z_stream d_stream;
|
|
|
|
dict_index_t* index = NULL;
|
|
|
|
rec_t** recs; /* dense page directory, sorted by address */
|
|
|
|
ulint n_dense;/* number of user records on the page */
|
|
|
|
ulint trx_id_col = ULINT_UNDEFINED;
|
|
|
|
mem_heap_t* heap;
|
|
|
|
ulint* offsets;
|
2008-02-27 14:34:44 +00:00
|
|
|
ullint usec = ut_time_us(NULL);
|
2006-09-21 19:09:25 +00:00
|
|
|
|
|
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
2007-10-31 12:42:38 +00:00
|
|
|
UNIV_MEM_ASSERT_W(page, UNIV_PAGE_SIZE);
|
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2006-09-21 19:09:25 +00:00
|
|
|
|
|
|
|
/* The dense directory excludes the infimum and supremum records. */
|
2006-10-20 12:45:53 +00:00
|
|
|
n_dense = page_dir_get_n_heap(page_zip->data) - PAGE_HEAP_NO_USER_LOW;
|
2006-09-21 19:09:25 +00:00
|
|
|
if (UNIV_UNLIKELY(n_dense * PAGE_ZIP_DIR_SLOT_SIZE
|
2006-11-27 13:44:32 +00:00
|
|
|
>= page_zip_get_size(page_zip))) {
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_decompress 1: %lu %lu\n",
|
|
|
|
(ulong) n_dense,
|
|
|
|
(ulong) page_zip_get_size(page_zip)));
|
2006-09-21 19:09:25 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2007-01-05 21:15:05 +00:00
|
|
|
heap = mem_heap_create(n_dense * (3 * sizeof *recs) + UNIV_PAGE_SIZE);
|
2006-09-21 19:09:25 +00:00
|
|
|
recs = mem_heap_alloc(heap, n_dense * (2 * sizeof *recs));
|
|
|
|
|
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2007-11-09 15:32:37 +00:00
|
|
|
/* Clear the page. */
|
|
|
|
memset(page, 0x55, UNIV_PAGE_SIZE);
|
2006-09-21 19:09:25 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2007-10-31 12:42:38 +00:00
|
|
|
UNIV_MEM_INVALID(page, UNIV_PAGE_SIZE);
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Copy the page header. */
|
|
|
|
memcpy(page, page_zip->data, PAGE_DATA);
|
|
|
|
|
|
|
|
/* Copy the page directory. */
|
|
|
|
if (UNIV_UNLIKELY(!page_zip_dir_decode(page_zip, page, recs,
|
|
|
|
recs + n_dense, n_dense))) {
|
|
|
|
zlib_error:
|
2006-02-10 15:06:17 +00:00
|
|
|
mem_heap_free(heap);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Copy the infimum and supremum records. */
|
|
|
|
memcpy(page + (PAGE_NEW_INFIMUM - REC_N_NEW_EXTRA_BYTES),
|
|
|
|
infimum_extra, sizeof infimum_extra);
|
|
|
|
if (UNIV_UNLIKELY(!page_get_n_recs(page))) {
|
|
|
|
rec_set_next_offs_new(page + PAGE_NEW_INFIMUM,
|
|
|
|
PAGE_NEW_SUPREMUM);
|
|
|
|
} else {
|
|
|
|
rec_set_next_offs_new(page + PAGE_NEW_INFIMUM,
|
|
|
|
page_zip_dir_get(page_zip, 0)
|
|
|
|
& PAGE_ZIP_DIR_SLOT_MASK);
|
|
|
|
}
|
|
|
|
memcpy(page + PAGE_NEW_INFIMUM, infimum_data, sizeof infimum_data);
|
|
|
|
memcpy(page + (PAGE_NEW_SUPREMUM - REC_N_NEW_EXTRA_BYTES + 1),
|
|
|
|
supremum_extra_data, sizeof supremum_extra_data);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2007-01-29 08:51:20 +00:00
|
|
|
page_zip_set_alloc(&d_stream, heap);
|
2006-03-16 14:02:22 +00:00
|
|
|
|
2007-01-05 21:15:05 +00:00
|
|
|
if (UNIV_UNLIKELY(inflateInit2(&d_stream, UNIV_PAGE_SIZE_SHIFT)
|
|
|
|
!= Z_OK)) {
|
2006-09-21 19:09:25 +00:00
|
|
|
ut_error;
|
2006-03-09 17:26:02 +00:00
|
|
|
}
|
2006-03-13 15:02:16 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
d_stream.next_in = page_zip->data + PAGE_DATA;
|
|
|
|
/* Subtract the space reserved for
|
|
|
|
the page header and the end marker of the modification log. */
|
2006-11-27 13:44:32 +00:00
|
|
|
d_stream.avail_in = page_zip_get_size(page_zip) - (PAGE_DATA + 1);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
d_stream.next_out = page + PAGE_ZIP_START;
|
|
|
|
d_stream.avail_out = UNIV_PAGE_SIZE - PAGE_ZIP_START;
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Decode the zlib header and the index information. */
|
2008-01-03 10:13:11 +00:00
|
|
|
if (UNIV_UNLIKELY(inflate(&d_stream, Z_BLOCK) != Z_OK)) {
|
|
|
|
|
|
|
|
page_zip_fail(("page_zip_decompress:"
|
|
|
|
" 1 inflate(Z_BLOCK)=%s\n", d_stream.msg));
|
|
|
|
goto zlib_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(inflate(&d_stream, Z_BLOCK) != Z_OK)) {
|
2006-03-29 14:08:57 +00:00
|
|
|
|
2008-01-03 10:13:11 +00:00
|
|
|
page_zip_fail(("page_zip_decompress:"
|
|
|
|
" 2 inflate(Z_BLOCK)=%s\n", d_stream.msg));
|
2006-09-21 19:09:25 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
2006-03-29 14:08:57 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
index = page_zip_fields_decode(
|
|
|
|
page + PAGE_ZIP_START, d_stream.next_out,
|
|
|
|
page_is_leaf(page) ? &trx_id_col : NULL);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
if (UNIV_UNLIKELY(!index)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
goto zlib_error;
|
|
|
|
}
|
2006-03-14 14:38:45 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
/* Decompress the user records. */
|
|
|
|
page_zip->n_blobs = 0;
|
|
|
|
d_stream.next_out = page + PAGE_ZIP_START;
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Pre-allocate the offsets for rec_get_offsets_reverse(). */
|
|
|
|
ulint n = 1 + 1/* node ptr */ + REC_OFFS_HEADER_SIZE
|
|
|
|
+ dict_index_get_n_fields(index);
|
|
|
|
offsets = mem_heap_alloc(heap, n * sizeof(ulint));
|
|
|
|
*offsets = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decompress the records in heap_no order. */
|
|
|
|
if (!page_is_leaf(page)) {
|
|
|
|
/* This is a node pointer page. */
|
|
|
|
ulint info_bits;
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY
|
|
|
|
(!page_zip_decompress_node_ptrs(page_zip, &d_stream,
|
|
|
|
recs, n_dense, index,
|
|
|
|
offsets, heap))) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
info_bits = mach_read_from_4(page + FIL_PAGE_PREV) == FIL_NULL
|
|
|
|
? REC_INFO_MIN_REC_FLAG : 0;
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(!page_zip_set_extra_bytes(page_zip, page,
|
|
|
|
info_bits))) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
} else if (UNIV_LIKELY(trx_id_col == ULINT_UNDEFINED)) {
|
|
|
|
/* This is a leaf page in a secondary index. */
|
|
|
|
if (UNIV_UNLIKELY(!page_zip_decompress_sec(page_zip, &d_stream,
|
|
|
|
recs, n_dense,
|
|
|
|
index, offsets))) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
2006-03-16 14:02:22 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
if (UNIV_UNLIKELY(!page_zip_set_extra_bytes(page_zip,
|
|
|
|
page, 0))) {
|
|
|
|
err_exit:
|
|
|
|
page_zip_fields_free(index);
|
|
|
|
mem_heap_free(heap);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* This is a leaf page in a clustered index. */
|
|
|
|
if (UNIV_UNLIKELY(!page_zip_decompress_clust(page_zip,
|
|
|
|
&d_stream, recs,
|
|
|
|
n_dense, index,
|
|
|
|
trx_id_col,
|
|
|
|
offsets, heap))) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-21 19:09:25 +00:00
|
|
|
if (UNIV_UNLIKELY(!page_zip_set_extra_bytes(page_zip,
|
|
|
|
page, 0))) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
ut_a(page_is_comp(page));
|
2007-11-07 14:14:47 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page, UNIV_PAGE_SIZE);
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-02-27 16:03:32 +00:00
|
|
|
page_zip_fields_free(index);
|
|
|
|
mem_heap_free(heap);
|
branches/zip: Rename the INFORMATION_SCHEMA tables
INNODB_ZIP and INNODB_ZIP_RESET to
INNODB_COMPRESSION and INNODB_COMPRESSION_RESET,
and remove the statistics of the buddy system.
This change was discussed with Ken. It makes the tables shorter
and easier to understand. The removed data will be represented in
the tables INNODB_COMPRESSION_BUDDY and INNODB_COMPRESSION_BUDDY_RESET
that will be added later.
i_s_innodb_zip, i_s_innodb_zip_reset, i_s_zip_fields_info[],
i_s_zip_fill_low(), i_s_zip_fill(), i_s_zip_reset_fill(),
i_s_zip_init(), i_s_zip_reset_init(): Replace "zip" with "compression".
i_s_compression_fields_info[]: Remove "used", "free",
"relocated", "relocated_usec". In "compressed_usec" and "decompressed_usec",
replace microseconds with seconds ("usec" with "sec").
page_zip_decompress(): Correct a typo in the function comment.
PAGE_ZIP_SSIZE_BITS, PAGE_ZIP_NUM_SSIZE: New constants.
page_zip_stat_t, page_zip_stat: Statistics of the compression, grouped
by page size.
page_zip_simple_validate(): Assert that page_zip->ssize is reasonable.
2008-03-28 09:28:54 +00:00
|
|
|
{
|
|
|
|
page_zip_stat_t* zip_stat
|
|
|
|
= &page_zip_stat[page_zip->ssize - 1];
|
|
|
|
zip_stat->decompressed++;
|
|
|
|
zip_stat->decompressed_usec += ut_time_us(NULL) - usec;
|
|
|
|
}
|
2006-02-27 16:03:32 +00:00
|
|
|
|
2008-03-03 12:48:38 +00:00
|
|
|
/* Update the stat counter for LRU policy. */
|
|
|
|
buf_LRU_stat_inc_unzip();
|
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2008-09-29 08:26:42 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Dump a block of memory on the standard error stream. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
page_zip_hexdump_func(
|
|
|
|
/*==================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const char* name, /*!< in: name of the data structure */
|
|
|
|
const void* buf, /*!< in: data */
|
|
|
|
ulint size) /*!< in: length of the data, in bytes */
|
2008-09-29 08:26:42 +00:00
|
|
|
{
|
|
|
|
const byte* s = buf;
|
|
|
|
ulint addr;
|
|
|
|
const ulint width = 32; /* bytes per line */
|
|
|
|
|
|
|
|
fprintf(stderr, "%s:\n", name);
|
|
|
|
|
|
|
|
for (addr = 0; addr < size; addr += width) {
|
|
|
|
ulint i;
|
|
|
|
|
|
|
|
fprintf(stderr, "%04lx ", (ulong) addr);
|
|
|
|
|
|
|
|
i = ut_min(width, size - addr);
|
|
|
|
|
|
|
|
while (i--) {
|
|
|
|
fprintf(stderr, "%02x", *s++);
|
|
|
|
}
|
|
|
|
|
|
|
|
putc('\n', stderr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define page_zip_hexdump(buf, size) page_zip_hexdump_func(#buf, buf, size)
|
|
|
|
|
2006-06-14 08:15:44 +00:00
|
|
|
/* Flag: make page_zip_validate() compare page headers only */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN ibool page_zip_validate_header_only = FALSE;
|
2006-06-14 08:15:44 +00:00
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Check that the compressed and decompressed pages match.
|
|
|
|
@return TRUE if valid, FALSE if not */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 11:48:10 +00:00
|
|
|
ibool
|
2008-10-06 07:13:52 +00:00
|
|
|
page_zip_validate_low(
|
|
|
|
/*==================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_zip_des_t* page_zip,/*!< in: compressed page */
|
|
|
|
const page_t* page, /*!< in: uncompressed page */
|
|
|
|
ibool sloppy) /*!< in: FALSE=strict,
|
2008-10-06 07:13:52 +00:00
|
|
|
TRUE=ignore the MIN_REC_FLAG */
|
2005-10-27 11:48:10 +00:00
|
|
|
{
|
2007-11-07 14:14:47 +00:00
|
|
|
page_zip_des_t temp_page_zip;
|
2006-07-28 07:34:33 +00:00
|
|
|
byte* temp_page_buf;
|
2006-06-14 08:15:44 +00:00
|
|
|
page_t* temp_page;
|
2005-11-24 14:13:10 +00:00
|
|
|
ibool valid;
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-06-14 08:15:44 +00:00
|
|
|
if (memcmp(page_zip->data + FIL_PAGE_PREV, page + FIL_PAGE_PREV,
|
2006-08-29 09:30:31 +00:00
|
|
|
FIL_PAGE_LSN - FIL_PAGE_PREV)
|
2006-06-14 08:15:44 +00:00
|
|
|
|| memcmp(page_zip->data + FIL_PAGE_TYPE, page + FIL_PAGE_TYPE, 2)
|
|
|
|
|| memcmp(page_zip->data + FIL_PAGE_DATA, page + FIL_PAGE_DATA,
|
2006-08-29 09:30:31 +00:00
|
|
|
PAGE_DATA - FIL_PAGE_DATA)) {
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_validate: page header\n"));
|
2008-10-01 19:03:45 +00:00
|
|
|
page_zip_hexdump(page_zip, sizeof *page_zip);
|
|
|
|
page_zip_hexdump(page_zip->data, page_zip_get_size(page_zip));
|
|
|
|
page_zip_hexdump(page, UNIV_PAGE_SIZE);
|
2006-06-14 08:15:44 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2007-01-10 10:08:34 +00:00
|
|
|
ut_a(page_is_comp(page));
|
|
|
|
|
2006-06-14 08:15:44 +00:00
|
|
|
if (page_zip_validate_header_only) {
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2006-07-28 07:34:33 +00:00
|
|
|
/* page_zip_decompress() expects the uncompressed page to be
|
|
|
|
UNIV_PAGE_SIZE aligned. */
|
|
|
|
temp_page_buf = ut_malloc(2 * UNIV_PAGE_SIZE);
|
|
|
|
temp_page = ut_align(temp_page_buf, UNIV_PAGE_SIZE);
|
2006-06-14 08:15:44 +00:00
|
|
|
|
2007-11-07 14:14:47 +00:00
|
|
|
#ifdef UNIV_DEBUG_VALGRIND
|
2007-11-07 15:58:39 +00:00
|
|
|
/* Get detailed information on the valid bits in case the
|
2008-09-29 10:26:41 +00:00
|
|
|
UNIV_MEM_ASSERT_RW() checks fail. The v-bits of page[],
|
|
|
|
page_zip->data[] or page_zip could be viewed at temp_page[] or
|
|
|
|
temp_page_zip in a debugger when running valgrind --db-attach. */
|
2007-11-07 14:14:47 +00:00
|
|
|
VALGRIND_GET_VBITS(page, temp_page, UNIV_PAGE_SIZE);
|
|
|
|
UNIV_MEM_ASSERT_RW(page, UNIV_PAGE_SIZE);
|
2007-11-07 15:58:39 +00:00
|
|
|
VALGRIND_GET_VBITS(page_zip, &temp_page_zip, sizeof temp_page_zip);
|
|
|
|
UNIV_MEM_ASSERT_RW(page_zip, sizeof *page_zip);
|
|
|
|
VALGRIND_GET_VBITS(page_zip->data, temp_page,
|
|
|
|
page_zip_get_size(page_zip));
|
2007-11-07 14:14:47 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2007-11-07 15:58:39 +00:00
|
|
|
#endif /* UNIV_DEBUG_VALGRIND */
|
2007-11-07 14:14:47 +00:00
|
|
|
|
|
|
|
temp_page_zip = *page_zip;
|
2006-09-19 13:56:56 +00:00
|
|
|
valid = page_zip_decompress(&temp_page_zip, temp_page);
|
2006-03-14 14:38:45 +00:00
|
|
|
if (!valid) {
|
|
|
|
fputs("page_zip_validate(): failed to decompress\n", stderr);
|
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
if (page_zip->n_blobs != temp_page_zip.n_blobs) {
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_validate: n_blobs: %u!=%u\n",
|
|
|
|
page_zip->n_blobs, temp_page_zip.n_blobs));
|
2006-03-14 14:38:45 +00:00
|
|
|
valid = FALSE;
|
|
|
|
}
|
2006-11-30 14:09:29 +00:00
|
|
|
#ifdef UNIV_DEBUG
|
2006-03-14 14:38:45 +00:00
|
|
|
if (page_zip->m_start != temp_page_zip.m_start) {
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_validate: m_start: %u!=%u\n",
|
|
|
|
page_zip->m_start, temp_page_zip.m_start));
|
2006-03-14 14:38:45 +00:00
|
|
|
valid = FALSE;
|
|
|
|
}
|
2006-11-30 14:09:29 +00:00
|
|
|
#endif /* UNIV_DEBUG */
|
2006-03-14 14:38:45 +00:00
|
|
|
if (page_zip->m_end != temp_page_zip.m_end) {
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_validate: m_end: %u!=%u\n",
|
|
|
|
page_zip->m_end, temp_page_zip.m_end));
|
2006-03-14 14:38:45 +00:00
|
|
|
valid = FALSE;
|
|
|
|
}
|
2006-11-30 14:09:29 +00:00
|
|
|
if (page_zip->m_nonempty != temp_page_zip.m_nonempty) {
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_validate(): m_nonempty: %u!=%u\n",
|
|
|
|
page_zip->m_nonempty,
|
|
|
|
temp_page_zip.m_nonempty));
|
2006-11-30 14:09:29 +00:00
|
|
|
valid = FALSE;
|
|
|
|
}
|
2006-03-14 14:38:45 +00:00
|
|
|
if (memcmp(page + PAGE_HEADER, temp_page + PAGE_HEADER,
|
2006-08-29 09:30:31 +00:00
|
|
|
UNIV_PAGE_SIZE - PAGE_HEADER - FIL_PAGE_DATA_END)) {
|
2008-10-06 07:13:52 +00:00
|
|
|
|
|
|
|
/* In crash recovery, the "minimum record" flag may be
|
|
|
|
set incorrectly until the mini-transaction is
|
|
|
|
committed. Let us tolerate that difference when we
|
|
|
|
are performing a sloppy validation. */
|
|
|
|
|
|
|
|
if (sloppy) {
|
|
|
|
byte info_bits_diff;
|
|
|
|
ulint offset
|
|
|
|
= rec_get_next_offs(page + PAGE_NEW_INFIMUM,
|
|
|
|
TRUE);
|
|
|
|
ut_a(offset >= PAGE_NEW_SUPREMUM);
|
|
|
|
offset -= 5 /* REC_NEW_INFO_BITS */;
|
|
|
|
|
|
|
|
info_bits_diff = page[offset] ^ temp_page[offset];
|
|
|
|
|
|
|
|
if (info_bits_diff == REC_INFO_MIN_REC_FLAG) {
|
|
|
|
temp_page[offset] = page[offset];
|
|
|
|
|
|
|
|
if (!memcmp(page + PAGE_HEADER,
|
|
|
|
temp_page + PAGE_HEADER,
|
|
|
|
UNIV_PAGE_SIZE - PAGE_HEADER
|
|
|
|
- FIL_PAGE_DATA_END)) {
|
|
|
|
|
|
|
|
/* Only the minimum record flag
|
|
|
|
differed. Let us ignore it. */
|
2008-10-06 12:26:27 +00:00
|
|
|
page_zip_fail(("page_zip_validate: "
|
|
|
|
"min_rec_flag "
|
|
|
|
"(ignored, "
|
|
|
|
"%lu,%lu,0x%02lx)\n",
|
|
|
|
page_get_space_id(page),
|
|
|
|
page_get_page_no(page),
|
|
|
|
(ulong) page[offset]));
|
2008-10-06 07:13:52 +00:00
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 10:56:34 +00:00
|
|
|
page_zip_fail(("page_zip_validate: content\n"));
|
2006-03-14 14:38:45 +00:00
|
|
|
valid = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
func_exit:
|
2008-09-29 08:26:42 +00:00
|
|
|
if (!valid) {
|
|
|
|
page_zip_hexdump(page_zip, sizeof *page_zip);
|
|
|
|
page_zip_hexdump(page_zip->data, page_zip_get_size(page_zip));
|
|
|
|
page_zip_hexdump(page, UNIV_PAGE_SIZE);
|
|
|
|
page_zip_hexdump(temp_page, UNIV_PAGE_SIZE);
|
|
|
|
}
|
2006-07-28 07:34:33 +00:00
|
|
|
ut_free(temp_page_buf);
|
2005-11-24 14:13:10 +00:00
|
|
|
return(valid);
|
2005-10-27 11:48:10 +00:00
|
|
|
}
|
2008-10-06 07:13:52 +00:00
|
|
|
|
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Check that the compressed and decompressed pages match.
|
|
|
|
@return TRUE if valid, FALSE if not */
|
2008-10-06 07:13:52 +00:00
|
|
|
UNIV_INTERN
|
|
|
|
ibool
|
|
|
|
page_zip_validate(
|
|
|
|
/*==============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_zip_des_t* page_zip,/*!< in: compressed page */
|
|
|
|
const page_t* page) /*!< in: uncompressed page */
|
2008-10-06 07:13:52 +00:00
|
|
|
{
|
|
|
|
return(page_zip_validate_low(page_zip, page,
|
|
|
|
recv_recovery_is_on()));
|
|
|
|
}
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-05-02 11:44:39 +00:00
|
|
|
#ifdef UNIV_DEBUG
|
2009-05-20 08:19:40 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Assert that the compressed and decompressed page headers match.
|
|
|
|
@return TRUE */
|
2006-05-02 11:44:39 +00:00
|
|
|
static
|
|
|
|
ibool
|
|
|
|
page_zip_header_cmp(
|
|
|
|
/*================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const page_zip_des_t* page_zip,/*!< in: compressed page */
|
|
|
|
const byte* page) /*!< in: uncompressed page */
|
2006-05-02 11:44:39 +00:00
|
|
|
{
|
|
|
|
ut_ad(!memcmp(page_zip->data + FIL_PAGE_PREV, page + FIL_PAGE_PREV,
|
2006-08-29 09:30:31 +00:00
|
|
|
FIL_PAGE_LSN - FIL_PAGE_PREV));
|
2006-05-02 11:44:39 +00:00
|
|
|
ut_ad(!memcmp(page_zip->data + FIL_PAGE_TYPE, page + FIL_PAGE_TYPE,
|
2006-08-29 09:30:31 +00:00
|
|
|
2));
|
2006-05-02 11:44:39 +00:00
|
|
|
ut_ad(!memcmp(page_zip->data + FIL_PAGE_DATA, page + FIL_PAGE_DATA,
|
2006-08-29 09:30:31 +00:00
|
|
|
PAGE_DATA - FIL_PAGE_DATA));
|
2006-05-02 11:44:39 +00:00
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
2007-02-05 14:05:39 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Write a record on the compressed page that contains externally stored
|
2009-05-25 05:30:14 +00:00
|
|
|
columns. The data must already have been written to the uncompressed page.
|
|
|
|
@return end of modification log */
|
2007-02-05 14:05:39 +00:00
|
|
|
static
|
|
|
|
byte*
|
|
|
|
page_zip_write_rec_ext(
|
|
|
|
/*===================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip, /*!< in/out: compressed page */
|
|
|
|
const page_t* page, /*!< in: page containing rec */
|
|
|
|
const byte* rec, /*!< in: record being written */
|
|
|
|
dict_index_t* index, /*!< in: record descriptor */
|
|
|
|
const ulint* offsets, /*!< in: rec_get_offsets(rec, index) */
|
|
|
|
ulint create, /*!< in: nonzero=insert, zero=update */
|
|
|
|
ulint trx_id_col, /*!< in: position of DB_TRX_ID */
|
|
|
|
ulint heap_no, /*!< in: heap number of rec */
|
|
|
|
byte* storage, /*!< in: end of dense page directory */
|
|
|
|
byte* data) /*!< in: end of modification log */
|
2007-02-05 14:05:39 +00:00
|
|
|
{
|
|
|
|
const byte* start = rec;
|
|
|
|
ulint i;
|
|
|
|
ulint len;
|
|
|
|
byte* externs = storage;
|
|
|
|
ulint n_ext = rec_offs_n_extern(offsets);
|
|
|
|
|
|
|
|
ut_ad(rec_offs_validate(rec, index, offsets));
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets));
|
|
|
|
UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets),
|
|
|
|
rec_offs_extra_size(offsets));
|
2007-02-05 14:05:39 +00:00
|
|
|
|
|
|
|
externs -= (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN)
|
|
|
|
* (page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW);
|
|
|
|
|
|
|
|
/* Note that this will not take into account
|
|
|
|
the BLOB columns of rec if create==TRUE. */
|
|
|
|
ut_ad(data + rec_offs_data_size(offsets)
|
|
|
|
- (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN)
|
|
|
|
- n_ext * BTR_EXTERN_FIELD_REF_SIZE
|
|
|
|
< externs - BTR_EXTERN_FIELD_REF_SIZE * page_zip->n_blobs);
|
|
|
|
|
|
|
|
{
|
|
|
|
ulint blob_no = page_zip_get_n_prev_extern(
|
|
|
|
page_zip, rec, index);
|
|
|
|
byte* ext_end = externs - page_zip->n_blobs
|
|
|
|
* BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
ut_ad(blob_no <= page_zip->n_blobs);
|
|
|
|
externs -= blob_no * BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
if (create) {
|
|
|
|
page_zip->n_blobs += n_ext;
|
2007-12-13 10:57:30 +00:00
|
|
|
ASSERT_ZERO_BLOB(ext_end - n_ext
|
|
|
|
* BTR_EXTERN_FIELD_REF_SIZE);
|
2007-02-05 14:05:39 +00:00
|
|
|
memmove(ext_end - n_ext
|
|
|
|
* BTR_EXTERN_FIELD_REF_SIZE,
|
|
|
|
ext_end,
|
|
|
|
externs - ext_end);
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_a(blob_no + n_ext <= page_zip->n_blobs);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < rec_offs_n_fields(offsets); i++) {
|
|
|
|
const byte* src;
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(i == trx_id_col)) {
|
|
|
|
ut_ad(!rec_offs_nth_extern(offsets,
|
|
|
|
i));
|
|
|
|
ut_ad(!rec_offs_nth_extern(offsets,
|
|
|
|
i + 1));
|
|
|
|
/* Locate trx_id and roll_ptr. */
|
|
|
|
src = rec_get_nth_field(rec, offsets,
|
|
|
|
i, &len);
|
|
|
|
ut_ad(len == DATA_TRX_ID_LEN);
|
|
|
|
ut_ad(src + DATA_TRX_ID_LEN
|
|
|
|
== rec_get_nth_field(
|
|
|
|
rec, offsets,
|
|
|
|
i + 1, &len));
|
|
|
|
ut_ad(len == DATA_ROLL_PTR_LEN);
|
|
|
|
|
|
|
|
/* Log the preceding fields. */
|
2007-12-13 10:57:30 +00:00
|
|
|
ASSERT_ZERO(data, src - start);
|
2007-02-05 14:05:39 +00:00
|
|
|
memcpy(data, start, src - start);
|
|
|
|
data += src - start;
|
|
|
|
start = src + (DATA_TRX_ID_LEN
|
|
|
|
+ DATA_ROLL_PTR_LEN);
|
|
|
|
|
|
|
|
/* Store trx_id and roll_ptr. */
|
|
|
|
memcpy(storage - (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN)
|
|
|
|
* (heap_no - 1),
|
|
|
|
src, DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
|
|
|
i++; /* skip also roll_ptr */
|
|
|
|
} else if (rec_offs_nth_extern(offsets, i)) {
|
|
|
|
src = rec_get_nth_field(rec, offsets,
|
|
|
|
i, &len);
|
|
|
|
|
|
|
|
ut_ad(dict_index_is_clust(index));
|
|
|
|
ut_ad(len
|
|
|
|
>= BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
src += len - BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
2007-12-13 10:57:30 +00:00
|
|
|
ASSERT_ZERO(data, src - start);
|
2007-02-05 14:05:39 +00:00
|
|
|
memcpy(data, start, src - start);
|
|
|
|
data += src - start;
|
|
|
|
start = src + BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
/* Store the BLOB pointer. */
|
|
|
|
externs -= BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
ut_ad(data < externs);
|
|
|
|
memcpy(externs, src, BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Log the last bytes of the record. */
|
|
|
|
len = rec_offs_data_size(offsets) - (start - rec);
|
|
|
|
|
2007-12-13 10:57:30 +00:00
|
|
|
ASSERT_ZERO(data, len);
|
2007-02-05 14:05:39 +00:00
|
|
|
memcpy(data, start, len);
|
|
|
|
data += len;
|
|
|
|
|
|
|
|
return(data);
|
|
|
|
}
|
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
/**************************************************************************
|
2006-02-10 15:06:17 +00:00
|
|
|
Write an entire record on the compressed page. The data must already
|
2005-10-27 11:48:10 +00:00
|
|
|
have been written to the uncompressed page. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 11:48:10 +00:00
|
|
|
void
|
2006-02-10 15:06:17 +00:00
|
|
|
page_zip_write_rec(
|
|
|
|
/*===============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page */
|
|
|
|
const byte* rec, /*!< in: record being written */
|
|
|
|
dict_index_t* index, /*!< in: the index the record belongs to */
|
|
|
|
const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */
|
|
|
|
ulint create) /*!< in: nonzero=insert, zero=update */
|
2005-10-27 11:48:10 +00:00
|
|
|
{
|
2007-02-05 14:05:39 +00:00
|
|
|
const page_t* page;
|
|
|
|
byte* data;
|
|
|
|
byte* storage;
|
|
|
|
ulint heap_no;
|
|
|
|
byte* slot;
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2009-03-23 09:07:20 +00:00
|
|
|
ut_ad(PAGE_ZIP_MATCH(rec, page_zip));
|
2005-10-27 11:48:10 +00:00
|
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
2006-11-27 13:44:32 +00:00
|
|
|
ut_ad(page_zip_get_size(page_zip)
|
|
|
|
> PAGE_DATA + page_zip_dir_size(page_zip));
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_ad(rec_offs_comp(offsets));
|
2006-10-19 07:52:28 +00:00
|
|
|
ut_ad(rec_offs_validate(rec, index, offsets));
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_ad(page_zip->m_start >= PAGE_DATA);
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2007-10-03 12:22:29 +00:00
|
|
|
page = page_align(rec);
|
2006-05-02 11:44:39 +00:00
|
|
|
|
|
|
|
ut_ad(page_zip_header_cmp(page_zip, page));
|
2007-02-05 14:05:39 +00:00
|
|
|
ut_ad(page_simple_validate_new((page_t*) page));
|
2006-05-02 11:44:39 +00:00
|
|
|
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets));
|
|
|
|
UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets),
|
|
|
|
rec_offs_extra_size(offsets));
|
2007-10-30 08:19:48 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
slot = page_zip_dir_find(page_zip, page_offset(rec));
|
2006-03-20 13:21:11 +00:00
|
|
|
ut_a(slot);
|
2006-03-22 14:10:09 +00:00
|
|
|
/* Copy the delete mark. */
|
2006-10-16 11:42:46 +00:00
|
|
|
if (rec_get_deleted_flag(rec, TRUE)) {
|
2006-03-22 14:10:09 +00:00
|
|
|
*slot |= PAGE_ZIP_DIR_SLOT_DEL >> 8;
|
|
|
|
} else {
|
|
|
|
*slot &= ~(PAGE_ZIP_DIR_SLOT_DEL >> 8);
|
|
|
|
}
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_ad(rec_get_start((rec_t*) rec, offsets) >= page + PAGE_ZIP_START);
|
|
|
|
ut_ad(rec_get_end((rec_t*) rec, offsets) <= page + UNIV_PAGE_SIZE
|
2006-08-29 09:30:31 +00:00
|
|
|
- PAGE_DIR - PAGE_DIR_SLOT_SIZE
|
|
|
|
* page_dir_get_n_slots(page));
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-10-16 11:42:46 +00:00
|
|
|
heap_no = rec_get_heap_no_new(rec);
|
2006-10-20 12:45:53 +00:00
|
|
|
ut_ad(heap_no >= PAGE_HEAP_NO_USER_LOW); /* not infimum or supremum */
|
2006-03-01 13:39:56 +00:00
|
|
|
ut_ad(heap_no < page_dir_get_n_heap(page));
|
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
/* Append to the modification log. */
|
2006-02-10 15:06:17 +00:00
|
|
|
data = page_zip->data + page_zip->m_end;
|
2006-03-07 09:41:31 +00:00
|
|
|
ut_ad(!*data);
|
|
|
|
|
|
|
|
/* Identify the record by writing its heap number - 1.
|
|
|
|
0 is reserved to indicate the end of the modification log. */
|
|
|
|
|
2006-03-14 14:38:45 +00:00
|
|
|
if (UNIV_UNLIKELY(heap_no - 1 >= 64)) {
|
branches/zip: Fix most MSVC (Windows) compilation warnings.
lock_get_table(), locks_row_eq_lock(), buf_page_get_mutex(): Add return
after ut_error. On Windows, ut_error is not declared as "noreturn".
Add explicit type casts when assigning ulint to byte to get rid of
"possible loss of precision" warnings.
struct i_s_table_cache_struct: Declare rows_used, rows_allocd as ulint
instead of ullint. 32 bits should be enough.
fill_innodb_trx_from_cache(), i_s_zip_fill_low(): Cast 64-bit unsigned
integers to longlong when calling Field::store(longlong, bool is_unsigned).
Otherwise, the compiler would implicitly convert them to double and
invoke Field::store(double) instead.
recv_truncate_group(), recv_copy_group(), recv_calc_lsn_on_data_add():
Cast ib_uint64_t expressions to ulint to get rid of "possible loss of
precision" warnings. (There should not be any loss of precision in
these cases.)
log_close(), log_checkpoint_margin(): Declare some variables as ib_uint64_t
instead of ulint, so that there won't be any potential loss of precision.
mach_write_ull(): Cast the second argument of mach_write_to_4() to ulint.
OS_FILE_FROM_FD(): Cast the return value of _get_osfhandle() to HANDLE.
row_merge_dict_table_get_index(): Cast the parameter of mem_free() to (void*)
in order to get rid of the bogus MSVC warning C4090, which has been reported
as MSVC bug 101661:
<http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101661>
row_mysql_read_blob_ref(): To get rid of a bogus MSVC warning C4090,
drop a const qualifier.
2008-03-04 08:57:07 +00:00
|
|
|
*data++ = (byte) (0x80 | (heap_no - 1) >> 7);
|
2006-03-17 14:11:57 +00:00
|
|
|
ut_ad(!*data);
|
2006-03-07 09:41:31 +00:00
|
|
|
}
|
branches/zip: Fix most MSVC (Windows) compilation warnings.
lock_get_table(), locks_row_eq_lock(), buf_page_get_mutex(): Add return
after ut_error. On Windows, ut_error is not declared as "noreturn".
Add explicit type casts when assigning ulint to byte to get rid of
"possible loss of precision" warnings.
struct i_s_table_cache_struct: Declare rows_used, rows_allocd as ulint
instead of ullint. 32 bits should be enough.
fill_innodb_trx_from_cache(), i_s_zip_fill_low(): Cast 64-bit unsigned
integers to longlong when calling Field::store(longlong, bool is_unsigned).
Otherwise, the compiler would implicitly convert them to double and
invoke Field::store(double) instead.
recv_truncate_group(), recv_copy_group(), recv_calc_lsn_on_data_add():
Cast ib_uint64_t expressions to ulint to get rid of "possible loss of
precision" warnings. (There should not be any loss of precision in
these cases.)
log_close(), log_checkpoint_margin(): Declare some variables as ib_uint64_t
instead of ulint, so that there won't be any potential loss of precision.
mach_write_ull(): Cast the second argument of mach_write_to_4() to ulint.
OS_FILE_FROM_FD(): Cast the return value of _get_osfhandle() to HANDLE.
row_merge_dict_table_get_index(): Cast the parameter of mem_free() to (void*)
in order to get rid of the bogus MSVC warning C4090, which has been reported
as MSVC bug 101661:
<http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101661>
row_mysql_read_blob_ref(): To get rid of a bogus MSVC warning C4090,
drop a const qualifier.
2008-03-04 08:57:07 +00:00
|
|
|
*data++ = (byte) ((heap_no - 1) << 1);
|
2006-03-17 14:11:57 +00:00
|
|
|
ut_ad(!*data);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
{
|
2007-10-03 12:22:29 +00:00
|
|
|
const byte* start = rec - rec_offs_extra_size(offsets);
|
2006-02-10 15:06:17 +00:00
|
|
|
const byte* b = rec - REC_N_NEW_EXTRA_BYTES;
|
|
|
|
|
|
|
|
/* Write the extra bytes backwards, so that
|
|
|
|
rec_offs_extra_size() can be easily computed in
|
|
|
|
page_zip_apply_log() by invoking
|
|
|
|
rec_get_offsets_reverse(). */
|
|
|
|
|
|
|
|
while (b != start) {
|
|
|
|
*data++ = *--b;
|
2006-03-17 14:11:57 +00:00
|
|
|
ut_ad(!*data);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the data bytes. Store the uncompressed bytes separately. */
|
2006-11-27 13:44:32 +00:00
|
|
|
storage = page_zip->data + page_zip_get_size(page_zip)
|
2006-10-20 12:45:53 +00:00
|
|
|
- (page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW)
|
2006-08-29 09:30:31 +00:00
|
|
|
* PAGE_ZIP_DIR_SLOT_SIZE;
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
if (page_is_leaf(page)) {
|
|
|
|
ulint len;
|
2006-03-09 17:26:02 +00:00
|
|
|
|
|
|
|
if (dict_index_is_clust(index)) {
|
2006-08-21 10:27:15 +00:00
|
|
|
ulint trx_id_col;
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
trx_id_col = dict_index_get_sys_col_pos(index,
|
|
|
|
DATA_TRX_ID);
|
2006-03-09 17:26:02 +00:00
|
|
|
ut_ad(trx_id_col != ULINT_UNDEFINED);
|
2006-03-13 15:02:16 +00:00
|
|
|
|
2006-08-21 10:27:15 +00:00
|
|
|
/* Store separately trx_id, roll_ptr and
|
|
|
|
the BTR_EXTERN_FIELD_REF of each BLOB column. */
|
2007-02-05 14:05:39 +00:00
|
|
|
if (rec_offs_any_extern(offsets)) {
|
|
|
|
data = page_zip_write_rec_ext(
|
|
|
|
page_zip, page,
|
|
|
|
rec, index, offsets, create,
|
|
|
|
trx_id_col, heap_no, storage, data);
|
|
|
|
} else {
|
|
|
|
/* Locate trx_id and roll_ptr. */
|
|
|
|
const byte* src
|
|
|
|
= rec_get_nth_field(rec, offsets,
|
|
|
|
trx_id_col, &len);
|
|
|
|
ut_ad(len == DATA_TRX_ID_LEN);
|
|
|
|
ut_ad(src + DATA_TRX_ID_LEN
|
|
|
|
== rec_get_nth_field(
|
|
|
|
rec, offsets,
|
|
|
|
trx_id_col + 1, &len));
|
|
|
|
ut_ad(len == DATA_ROLL_PTR_LEN);
|
|
|
|
|
|
|
|
/* Log the preceding fields. */
|
2007-12-13 10:57:30 +00:00
|
|
|
ASSERT_ZERO(data, src - rec);
|
2007-02-05 14:05:39 +00:00
|
|
|
memcpy(data, rec, src - rec);
|
|
|
|
data += src - rec;
|
|
|
|
|
|
|
|
/* Store trx_id and roll_ptr. */
|
|
|
|
memcpy(storage
|
|
|
|
- (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN)
|
|
|
|
* (heap_no - 1),
|
|
|
|
src,
|
|
|
|
DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
|
|
|
|
|
|
|
src += DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN;
|
|
|
|
|
|
|
|
/* Log the last bytes of the record. */
|
|
|
|
len = rec_offs_data_size(offsets)
|
|
|
|
- (src - rec);
|
|
|
|
|
2007-12-13 10:57:30 +00:00
|
|
|
ASSERT_ZERO(data, len);
|
2007-02-05 14:05:39 +00:00
|
|
|
memcpy(data, src, len);
|
|
|
|
data += len;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2006-08-21 10:27:15 +00:00
|
|
|
} else {
|
|
|
|
/* Leaf page of a secondary index:
|
|
|
|
no externally stored columns */
|
|
|
|
ut_ad(dict_index_get_sys_col_pos(index, DATA_TRX_ID)
|
2006-08-29 09:30:31 +00:00
|
|
|
== ULINT_UNDEFINED);
|
2006-08-21 10:27:15 +00:00
|
|
|
ut_ad(!rec_offs_any_extern(offsets));
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2007-02-05 14:05:39 +00:00
|
|
|
/* Log the entire record. */
|
|
|
|
len = rec_offs_data_size(offsets);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2007-12-13 10:57:30 +00:00
|
|
|
ASSERT_ZERO(data, len);
|
2007-02-05 14:05:39 +00:00
|
|
|
memcpy(data, rec, len);
|
|
|
|
data += len;
|
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
} else {
|
|
|
|
/* This is a node pointer page. */
|
|
|
|
ulint len;
|
|
|
|
|
|
|
|
/* Non-leaf nodes should not have any externally
|
|
|
|
stored columns. */
|
|
|
|
ut_ad(!rec_offs_any_extern(offsets));
|
|
|
|
|
|
|
|
/* Copy the data bytes, except node_ptr. */
|
|
|
|
len = rec_offs_data_size(offsets) - REC_NODE_PTR_SIZE;
|
2006-03-09 17:26:02 +00:00
|
|
|
ut_ad(data + len < storage - REC_NODE_PTR_SIZE
|
2006-10-20 12:45:53 +00:00
|
|
|
* (page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW));
|
2007-12-13 10:57:30 +00:00
|
|
|
ASSERT_ZERO(data, len);
|
2006-02-10 15:06:17 +00:00
|
|
|
memcpy(data, rec, len);
|
|
|
|
data += len;
|
|
|
|
|
|
|
|
/* Copy the node pointer to the uncompressed area. */
|
|
|
|
memcpy(storage - REC_NODE_PTR_SIZE
|
2006-08-29 09:30:31 +00:00
|
|
|
* (heap_no - 1),
|
|
|
|
rec + len,
|
|
|
|
REC_NODE_PTR_SIZE);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2006-03-06 21:00:05 +00:00
|
|
|
ut_a(!*data);
|
2006-11-27 13:44:32 +00:00
|
|
|
ut_ad((ulint) (data - page_zip->data) < page_zip_get_size(page_zip));
|
2006-03-09 17:26:02 +00:00
|
|
|
page_zip->m_end = data - page_zip->data;
|
2006-11-30 14:09:29 +00:00
|
|
|
page_zip->m_nonempty = TRUE;
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2007-10-03 12:22:29 +00:00
|
|
|
ut_a(page_zip_validate(page_zip, page_align(rec)));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2006-04-07 12:56:22 +00:00
|
|
|
/***************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Parses a log record of writing a BLOB pointer of a record.
|
|
|
|
@return end of log record or NULL */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-04-07 12:56:22 +00:00
|
|
|
byte*
|
|
|
|
page_zip_parse_write_blob_ptr(
|
|
|
|
/*==========================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
byte* ptr, /*!< in: redo log buffer */
|
|
|
|
byte* end_ptr,/*!< in: redo log buffer end */
|
|
|
|
page_t* page, /*!< in/out: uncompressed page */
|
|
|
|
page_zip_des_t* page_zip)/*!< in/out: compressed page */
|
2006-04-07 12:56:22 +00:00
|
|
|
{
|
|
|
|
ulint offset;
|
|
|
|
ulint z_offset;
|
|
|
|
|
|
|
|
ut_ad(!page == !page_zip);
|
|
|
|
|
2006-08-29 09:30:31 +00:00
|
|
|
if (UNIV_UNLIKELY
|
|
|
|
(end_ptr < ptr + (2 + 2 + BTR_EXTERN_FIELD_REF_SIZE))) {
|
2006-04-07 12:56:22 +00:00
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = mach_read_from_2(ptr);
|
|
|
|
z_offset = mach_read_from_2(ptr + 2);
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(offset < PAGE_ZIP_START)
|
2006-08-29 09:30:31 +00:00
|
|
|
|| UNIV_UNLIKELY(offset >= UNIV_PAGE_SIZE)
|
|
|
|
|| UNIV_UNLIKELY(z_offset >= UNIV_PAGE_SIZE)) {
|
2006-04-07 12:56:22 +00:00
|
|
|
corrupt:
|
|
|
|
recv_sys->found_corrupt_log = TRUE;
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page) {
|
2006-05-30 09:04:57 +00:00
|
|
|
if (UNIV_UNLIKELY(!page_zip)
|
2006-08-29 09:30:31 +00:00
|
|
|
|| UNIV_UNLIKELY(!page_is_leaf(page))) {
|
2006-04-07 12:56:22 +00:00
|
|
|
|
|
|
|
goto corrupt;
|
|
|
|
}
|
|
|
|
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-05-30 09:04:57 +00:00
|
|
|
ut_a(page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-05-30 09:04:57 +00:00
|
|
|
|
2006-04-07 12:56:22 +00:00
|
|
|
memcpy(page + offset,
|
2006-08-29 09:30:31 +00:00
|
|
|
ptr + 4, BTR_EXTERN_FIELD_REF_SIZE);
|
2006-04-07 12:56:22 +00:00
|
|
|
memcpy(page_zip->data + z_offset,
|
2006-08-29 09:30:31 +00:00
|
|
|
ptr + 4, BTR_EXTERN_FIELD_REF_SIZE);
|
2006-04-07 12:56:22 +00:00
|
|
|
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-04-07 12:56:22 +00:00
|
|
|
ut_a(page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-04-07 12:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(ptr + (2 + 2 + BTR_EXTERN_FIELD_REF_SIZE));
|
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
/**************************************************************************
|
2006-04-07 12:56:22 +00:00
|
|
|
Write a BLOB pointer of a record on the leaf page of a clustered index.
|
2006-02-10 15:06:17 +00:00
|
|
|
The information must already have been updated on the uncompressed page. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-02-10 15:06:17 +00:00
|
|
|
void
|
|
|
|
page_zip_write_blob_ptr(
|
|
|
|
/*====================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page */
|
|
|
|
const byte* rec, /*!< in/out: record whose data is being
|
2006-02-10 15:06:17 +00:00
|
|
|
written */
|
2009-05-25 05:30:14 +00:00
|
|
|
dict_index_t* index, /*!< in: index of the page */
|
|
|
|
const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */
|
|
|
|
ulint n, /*!< in: column index */
|
|
|
|
mtr_t* mtr) /*!< in: mini-transaction handle,
|
2006-02-10 15:06:17 +00:00
|
|
|
or NULL if no logging is needed */
|
|
|
|
{
|
2006-10-19 07:27:26 +00:00
|
|
|
const byte* field;
|
|
|
|
byte* externs;
|
2007-10-03 12:22:29 +00:00
|
|
|
const page_t* page = page_align(rec);
|
2006-10-19 07:27:26 +00:00
|
|
|
ulint blob_no;
|
|
|
|
ulint len;
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2009-03-23 09:07:20 +00:00
|
|
|
ut_ad(PAGE_ZIP_MATCH(rec, page_zip));
|
2007-10-03 12:22:29 +00:00
|
|
|
ut_ad(page_simple_validate_new((page_t*) page));
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
2006-11-27 13:44:32 +00:00
|
|
|
ut_ad(page_zip_get_size(page_zip)
|
|
|
|
> PAGE_DATA + page_zip_dir_size(page_zip));
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_ad(rec_offs_comp(offsets));
|
2006-10-16 11:42:46 +00:00
|
|
|
ut_ad(rec_offs_validate(rec, NULL, offsets));
|
2007-02-05 11:19:25 +00:00
|
|
|
ut_ad(rec_offs_any_extern(offsets));
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_ad(rec_offs_nth_extern(offsets, n));
|
|
|
|
|
|
|
|
ut_ad(page_zip->m_start >= PAGE_DATA);
|
2006-05-02 11:44:39 +00:00
|
|
|
ut_ad(page_zip_header_cmp(page_zip, page));
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
ut_ad(page_is_leaf(page));
|
2006-08-21 10:27:15 +00:00
|
|
|
ut_ad(dict_index_is_clust(index));
|
2006-02-10 15:06:17 +00:00
|
|
|
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets));
|
|
|
|
UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets),
|
|
|
|
rec_offs_extra_size(offsets));
|
2007-10-30 08:19:48 +00:00
|
|
|
|
2006-03-16 14:02:22 +00:00
|
|
|
blob_no = page_zip_get_n_prev_extern(page_zip, rec, index)
|
2006-08-29 09:30:31 +00:00
|
|
|
+ rec_get_n_extern_new(rec, index, n);
|
2006-04-07 12:56:22 +00:00
|
|
|
ut_a(blob_no < page_zip->n_blobs);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-11-27 13:44:32 +00:00
|
|
|
externs = page_zip->data + page_zip_get_size(page_zip)
|
2006-10-20 12:45:53 +00:00
|
|
|
- (page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW)
|
2006-08-29 09:30:31 +00:00
|
|
|
* (PAGE_ZIP_DIR_SLOT_SIZE
|
|
|
|
+ DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
2006-03-09 17:26:02 +00:00
|
|
|
|
2006-10-19 07:27:26 +00:00
|
|
|
field = rec_get_nth_field(rec, offsets, n, &len);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-04-07 12:56:22 +00:00
|
|
|
externs -= (blob_no + 1) * BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
field += len - BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
memcpy(externs, field, BTR_EXTERN_FIELD_REF_SIZE);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2007-10-03 12:22:29 +00:00
|
|
|
ut_a(page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-03-14 14:38:45 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
if (mtr) {
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2006-09-19 10:14:07 +00:00
|
|
|
byte* log_ptr = mlog_open(
|
|
|
|
mtr, 11 + 2 + 2 + BTR_EXTERN_FIELD_REF_SIZE);
|
2006-04-07 12:56:22 +00:00
|
|
|
if (UNIV_UNLIKELY(!log_ptr)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
log_ptr = mlog_write_initial_log_record_fast(
|
|
|
|
(byte*) field, MLOG_ZIP_WRITE_BLOB_PTR, log_ptr, mtr);
|
|
|
|
mach_write_to_2(log_ptr, page_offset(field));
|
2006-04-11 18:40:44 +00:00
|
|
|
log_ptr += 2;
|
2006-04-07 12:56:22 +00:00
|
|
|
mach_write_to_2(log_ptr, externs - page_zip->data);
|
|
|
|
log_ptr += 2;
|
|
|
|
memcpy(log_ptr, externs, BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
log_ptr += BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
mlog_close(mtr, log_ptr);
|
2009-03-23 14:21:34 +00:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-07 11:04:08 +00:00
|
|
|
/***************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Parses a log record of writing the node pointer of a record.
|
|
|
|
@return end of log record or NULL */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-04-07 11:04:08 +00:00
|
|
|
byte*
|
|
|
|
page_zip_parse_write_node_ptr(
|
|
|
|
/*==========================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
byte* ptr, /*!< in: redo log buffer */
|
|
|
|
byte* end_ptr,/*!< in: redo log buffer end */
|
|
|
|
page_t* page, /*!< in/out: uncompressed page */
|
|
|
|
page_zip_des_t* page_zip)/*!< in/out: compressed page */
|
2006-04-07 11:04:08 +00:00
|
|
|
{
|
|
|
|
ulint offset;
|
|
|
|
ulint z_offset;
|
|
|
|
|
|
|
|
ut_ad(!page == !page_zip);
|
|
|
|
|
2006-04-07 12:56:22 +00:00
|
|
|
if (UNIV_UNLIKELY(end_ptr < ptr + (2 + 2 + REC_NODE_PTR_SIZE))) {
|
2006-04-07 11:04:08 +00:00
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = mach_read_from_2(ptr);
|
|
|
|
z_offset = mach_read_from_2(ptr + 2);
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(offset < PAGE_ZIP_START)
|
2006-08-29 09:30:31 +00:00
|
|
|
|| UNIV_UNLIKELY(offset >= UNIV_PAGE_SIZE)
|
|
|
|
|| UNIV_UNLIKELY(z_offset >= UNIV_PAGE_SIZE)) {
|
2006-04-07 11:04:08 +00:00
|
|
|
corrupt:
|
|
|
|
recv_sys->found_corrupt_log = TRUE;
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page) {
|
|
|
|
byte* storage_end;
|
|
|
|
byte* field;
|
|
|
|
byte* storage;
|
|
|
|
ulint heap_no;
|
|
|
|
|
2006-05-30 09:04:57 +00:00
|
|
|
if (UNIV_UNLIKELY(!page_zip)
|
2006-08-29 09:30:31 +00:00
|
|
|
|| UNIV_UNLIKELY(page_is_leaf(page))) {
|
2006-04-07 11:04:08 +00:00
|
|
|
|
|
|
|
goto corrupt;
|
|
|
|
}
|
|
|
|
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-05-30 09:04:57 +00:00
|
|
|
ut_a(page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-05-30 09:04:57 +00:00
|
|
|
|
2006-04-07 11:04:08 +00:00
|
|
|
field = page + offset;
|
|
|
|
storage = page_zip->data + z_offset;
|
|
|
|
|
2006-11-27 13:44:32 +00:00
|
|
|
storage_end = page_zip->data + page_zip_get_size(page_zip)
|
2006-10-20 12:45:53 +00:00
|
|
|
- (page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW)
|
2006-04-07 11:04:08 +00:00
|
|
|
* PAGE_ZIP_DIR_SLOT_SIZE;
|
|
|
|
|
|
|
|
heap_no = 1 + (storage_end - storage) / REC_NODE_PTR_SIZE;
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY((storage_end - storage) % REC_NODE_PTR_SIZE)
|
2006-10-20 12:45:53 +00:00
|
|
|
|| UNIV_UNLIKELY(heap_no < PAGE_HEAP_NO_USER_LOW)
|
2006-04-07 11:04:08 +00:00
|
|
|
|| UNIV_UNLIKELY(heap_no >= page_dir_get_n_heap(page))) {
|
|
|
|
|
|
|
|
goto corrupt;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(field, ptr + 4, REC_NODE_PTR_SIZE);
|
|
|
|
memcpy(storage, ptr + 4, REC_NODE_PTR_SIZE);
|
|
|
|
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-04-07 11:04:08 +00:00
|
|
|
ut_a(page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-04-07 11:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-07 12:56:22 +00:00
|
|
|
return(ptr + (2 + 2 + REC_NODE_PTR_SIZE));
|
2006-04-07 11:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Write the node pointer of a record on a non-leaf compressed page. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-02-10 15:06:17 +00:00
|
|
|
void
|
|
|
|
page_zip_write_node_ptr(
|
|
|
|
/*====================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page */
|
|
|
|
byte* rec, /*!< in/out: record */
|
|
|
|
ulint size, /*!< in: data size of rec */
|
|
|
|
ulint ptr, /*!< in: node pointer */
|
|
|
|
mtr_t* mtr) /*!< in: mini-transaction, or NULL */
|
2006-02-10 15:06:17 +00:00
|
|
|
{
|
|
|
|
byte* field;
|
|
|
|
byte* storage;
|
2006-10-09 16:22:47 +00:00
|
|
|
page_t* page = page_align(rec);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2009-03-23 09:07:20 +00:00
|
|
|
ut_ad(PAGE_ZIP_MATCH(rec, page_zip));
|
2006-07-31 18:27:17 +00:00
|
|
|
ut_ad(page_simple_validate_new(page));
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
2006-11-27 13:44:32 +00:00
|
|
|
ut_ad(page_zip_get_size(page_zip)
|
|
|
|
> PAGE_DATA + page_zip_dir_size(page_zip));
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_ad(page_rec_is_comp(rec));
|
|
|
|
|
|
|
|
ut_ad(page_zip->m_start >= PAGE_DATA);
|
2006-05-02 11:44:39 +00:00
|
|
|
ut_ad(page_zip_header_cmp(page_zip, page));
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
ut_ad(!page_is_leaf(page));
|
|
|
|
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
|
|
|
UNIV_MEM_ASSERT_RW(rec, size);
|
|
|
|
|
2006-11-27 13:44:32 +00:00
|
|
|
storage = page_zip->data + page_zip_get_size(page_zip)
|
2006-10-20 12:45:53 +00:00
|
|
|
- (page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW)
|
2006-08-29 09:30:31 +00:00
|
|
|
* PAGE_ZIP_DIR_SLOT_SIZE
|
|
|
|
- (rec_get_heap_no_new(rec) - 1) * REC_NODE_PTR_SIZE;
|
2006-02-10 15:06:17 +00:00
|
|
|
field = rec + size - REC_NODE_PTR_SIZE;
|
|
|
|
|
2005-11-30 13:57:54 +00:00
|
|
|
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_a(!memcmp(storage, field, REC_NODE_PTR_SIZE));
|
2005-11-30 13:57:54 +00:00
|
|
|
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
|
2006-02-10 15:06:17 +00:00
|
|
|
#if REC_NODE_PTR_SIZE != 4
|
|
|
|
# error "REC_NODE_PTR_SIZE != 4"
|
|
|
|
#endif
|
|
|
|
mach_write_to_4(field, ptr);
|
|
|
|
memcpy(storage, field, REC_NODE_PTR_SIZE);
|
|
|
|
|
|
|
|
if (mtr) {
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2006-04-11 18:40:44 +00:00
|
|
|
byte* log_ptr = mlog_open(mtr,
|
2006-08-29 09:30:31 +00:00
|
|
|
11 + 2 + 2 + REC_NODE_PTR_SIZE);
|
2006-04-07 11:04:08 +00:00
|
|
|
if (UNIV_UNLIKELY(!log_ptr)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
log_ptr = mlog_write_initial_log_record_fast(
|
|
|
|
field, MLOG_ZIP_WRITE_NODE_PTR, log_ptr, mtr);
|
|
|
|
mach_write_to_2(log_ptr, page_offset(field));
|
2006-04-11 18:40:44 +00:00
|
|
|
log_ptr += 2;
|
2006-04-07 11:04:08 +00:00
|
|
|
mach_write_to_2(log_ptr, storage - page_zip->data);
|
|
|
|
log_ptr += 2;
|
2006-04-07 12:56:22 +00:00
|
|
|
memcpy(log_ptr, field, REC_NODE_PTR_SIZE);
|
2006-05-30 09:04:57 +00:00
|
|
|
log_ptr += REC_NODE_PTR_SIZE;
|
|
|
|
mlog_close(mtr, log_ptr);
|
2009-03-23 14:21:34 +00:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2005-10-27 11:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2006-03-09 17:26:02 +00:00
|
|
|
Write the trx_id and roll_ptr of a record on a B-tree leaf node page. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-02-10 15:06:17 +00:00
|
|
|
void
|
2006-03-09 17:26:02 +00:00
|
|
|
page_zip_write_trx_id_and_roll_ptr(
|
|
|
|
/*===============================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page */
|
|
|
|
byte* rec, /*!< in/out: record */
|
|
|
|
const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */
|
|
|
|
ulint trx_id_col,/*!< in: column number of TRX_ID in rec */
|
|
|
|
trx_id_t trx_id, /*!< in: transaction identifier */
|
|
|
|
roll_ptr_t roll_ptr)/*!< in: roll_ptr */
|
2005-10-27 11:48:10 +00:00
|
|
|
{
|
2006-02-10 15:06:17 +00:00
|
|
|
byte* field;
|
|
|
|
byte* storage;
|
2006-09-19 10:14:07 +00:00
|
|
|
page_t* page = page_align(rec);
|
2006-03-09 17:26:02 +00:00
|
|
|
ulint len;
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2009-03-23 09:07:20 +00:00
|
|
|
ut_ad(PAGE_ZIP_MATCH(rec, page_zip));
|
2006-07-31 18:27:17 +00:00
|
|
|
ut_ad(page_simple_validate_new(page));
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
2006-11-27 13:44:32 +00:00
|
|
|
ut_ad(page_zip_get_size(page_zip)
|
|
|
|
> PAGE_DATA + page_zip_dir_size(page_zip));
|
2006-03-09 17:26:02 +00:00
|
|
|
ut_ad(rec_offs_validate(rec, NULL, offsets));
|
|
|
|
ut_ad(rec_offs_comp(offsets));
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
ut_ad(page_zip->m_start >= PAGE_DATA);
|
2006-05-02 11:44:39 +00:00
|
|
|
ut_ad(page_zip_header_cmp(page_zip, page));
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
ut_ad(page_is_leaf(page));
|
|
|
|
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
|
|
|
|
2006-11-27 13:44:32 +00:00
|
|
|
storage = page_zip->data + page_zip_get_size(page_zip)
|
2006-10-20 12:45:53 +00:00
|
|
|
- (page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW)
|
2006-08-29 09:30:31 +00:00
|
|
|
* PAGE_ZIP_DIR_SLOT_SIZE
|
|
|
|
- (rec_get_heap_no_new(rec) - 1)
|
|
|
|
* (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
2006-03-09 17:26:02 +00:00
|
|
|
|
|
|
|
#if DATA_TRX_ID + 1 != DATA_ROLL_PTR
|
|
|
|
# error "DATA_TRX_ID + 1 != DATA_ROLL_PTR"
|
|
|
|
#endif
|
|
|
|
field = rec_get_nth_field(rec, offsets, trx_id_col, &len);
|
|
|
|
ut_ad(len == DATA_TRX_ID_LEN);
|
|
|
|
ut_ad(field + DATA_TRX_ID_LEN
|
2006-08-29 09:30:31 +00:00
|
|
|
== rec_get_nth_field(rec, offsets, trx_id_col + 1, &len));
|
2006-03-09 17:26:02 +00:00
|
|
|
ut_ad(len == DATA_ROLL_PTR_LEN);
|
2006-02-10 15:06:17 +00:00
|
|
|
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
|
|
|
|
ut_a(!memcmp(storage, field, DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN));
|
|
|
|
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
|
|
|
|
#if DATA_TRX_ID_LEN != 6
|
|
|
|
# error "DATA_TRX_ID_LEN != 6"
|
|
|
|
#endif
|
|
|
|
mach_write_to_6(field, trx_id);
|
|
|
|
#if DATA_ROLL_PTR_LEN != 7
|
|
|
|
# error "DATA_ROLL_PTR_LEN != 7"
|
|
|
|
#endif
|
2006-03-22 10:31:18 +00:00
|
|
|
mach_write_to_7(field + DATA_TRX_ID_LEN, roll_ptr);
|
2006-03-09 17:26:02 +00:00
|
|
|
memcpy(storage, field, DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
2007-10-30 08:19:48 +00:00
|
|
|
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets));
|
|
|
|
UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets),
|
|
|
|
rec_offs_extra_size(offsets));
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2006-08-04 11:46:20 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
|
|
|
/* Set this variable in a debugger to disable page_zip_clear_rec().
|
|
|
|
The only observable effect should be the compression ratio due to
|
2006-08-09 11:17:59 +00:00
|
|
|
deleted records not being zeroed out. In rare cases, there can be
|
|
|
|
page_zip_validate() failures on the node_ptr, trx_id and roll_ptr
|
|
|
|
columns if the space is reallocated for a smaller record. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN ibool page_zip_clear_rec_disable;
|
2006-08-04 11:46:20 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Clear an area on the uncompressed and compressed page, if possible. */
|
2006-03-23 08:13:08 +00:00
|
|
|
static
|
2006-02-10 15:06:17 +00:00
|
|
|
void
|
|
|
|
page_zip_clear_rec(
|
|
|
|
/*===============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page */
|
|
|
|
byte* rec, /*!< in: record to clear */
|
|
|
|
dict_index_t* index, /*!< in: index of rec */
|
|
|
|
const ulint* offsets)/*!< in: rec_get_offsets(rec, index) */
|
2006-02-10 15:06:17 +00:00
|
|
|
{
|
2006-03-14 14:38:45 +00:00
|
|
|
ulint heap_no;
|
2006-09-19 10:14:07 +00:00
|
|
|
page_t* page = page_align(rec);
|
2006-03-29 14:08:57 +00:00
|
|
|
/* page_zip_validate() would fail here if a record
|
|
|
|
containing externally stored columns is being deleted. */
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_ad(rec_offs_validate(rec, index, offsets));
|
2006-09-19 10:14:07 +00:00
|
|
|
ut_ad(!page_zip_dir_find(page_zip, page_offset(rec)));
|
|
|
|
ut_ad(page_zip_dir_find_free(page_zip, page_offset(rec)));
|
2006-08-03 08:06:45 +00:00
|
|
|
ut_ad(page_zip_header_cmp(page_zip, page));
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-03-14 14:38:45 +00:00
|
|
|
heap_no = rec_get_heap_no_new(rec);
|
2006-10-20 12:45:53 +00:00
|
|
|
ut_ad(heap_no >= PAGE_HEAP_NO_USER_LOW);
|
2006-03-14 14:38:45 +00:00
|
|
|
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets));
|
|
|
|
UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets),
|
|
|
|
rec_offs_extra_size(offsets));
|
2007-10-30 08:19:48 +00:00
|
|
|
|
2006-08-04 11:46:20 +00:00
|
|
|
if (
|
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-08-29 09:30:31 +00:00
|
|
|
!page_zip_clear_rec_disable &&
|
2006-08-04 11:46:20 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-08-29 09:30:31 +00:00
|
|
|
page_zip->m_end
|
|
|
|
+ 1 + ((heap_no - 1) >= 64)/* size of the log entry */
|
2007-02-19 14:51:44 +00:00
|
|
|
+ page_zip_get_trailer_len(page_zip,
|
|
|
|
dict_index_is_clust(index), NULL)
|
2006-11-27 13:44:32 +00:00
|
|
|
< page_zip_get_size(page_zip)) {
|
2006-03-14 14:38:45 +00:00
|
|
|
byte* data;
|
2006-03-16 14:02:22 +00:00
|
|
|
|
|
|
|
/* Clear only the data bytes, because the allocator and
|
|
|
|
the decompressor depend on the extra bytes. */
|
2006-02-10 15:06:17 +00:00
|
|
|
memset(rec, 0, rec_offs_data_size(offsets));
|
|
|
|
|
2006-03-28 07:57:47 +00:00
|
|
|
if (!page_is_leaf(page)) {
|
|
|
|
/* Clear node_ptr on the compressed page. */
|
2006-11-27 13:44:32 +00:00
|
|
|
byte* storage = page_zip->data
|
|
|
|
+ page_zip_get_size(page_zip)
|
2006-10-20 12:45:53 +00:00
|
|
|
- (page_dir_get_n_heap(page)
|
|
|
|
- PAGE_HEAP_NO_USER_LOW)
|
2006-08-29 09:30:31 +00:00
|
|
|
* PAGE_ZIP_DIR_SLOT_SIZE;
|
2006-03-28 07:57:47 +00:00
|
|
|
|
|
|
|
memset(storage - (heap_no - 1) * REC_NODE_PTR_SIZE,
|
2006-08-29 09:30:31 +00:00
|
|
|
0, REC_NODE_PTR_SIZE);
|
2006-07-31 06:43:25 +00:00
|
|
|
} else if (dict_index_is_clust(index)) {
|
2006-03-16 14:02:22 +00:00
|
|
|
/* Clear trx_id and roll_ptr on the compressed page. */
|
2006-11-27 13:44:32 +00:00
|
|
|
byte* storage = page_zip->data
|
|
|
|
+ page_zip_get_size(page_zip)
|
2006-10-20 12:45:53 +00:00
|
|
|
- (page_dir_get_n_heap(page)
|
|
|
|
- PAGE_HEAP_NO_USER_LOW)
|
2006-08-29 09:30:31 +00:00
|
|
|
* PAGE_ZIP_DIR_SLOT_SIZE;
|
2006-03-16 14:02:22 +00:00
|
|
|
|
|
|
|
memset(storage - (heap_no - 1)
|
2006-08-29 09:30:31 +00:00
|
|
|
* (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN),
|
|
|
|
0, DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
2006-03-16 14:02:22 +00:00
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Log that the data was zeroed out. */
|
2006-03-14 14:38:45 +00:00
|
|
|
data = page_zip->data + page_zip->m_end;
|
|
|
|
ut_ad(!*data);
|
|
|
|
if (UNIV_UNLIKELY(heap_no - 1 >= 64)) {
|
branches/zip: Fix most MSVC (Windows) compilation warnings.
lock_get_table(), locks_row_eq_lock(), buf_page_get_mutex(): Add return
after ut_error. On Windows, ut_error is not declared as "noreturn".
Add explicit type casts when assigning ulint to byte to get rid of
"possible loss of precision" warnings.
struct i_s_table_cache_struct: Declare rows_used, rows_allocd as ulint
instead of ullint. 32 bits should be enough.
fill_innodb_trx_from_cache(), i_s_zip_fill_low(): Cast 64-bit unsigned
integers to longlong when calling Field::store(longlong, bool is_unsigned).
Otherwise, the compiler would implicitly convert them to double and
invoke Field::store(double) instead.
recv_truncate_group(), recv_copy_group(), recv_calc_lsn_on_data_add():
Cast ib_uint64_t expressions to ulint to get rid of "possible loss of
precision" warnings. (There should not be any loss of precision in
these cases.)
log_close(), log_checkpoint_margin(): Declare some variables as ib_uint64_t
instead of ulint, so that there won't be any potential loss of precision.
mach_write_ull(): Cast the second argument of mach_write_to_4() to ulint.
OS_FILE_FROM_FD(): Cast the return value of _get_osfhandle() to HANDLE.
row_merge_dict_table_get_index(): Cast the parameter of mem_free() to (void*)
in order to get rid of the bogus MSVC warning C4090, which has been reported
as MSVC bug 101661:
<http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101661>
row_mysql_read_blob_ref(): To get rid of a bogus MSVC warning C4090,
drop a const qualifier.
2008-03-04 08:57:07 +00:00
|
|
|
*data++ = (byte) (0x80 | (heap_no - 1) >> 7);
|
2006-03-17 14:11:57 +00:00
|
|
|
ut_ad(!*data);
|
2006-03-14 14:38:45 +00:00
|
|
|
}
|
branches/zip: Fix most MSVC (Windows) compilation warnings.
lock_get_table(), locks_row_eq_lock(), buf_page_get_mutex(): Add return
after ut_error. On Windows, ut_error is not declared as "noreturn".
Add explicit type casts when assigning ulint to byte to get rid of
"possible loss of precision" warnings.
struct i_s_table_cache_struct: Declare rows_used, rows_allocd as ulint
instead of ullint. 32 bits should be enough.
fill_innodb_trx_from_cache(), i_s_zip_fill_low(): Cast 64-bit unsigned
integers to longlong when calling Field::store(longlong, bool is_unsigned).
Otherwise, the compiler would implicitly convert them to double and
invoke Field::store(double) instead.
recv_truncate_group(), recv_copy_group(), recv_calc_lsn_on_data_add():
Cast ib_uint64_t expressions to ulint to get rid of "possible loss of
precision" warnings. (There should not be any loss of precision in
these cases.)
log_close(), log_checkpoint_margin(): Declare some variables as ib_uint64_t
instead of ulint, so that there won't be any potential loss of precision.
mach_write_ull(): Cast the second argument of mach_write_to_4() to ulint.
OS_FILE_FROM_FD(): Cast the return value of _get_osfhandle() to HANDLE.
row_merge_dict_table_get_index(): Cast the parameter of mem_free() to (void*)
in order to get rid of the bogus MSVC warning C4090, which has been reported
as MSVC bug 101661:
<http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101661>
row_mysql_read_blob_ref(): To get rid of a bogus MSVC warning C4090,
drop a const qualifier.
2008-03-04 08:57:07 +00:00
|
|
|
*data++ = (byte) ((heap_no - 1) << 1 | 1);
|
2006-03-14 14:38:45 +00:00
|
|
|
ut_ad(!*data);
|
2006-11-27 13:44:32 +00:00
|
|
|
ut_ad((ulint) (data - page_zip->data)
|
|
|
|
< page_zip_get_size(page_zip));
|
2006-03-14 14:38:45 +00:00
|
|
|
page_zip->m_end = data - page_zip->data;
|
2006-11-30 14:09:29 +00:00
|
|
|
page_zip->m_nonempty = TRUE;
|
2006-08-21 10:27:15 +00:00
|
|
|
} else if (page_is_leaf(page) && dict_index_is_clust(index)) {
|
2006-08-01 07:58:38 +00:00
|
|
|
/* Do not clear the record, because there is not enough space
|
|
|
|
to log the operation. */
|
|
|
|
|
2007-02-02 16:20:48 +00:00
|
|
|
if (rec_offs_any_extern(offsets)) {
|
|
|
|
ulint i;
|
|
|
|
|
|
|
|
for (i = rec_offs_n_fields(offsets); i--; ) {
|
|
|
|
/* Clear all BLOB pointers in order to make
|
|
|
|
page_zip_validate() pass. */
|
|
|
|
if (rec_offs_nth_extern(offsets, i)) {
|
|
|
|
ulint len;
|
|
|
|
byte* field = rec_get_nth_field(
|
|
|
|
rec, offsets, i, &len);
|
|
|
|
memset(field + len
|
|
|
|
- BTR_EXTERN_FIELD_REF_SIZE,
|
|
|
|
0, BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
}
|
2006-08-01 07:58:38 +00:00
|
|
|
}
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-01 07:58:38 +00:00
|
|
|
|
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
|
|
|
ut_a(page_zip_validate(page_zip, page));
|
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Write the "deleted" flag of a record on a compressed page. The flag must
|
|
|
|
already have been written on the uncompressed page. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-02-10 15:06:17 +00:00
|
|
|
void
|
|
|
|
page_zip_rec_set_deleted(
|
|
|
|
/*=====================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page */
|
|
|
|
const byte* rec, /*!< in: record on the uncompressed page */
|
|
|
|
ulint flag) /*!< in: the deleted flag (nonzero=TRUE) */
|
2006-02-10 15:06:17 +00:00
|
|
|
{
|
2006-09-19 10:14:07 +00:00
|
|
|
byte* slot = page_zip_dir_find(page_zip, page_offset(rec));
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_a(slot);
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2006-02-10 15:06:17 +00:00
|
|
|
if (flag) {
|
|
|
|
*slot |= (PAGE_ZIP_DIR_SLOT_DEL >> 8);
|
|
|
|
} else {
|
|
|
|
*slot &= ~(PAGE_ZIP_DIR_SLOT_DEL >> 8);
|
|
|
|
}
|
2007-11-28 11:22:25 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
|
|
|
ut_a(page_zip_validate(page_zip, page_align(rec)));
|
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Write the "owned" flag of a record on a compressed page. The n_owned field
|
|
|
|
must already have been written on the uncompressed page. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-02-10 15:06:17 +00:00
|
|
|
void
|
|
|
|
page_zip_rec_set_owned(
|
|
|
|
/*===================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page */
|
|
|
|
const byte* rec, /*!< in: record on the uncompressed page */
|
|
|
|
ulint flag) /*!< in: the owned flag (nonzero=TRUE) */
|
2006-02-10 15:06:17 +00:00
|
|
|
{
|
2006-09-19 10:14:07 +00:00
|
|
|
byte* slot = page_zip_dir_find(page_zip, page_offset(rec));
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_a(slot);
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2006-02-10 15:06:17 +00:00
|
|
|
if (flag) {
|
|
|
|
*slot |= (PAGE_ZIP_DIR_SLOT_OWNED >> 8);
|
|
|
|
} else {
|
|
|
|
*slot &= ~(PAGE_ZIP_DIR_SLOT_OWNED >> 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-18 19:30:55 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Insert a record to the dense page directory. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-08-18 19:30:55 +00:00
|
|
|
void
|
|
|
|
page_zip_dir_insert(
|
|
|
|
/*================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page */
|
|
|
|
const byte* prev_rec,/*!< in: record after which to insert */
|
|
|
|
const byte* free_rec,/*!< in: record from which rec was
|
2006-08-18 19:30:55 +00:00
|
|
|
allocated, or NULL */
|
2009-05-25 05:30:14 +00:00
|
|
|
byte* rec) /*!< in: record to insert */
|
2006-08-18 19:30:55 +00:00
|
|
|
{
|
|
|
|
ulint n_dense;
|
|
|
|
byte* slot_rec;
|
|
|
|
byte* slot_free;
|
|
|
|
|
|
|
|
ut_ad(prev_rec != rec);
|
|
|
|
ut_ad(page_rec_get_next((rec_t*) prev_rec) == rec);
|
2006-08-22 08:34:14 +00:00
|
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
2006-08-18 19:30:55 +00:00
|
|
|
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
|
|
|
|
2006-08-18 19:30:55 +00:00
|
|
|
if (page_rec_is_infimum(prev_rec)) {
|
|
|
|
/* Use the first slot. */
|
2006-11-27 13:44:32 +00:00
|
|
|
slot_rec = page_zip->data + page_zip_get_size(page_zip);
|
2006-08-18 19:30:55 +00:00
|
|
|
} else {
|
2006-11-27 13:44:32 +00:00
|
|
|
byte* end = page_zip->data + page_zip_get_size(page_zip);
|
2006-08-22 08:34:14 +00:00
|
|
|
byte* start = end - page_zip_dir_user_size(page_zip);
|
|
|
|
|
|
|
|
if (UNIV_LIKELY(!free_rec)) {
|
|
|
|
/* PAGE_N_RECS was already incremented
|
2007-02-01 09:53:26 +00:00
|
|
|
in page_cur_insert_rec_zip(), but the
|
2006-08-22 08:34:14 +00:00
|
|
|
dense directory slot at that position
|
|
|
|
contains garbage. Skip it. */
|
|
|
|
start += PAGE_ZIP_DIR_SLOT_SIZE;
|
|
|
|
}
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
slot_rec = page_zip_dir_find_low(start, end,
|
|
|
|
page_offset(prev_rec));
|
2006-08-18 19:30:55 +00:00
|
|
|
ut_a(slot_rec);
|
|
|
|
}
|
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
/* Read the old n_dense (n_heap may have been incremented). */
|
|
|
|
n_dense = page_dir_get_n_heap(page_zip->data)
|
|
|
|
- (PAGE_HEAP_NO_USER_LOW + 1);
|
2006-08-18 19:30:55 +00:00
|
|
|
|
|
|
|
if (UNIV_LIKELY_NULL(free_rec)) {
|
|
|
|
/* The record was allocated from the free list.
|
|
|
|
Shift the dense directory only up to that slot.
|
|
|
|
Note that in this case, n_dense is actually
|
2007-02-01 09:53:26 +00:00
|
|
|
off by one, because page_cur_insert_rec_zip()
|
2006-08-18 19:30:55 +00:00
|
|
|
did not increment n_heap. */
|
|
|
|
ut_ad(rec_get_heap_no_new(rec) < n_dense + 1
|
2006-10-20 12:45:53 +00:00
|
|
|
+ PAGE_HEAP_NO_USER_LOW);
|
2006-08-18 19:30:55 +00:00
|
|
|
ut_ad(rec >= free_rec);
|
2006-09-19 10:14:07 +00:00
|
|
|
slot_free = page_zip_dir_find(page_zip, page_offset(free_rec));
|
2006-08-18 19:30:55 +00:00
|
|
|
ut_ad(slot_free);
|
|
|
|
slot_free += PAGE_ZIP_DIR_SLOT_SIZE;
|
|
|
|
} else {
|
|
|
|
/* The record was allocated from the heap.
|
|
|
|
Shift the entire dense directory. */
|
|
|
|
ut_ad(rec_get_heap_no_new(rec) == n_dense
|
2006-10-20 12:45:53 +00:00
|
|
|
+ PAGE_HEAP_NO_USER_LOW);
|
2006-08-18 19:30:55 +00:00
|
|
|
|
|
|
|
/* Shift to the end of the dense page directory. */
|
2006-11-27 13:44:32 +00:00
|
|
|
slot_free = page_zip->data + page_zip_get_size(page_zip)
|
2006-08-29 09:30:31 +00:00
|
|
|
- PAGE_ZIP_DIR_SLOT_SIZE * n_dense;
|
2006-08-18 19:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Shift the dense directory to allocate place for rec. */
|
|
|
|
memmove(slot_free - PAGE_ZIP_DIR_SLOT_SIZE, slot_free,
|
2006-08-29 09:30:31 +00:00
|
|
|
slot_rec - slot_free);
|
2006-08-18 19:30:55 +00:00
|
|
|
|
|
|
|
/* Write the entry for the inserted record.
|
|
|
|
The "owned" and "deleted" flags must be zero. */
|
2006-09-19 10:14:07 +00:00
|
|
|
mach_write_to_2(slot_rec - PAGE_ZIP_DIR_SLOT_SIZE, page_offset(rec));
|
2006-08-18 19:30:55 +00:00
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
/**************************************************************************
|
2006-03-14 14:38:45 +00:00
|
|
|
Shift the dense page directory and the array of BLOB pointers
|
|
|
|
when a record is deleted. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-02-10 15:06:17 +00:00
|
|
|
void
|
|
|
|
page_zip_dir_delete(
|
|
|
|
/*================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page */
|
|
|
|
byte* rec, /*!< in: record to delete */
|
|
|
|
dict_index_t* index, /*!< in: index of rec */
|
|
|
|
const ulint* offsets,/*!< in: rec_get_offsets(rec) */
|
|
|
|
const byte* free) /*!< in: previous start of the free list */
|
2006-02-10 15:06:17 +00:00
|
|
|
{
|
|
|
|
byte* slot_rec;
|
|
|
|
byte* slot_free;
|
2006-03-16 14:02:22 +00:00
|
|
|
ulint n_ext;
|
2006-09-19 10:14:07 +00:00
|
|
|
page_t* page = page_align(rec);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-03-16 14:02:22 +00:00
|
|
|
ut_ad(rec_offs_validate(rec, index, offsets));
|
|
|
|
ut_ad(rec_offs_comp(offsets));
|
2006-03-08 22:19:20 +00:00
|
|
|
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2007-10-31 10:44:15 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets));
|
|
|
|
UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets),
|
|
|
|
rec_offs_extra_size(offsets));
|
2007-10-30 08:19:48 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
slot_rec = page_zip_dir_find(page_zip, page_offset(rec));
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
ut_a(slot_rec);
|
|
|
|
|
2006-03-16 14:02:22 +00:00
|
|
|
/* This could not be done before page_zip_dir_find(). */
|
|
|
|
page_header_set_field(page, page_zip, PAGE_N_RECS,
|
2006-08-29 09:30:31 +00:00
|
|
|
(ulint)(page_get_n_recs(page) - 1));
|
2006-03-16 14:02:22 +00:00
|
|
|
|
2006-03-08 22:19:20 +00:00
|
|
|
if (UNIV_UNLIKELY(!free)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Make the last slot the start of the free list. */
|
2006-11-27 13:44:32 +00:00
|
|
|
slot_free = page_zip->data + page_zip_get_size(page_zip)
|
2006-08-29 09:30:31 +00:00
|
|
|
- PAGE_ZIP_DIR_SLOT_SIZE
|
2006-10-20 12:45:53 +00:00
|
|
|
* (page_dir_get_n_heap(page_zip->data)
|
|
|
|
- PAGE_HEAP_NO_USER_LOW);
|
2006-02-10 15:06:17 +00:00
|
|
|
} else {
|
2006-09-19 10:14:07 +00:00
|
|
|
slot_free = page_zip_dir_find_free(page_zip,
|
|
|
|
page_offset(free));
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_a(slot_free < slot_rec);
|
|
|
|
/* Grow the free list by one slot by moving the start. */
|
|
|
|
slot_free += PAGE_ZIP_DIR_SLOT_SIZE;
|
|
|
|
}
|
|
|
|
|
2006-03-08 22:19:20 +00:00
|
|
|
if (UNIV_LIKELY(slot_rec > slot_free)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
memmove(slot_free + PAGE_ZIP_DIR_SLOT_SIZE,
|
|
|
|
slot_free,
|
2006-03-08 22:19:20 +00:00
|
|
|
slot_rec - slot_free);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the entry for the deleted record.
|
|
|
|
The "owned" and "deleted" flags will be cleared. */
|
2006-09-19 10:14:07 +00:00
|
|
|
mach_write_to_2(slot_free, page_offset(rec));
|
2006-03-16 14:02:22 +00:00
|
|
|
|
2006-08-21 10:27:15 +00:00
|
|
|
if (!page_is_leaf(page) || !dict_index_is_clust(index)) {
|
|
|
|
ut_ad(!rec_offs_any_extern(offsets));
|
|
|
|
goto skip_blobs;
|
|
|
|
}
|
|
|
|
|
2006-03-16 14:02:22 +00:00
|
|
|
n_ext = rec_offs_n_extern(offsets);
|
|
|
|
if (UNIV_UNLIKELY(n_ext)) {
|
|
|
|
/* Shift and zero fill the array of BLOB pointers. */
|
|
|
|
ulint blob_no;
|
|
|
|
byte* externs;
|
|
|
|
byte* ext_end;
|
|
|
|
|
|
|
|
blob_no = page_zip_get_n_prev_extern(page_zip, rec, index);
|
|
|
|
ut_a(blob_no + n_ext <= page_zip->n_blobs);
|
|
|
|
|
2006-11-27 13:44:32 +00:00
|
|
|
externs = page_zip->data + page_zip_get_size(page_zip)
|
2006-10-20 12:45:53 +00:00
|
|
|
- (page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW)
|
2006-08-29 09:30:31 +00:00
|
|
|
* (PAGE_ZIP_DIR_SLOT_SIZE
|
|
|
|
+ DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
2006-03-16 14:02:22 +00:00
|
|
|
|
|
|
|
ext_end = externs - page_zip->n_blobs
|
2006-08-29 09:30:31 +00:00
|
|
|
* BTR_EXTERN_FIELD_REF_SIZE;
|
2006-03-16 14:02:22 +00:00
|
|
|
externs -= blob_no * BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
page_zip->n_blobs -= n_ext;
|
|
|
|
/* Shift and zero fill the array. */
|
|
|
|
memmove(ext_end + n_ext * BTR_EXTERN_FIELD_REF_SIZE, ext_end,
|
2006-08-29 09:30:31 +00:00
|
|
|
(page_zip->n_blobs - blob_no)
|
|
|
|
* BTR_EXTERN_FIELD_REF_SIZE);
|
2006-03-16 14:02:22 +00:00
|
|
|
memset(ext_end, 0, n_ext * BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
}
|
|
|
|
|
2006-08-21 10:27:15 +00:00
|
|
|
skip_blobs:
|
2006-03-16 14:02:22 +00:00
|
|
|
/* The compression algorithm expects info_bits and n_owned
|
|
|
|
to be 0 for deleted records. */
|
|
|
|
rec[-REC_N_NEW_EXTRA_BYTES] = 0; /* info_bits and n_owned */
|
|
|
|
|
2006-04-10 19:48:37 +00:00
|
|
|
page_zip_clear_rec(page_zip, rec, index, offsets);
|
2005-10-27 11:48:10 +00:00
|
|
|
}
|
2006-02-22 13:02:40 +00:00
|
|
|
|
2006-03-06 21:00:05 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Add a slot to the dense page directory. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-03-06 21:00:05 +00:00
|
|
|
void
|
|
|
|
page_zip_dir_add_slot(
|
|
|
|
/*==================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip, /*!< in/out: compressed page */
|
|
|
|
ulint is_clustered) /*!< in: nonzero for clustered index,
|
2006-03-09 17:26:02 +00:00
|
|
|
zero for others */
|
2006-03-06 21:00:05 +00:00
|
|
|
{
|
|
|
|
ulint n_dense;
|
|
|
|
byte* dir;
|
|
|
|
byte* stored;
|
|
|
|
|
2006-03-09 17:26:02 +00:00
|
|
|
ut_ad(page_is_comp(page_zip->data));
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2006-03-09 17:26:02 +00:00
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
/* Read the old n_dense (n_heap has already been incremented). */
|
|
|
|
n_dense = page_dir_get_n_heap(page_zip->data)
|
|
|
|
- (PAGE_HEAP_NO_USER_LOW + 1);
|
2006-03-06 21:00:05 +00:00
|
|
|
|
2006-11-27 13:44:32 +00:00
|
|
|
dir = page_zip->data + page_zip_get_size(page_zip)
|
2006-08-29 09:30:31 +00:00
|
|
|
- PAGE_ZIP_DIR_SLOT_SIZE * n_dense;
|
2006-03-06 21:00:05 +00:00
|
|
|
|
2006-03-09 17:26:02 +00:00
|
|
|
if (!page_is_leaf(page_zip->data)) {
|
|
|
|
ut_ad(!page_zip->n_blobs);
|
|
|
|
stored = dir - n_dense * REC_NODE_PTR_SIZE;
|
|
|
|
} else if (UNIV_UNLIKELY(is_clustered)) {
|
2006-03-16 14:02:22 +00:00
|
|
|
/* Move the BLOB pointer array backwards to make space for the
|
|
|
|
roll_ptr and trx_id columns and the dense directory slot. */
|
|
|
|
byte* externs;
|
|
|
|
|
2006-03-09 17:26:02 +00:00
|
|
|
stored = dir - n_dense
|
2006-03-16 14:02:22 +00:00
|
|
|
* (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
|
|
|
externs = stored
|
2006-03-06 21:00:05 +00:00
|
|
|
- page_zip->n_blobs * BTR_EXTERN_FIELD_REF_SIZE;
|
2007-12-13 10:57:30 +00:00
|
|
|
ASSERT_ZERO(externs
|
|
|
|
- (PAGE_ZIP_DIR_SLOT_SIZE
|
|
|
|
+ DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN),
|
|
|
|
PAGE_ZIP_DIR_SLOT_SIZE
|
|
|
|
+ DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN);
|
2006-03-16 14:02:22 +00:00
|
|
|
memmove(externs - (PAGE_ZIP_DIR_SLOT_SIZE
|
2006-08-29 09:30:31 +00:00
|
|
|
+ DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN),
|
2006-03-16 14:02:22 +00:00
|
|
|
externs, stored - externs);
|
2006-03-06 21:00:05 +00:00
|
|
|
} else {
|
2006-03-09 17:26:02 +00:00
|
|
|
stored = dir
|
|
|
|
- page_zip->n_blobs * BTR_EXTERN_FIELD_REF_SIZE;
|
2007-12-13 10:57:30 +00:00
|
|
|
ASSERT_ZERO(stored - PAGE_ZIP_DIR_SLOT_SIZE,
|
|
|
|
PAGE_ZIP_DIR_SLOT_SIZE);
|
2006-03-06 21:00:05 +00:00
|
|
|
}
|
|
|
|
|
2006-03-09 17:26:02 +00:00
|
|
|
/* Move the uncompressed area backwards to make space
|
|
|
|
for one directory slot. */
|
|
|
|
memmove(stored - PAGE_ZIP_DIR_SLOT_SIZE, stored, dir - stored);
|
2006-03-06 21:00:05 +00:00
|
|
|
}
|
|
|
|
|
2006-04-07 11:44:14 +00:00
|
|
|
/***************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Parses a log record of writing to the header of a page.
|
|
|
|
@return end of log record or NULL */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-04-07 11:44:14 +00:00
|
|
|
byte*
|
|
|
|
page_zip_parse_write_header(
|
|
|
|
/*========================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
byte* ptr, /*!< in: redo log buffer */
|
|
|
|
byte* end_ptr,/*!< in: redo log buffer end */
|
|
|
|
page_t* page, /*!< in/out: uncompressed page */
|
|
|
|
page_zip_des_t* page_zip)/*!< in/out: compressed page */
|
2006-04-07 11:44:14 +00:00
|
|
|
{
|
|
|
|
ulint offset;
|
|
|
|
ulint len;
|
|
|
|
|
2006-05-16 07:58:10 +00:00
|
|
|
ut_ad(ptr && end_ptr);
|
2006-04-07 11:44:14 +00:00
|
|
|
ut_ad(!page == !page_zip);
|
|
|
|
|
2006-04-11 18:40:44 +00:00
|
|
|
if (UNIV_UNLIKELY(end_ptr < ptr + (1 + 1))) {
|
2006-04-07 11:44:14 +00:00
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2006-04-11 18:40:44 +00:00
|
|
|
offset = (ulint) *ptr++;
|
2006-04-07 11:44:14 +00:00
|
|
|
len = (ulint) *ptr++;
|
|
|
|
|
2006-05-16 07:58:10 +00:00
|
|
|
if (UNIV_UNLIKELY(!len) || UNIV_UNLIKELY(offset + len >= PAGE_DATA)) {
|
|
|
|
corrupt:
|
2006-04-07 11:44:14 +00:00
|
|
|
recv_sys->found_corrupt_log = TRUE;
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(end_ptr < ptr + len)) {
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page) {
|
2006-05-16 07:58:10 +00:00
|
|
|
if (UNIV_UNLIKELY(!page_zip)) {
|
|
|
|
|
|
|
|
goto corrupt;
|
|
|
|
}
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-04-07 11:44:14 +00:00
|
|
|
ut_a(page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-04-07 11:44:14 +00:00
|
|
|
|
|
|
|
memcpy(page + offset, ptr, len);
|
|
|
|
memcpy(page_zip->data + offset, ptr, len);
|
|
|
|
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-04-07 11:44:14 +00:00
|
|
|
ut_a(page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-04-07 11:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(ptr + len);
|
|
|
|
}
|
|
|
|
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2006-02-22 13:02:40 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Write a log record of writing to the uncompressed header portion of a page. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-02-22 13:02:40 +00:00
|
|
|
void
|
|
|
|
page_zip_write_header_log(
|
|
|
|
/*======================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const byte* data, /*!< in: data on the uncompressed page */
|
|
|
|
ulint length, /*!< in: length of the data */
|
|
|
|
mtr_t* mtr) /*!< in: mini-transaction */
|
2006-02-22 13:02:40 +00:00
|
|
|
{
|
2006-04-26 09:35:18 +00:00
|
|
|
byte* log_ptr = mlog_open(mtr, 11 + 1 + 1);
|
2006-09-19 10:14:07 +00:00
|
|
|
ulint offset = page_offset(data);
|
2006-04-26 09:35:18 +00:00
|
|
|
|
2006-02-22 13:02:40 +00:00
|
|
|
ut_ad(offset < PAGE_DATA);
|
|
|
|
ut_ad(offset + length < PAGE_DATA);
|
|
|
|
#if PAGE_DATA > 255
|
|
|
|
# error "PAGE_DATA > 255"
|
|
|
|
#endif
|
|
|
|
ut_ad(length < 256);
|
|
|
|
|
|
|
|
/* If no logging is requested, we may return now */
|
2006-04-07 12:56:22 +00:00
|
|
|
if (UNIV_UNLIKELY(!log_ptr)) {
|
2006-02-22 13:02:40 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
log_ptr = mlog_write_initial_log_record_fast(
|
|
|
|
(byte*) data, MLOG_ZIP_WRITE_HEADER, log_ptr, mtr);
|
2006-04-11 18:40:44 +00:00
|
|
|
*log_ptr++ = (byte) offset;
|
2006-04-07 11:04:08 +00:00
|
|
|
*log_ptr++ = (byte) length;
|
2006-02-22 13:02:40 +00:00
|
|
|
mlog_close(mtr, log_ptr);
|
|
|
|
|
2006-04-26 09:35:18 +00:00
|
|
|
mlog_catenate_string(mtr, data, length);
|
2006-02-22 13:02:40 +00:00
|
|
|
}
|
2009-03-23 14:21:34 +00:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2006-04-11 12:27:06 +00:00
|
|
|
|
2006-05-16 14:17:43 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Reorganize and compress a page. This is a low-level operation for
|
|
|
|
compressed pages, to be used when page_zip_compress() fails.
|
2006-06-19 11:07:21 +00:00
|
|
|
On success, a redo log entry MLOG_ZIP_PAGE_COMPRESS will be written.
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
The function btr_page_reorganize() should be preferred whenever possible.
|
|
|
|
IMPORTANT: if page_zip_reorganize() is invoked on a leaf page of a
|
|
|
|
non-clustered index, the caller must update the insert buffer free
|
|
|
|
bits in the same mini-transaction in such a way that the modification
|
2009-05-25 05:30:14 +00:00
|
|
|
will be redo-logged.
|
|
|
|
@return TRUE on success, FALSE on failure; page and page_zip will be left intact on failure. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-05-16 14:17:43 +00:00
|
|
|
ibool
|
|
|
|
page_zip_reorganize(
|
|
|
|
/*================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
buf_block_t* block, /*!< in/out: page with compressed page;
|
2006-10-18 11:39:31 +00:00
|
|
|
on the compressed page, in: size;
|
2006-11-30 14:09:29 +00:00
|
|
|
out: data, n_blobs,
|
|
|
|
m_start, m_end, m_nonempty */
|
2009-05-25 05:30:14 +00:00
|
|
|
dict_index_t* index, /*!< in: index of the B-tree node */
|
|
|
|
mtr_t* mtr) /*!< in: mini-transaction */
|
2006-05-16 14:17:43 +00:00
|
|
|
{
|
2006-10-18 11:39:31 +00:00
|
|
|
page_zip_des_t* page_zip = buf_block_get_page_zip(block);
|
|
|
|
page_t* page = buf_block_get_frame(block);
|
2006-10-12 12:38:29 +00:00
|
|
|
buf_block_t* temp_block;
|
2006-10-12 11:05:22 +00:00
|
|
|
page_t* temp_page;
|
|
|
|
ulint log_mode;
|
2006-05-16 14:17:43 +00:00
|
|
|
|
2006-10-23 19:14:36 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
|
2006-05-16 14:17:43 +00:00
|
|
|
ut_ad(page_is_comp(page));
|
branches/zip: Write PAGE_MAX_TRX_ID to the redo log. Otherwise,
transactions that are started before the rollback of incomplete
transactions has finished may have an inconsistent view of the
secondary indexes.
dict_index_is_sec_or_ibuf(): Auxiliary function for controlling
updates and checks of PAGE_MAX_TRX_ID: check whether an index is a
secondary index or the insert buffer tree.
page_set_max_trx_id(), page_update_max_trx_id(),
lock_rec_insert_check_and_lock(),
lock_sec_rec_modify_check_and_lock(), btr_cur_ins_lock_and_undo(),
btr_cur_upd_lock_and_undo(): Add the parameter mtr.
page_set_max_trx_id(): Allow mtr to be NULL. When mtr==NULL, do not
attempt to write to the redo log. This only occurs when creating a
page or reorganizing a compressed page. In these cases, the
PAGE_MAX_TRX_ID will be set correctly during the application of redo
log records, even though there is no explicit log record about it.
btr_discard_only_page_on_level(): Preserve PAGE_MAX_TRX_ID. This
function should be unreachable, though.
btr_cur_pessimistic_update(): Update PAGE_MAX_TRX_ID.
Add some assertions for checking that PAGE_MAX_TRX_ID is set on all
secondary index leaf pages.
rb://115 tested by Michael, fixes Issue #211
2009-05-19 18:59:07 +00:00
|
|
|
ut_ad(!dict_index_is_ibuf(index));
|
2006-05-16 14:17:43 +00:00
|
|
|
/* Note that page_zip_validate(page_zip, page) may fail here. */
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(page, UNIV_PAGE_SIZE);
|
|
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
2006-05-16 14:17:43 +00:00
|
|
|
|
|
|
|
/* Disable logging */
|
|
|
|
log_mode = mtr_set_log_mode(mtr, MTR_LOG_NONE);
|
|
|
|
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2006-10-12 12:38:29 +00:00
|
|
|
temp_block = buf_block_alloc(0);
|
2008-01-07 13:40:12 +00:00
|
|
|
btr_search_drop_page_hash_index(block);
|
2009-03-23 14:21:34 +00:00
|
|
|
block->check_index_page_at_flush = TRUE;
|
|
|
|
#else /* !UNIV_HOTBACKUP */
|
|
|
|
ut_ad(block == back_block1);
|
|
|
|
temp_block = back_block2;
|
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
|
|
|
temp_page = temp_block->frame;
|
2008-01-07 13:40:12 +00:00
|
|
|
|
2006-05-16 14:17:43 +00:00
|
|
|
/* Copy the old page to temporary space */
|
|
|
|
buf_frame_copy(temp_page, page);
|
|
|
|
|
|
|
|
/* Recreate the page: note that global data on page (possible
|
|
|
|
segment headers, next page-field, etc.) is preserved intact */
|
|
|
|
|
2008-08-27 06:23:59 +00:00
|
|
|
page_create(block, mtr, TRUE);
|
2006-05-16 14:17:43 +00:00
|
|
|
|
|
|
|
/* Copy the records from the temporary space to the recreated page;
|
|
|
|
do not copy the lock bits yet */
|
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
page_copy_rec_list_end_no_locks(block, temp_block,
|
|
|
|
page_get_infimum_rec(temp_page),
|
2006-09-19 10:14:07 +00:00
|
|
|
index, mtr);
|
branches/zip: Write PAGE_MAX_TRX_ID to the redo log. Otherwise,
transactions that are started before the rollback of incomplete
transactions has finished may have an inconsistent view of the
secondary indexes.
dict_index_is_sec_or_ibuf(): Auxiliary function for controlling
updates and checks of PAGE_MAX_TRX_ID: check whether an index is a
secondary index or the insert buffer tree.
page_set_max_trx_id(), page_update_max_trx_id(),
lock_rec_insert_check_and_lock(),
lock_sec_rec_modify_check_and_lock(), btr_cur_ins_lock_and_undo(),
btr_cur_upd_lock_and_undo(): Add the parameter mtr.
page_set_max_trx_id(): Allow mtr to be NULL. When mtr==NULL, do not
attempt to write to the redo log. This only occurs when creating a
page or reorganizing a compressed page. In these cases, the
PAGE_MAX_TRX_ID will be set correctly during the application of redo
log records, even though there is no explicit log record about it.
btr_discard_only_page_on_level(): Preserve PAGE_MAX_TRX_ID. This
function should be unreachable, though.
btr_cur_pessimistic_update(): Update PAGE_MAX_TRX_ID.
Add some assertions for checking that PAGE_MAX_TRX_ID is set on all
secondary index leaf pages.
rb://115 tested by Michael, fixes Issue #211
2009-05-19 18:59:07 +00:00
|
|
|
|
|
|
|
if (!dict_index_is_clust(index) && page_is_leaf(temp_page)) {
|
|
|
|
/* Copy max trx id to recreated page */
|
|
|
|
trx_id_t max_trx_id = page_get_max_trx_id(temp_page);
|
|
|
|
page_set_max_trx_id(block, NULL, max_trx_id, NULL);
|
|
|
|
ut_ad(!ut_dulint_is_zero(max_trx_id));
|
|
|
|
}
|
2006-05-16 14:17:43 +00:00
|
|
|
|
2006-06-19 11:07:21 +00:00
|
|
|
/* Restore logging. */
|
|
|
|
mtr_set_log_mode(mtr, log_mode);
|
|
|
|
|
2006-05-16 14:17:43 +00:00
|
|
|
if (UNIV_UNLIKELY(!page_zip_compress(page_zip, page, index, mtr))) {
|
|
|
|
|
|
|
|
/* Restore the old page and exit. */
|
|
|
|
buf_frame_copy(page, temp_page);
|
|
|
|
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2006-10-12 12:38:29 +00:00
|
|
|
buf_block_free(temp_block);
|
2009-03-23 14:21:34 +00:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2006-05-16 14:17:43 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
lock_move_reorganize_page(block, temp_block);
|
2006-05-16 14:17:43 +00:00
|
|
|
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2006-10-12 12:38:29 +00:00
|
|
|
buf_block_free(temp_block);
|
2009-03-23 14:21:34 +00:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2006-05-16 14:17:43 +00:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2006-05-11 18:23:10 +00:00
|
|
|
/**************************************************************************
|
2008-09-25 12:17:52 +00:00
|
|
|
Copy the records of a page byte for byte. Do not copy the page header
|
|
|
|
or trailer, except those B-tree header fields that are directly
|
2008-10-15 06:32:40 +00:00
|
|
|
related to the storage of records. Also copy PAGE_MAX_TRX_ID.
|
|
|
|
NOTE: The caller must update the lock table and the adaptive hash index. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-05-11 18:23:10 +00:00
|
|
|
void
|
2008-09-25 12:17:52 +00:00
|
|
|
page_zip_copy_recs(
|
|
|
|
/*===============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
page_zip_des_t* page_zip, /*!< out: copy of src_zip
|
2006-11-24 08:32:18 +00:00
|
|
|
(n_blobs, m_start, m_end,
|
2006-11-30 14:09:29 +00:00
|
|
|
m_nonempty, data[0..size-1]) */
|
2009-05-25 05:30:14 +00:00
|
|
|
page_t* page, /*!< out: copy of src */
|
|
|
|
const page_zip_des_t* src_zip, /*!< in: compressed page */
|
|
|
|
const page_t* src, /*!< in: page */
|
|
|
|
dict_index_t* index, /*!< in: index of the B-tree */
|
|
|
|
mtr_t* mtr) /*!< in: mini-transaction */
|
2006-05-11 18:23:10 +00:00
|
|
|
{
|
2006-10-09 19:36:58 +00:00
|
|
|
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
|
|
|
|
ut_ad(mtr_memo_contains_page(mtr, (page_t*) src, MTR_MEMO_PAGE_X_FIX));
|
branches/zip: Write PAGE_MAX_TRX_ID to the redo log. Otherwise,
transactions that are started before the rollback of incomplete
transactions has finished may have an inconsistent view of the
secondary indexes.
dict_index_is_sec_or_ibuf(): Auxiliary function for controlling
updates and checks of PAGE_MAX_TRX_ID: check whether an index is a
secondary index or the insert buffer tree.
page_set_max_trx_id(), page_update_max_trx_id(),
lock_rec_insert_check_and_lock(),
lock_sec_rec_modify_check_and_lock(), btr_cur_ins_lock_and_undo(),
btr_cur_upd_lock_and_undo(): Add the parameter mtr.
page_set_max_trx_id(): Allow mtr to be NULL. When mtr==NULL, do not
attempt to write to the redo log. This only occurs when creating a
page or reorganizing a compressed page. In these cases, the
PAGE_MAX_TRX_ID will be set correctly during the application of redo
log records, even though there is no explicit log record about it.
btr_discard_only_page_on_level(): Preserve PAGE_MAX_TRX_ID. This
function should be unreachable, though.
btr_cur_pessimistic_update(): Update PAGE_MAX_TRX_ID.
Add some assertions for checking that PAGE_MAX_TRX_ID is set on all
secondary index leaf pages.
rb://115 tested by Michael, fixes Issue #211
2009-05-19 18:59:07 +00:00
|
|
|
ut_ad(!dict_index_is_ibuf(index));
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2008-10-07 12:51:32 +00:00
|
|
|
/* The B-tree operations that call this function may set
|
|
|
|
FIL_PAGE_PREV or PAGE_LEVEL, causing a temporary min_rec_flag
|
|
|
|
mismatch. A strict page_zip_validate() will be executed later
|
|
|
|
during the B-tree operations. */
|
|
|
|
ut_a(page_zip_validate_low(src_zip, src, TRUE));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-11-27 13:44:32 +00:00
|
|
|
ut_a(page_zip_get_size(page_zip) == page_zip_get_size(src_zip));
|
2006-08-21 10:27:15 +00:00
|
|
|
if (UNIV_UNLIKELY(src_zip->n_blobs)) {
|
2006-10-19 07:52:28 +00:00
|
|
|
ut_a(page_is_leaf(src));
|
2006-08-21 10:27:15 +00:00
|
|
|
ut_a(dict_index_is_clust(index));
|
|
|
|
}
|
2006-05-11 18:23:10 +00:00
|
|
|
|
branches/zip: Write PAGE_MAX_TRX_ID to the redo log. Otherwise,
transactions that are started before the rollback of incomplete
transactions has finished may have an inconsistent view of the
secondary indexes.
dict_index_is_sec_or_ibuf(): Auxiliary function for controlling
updates and checks of PAGE_MAX_TRX_ID: check whether an index is a
secondary index or the insert buffer tree.
page_set_max_trx_id(), page_update_max_trx_id(),
lock_rec_insert_check_and_lock(),
lock_sec_rec_modify_check_and_lock(), btr_cur_ins_lock_and_undo(),
btr_cur_upd_lock_and_undo(): Add the parameter mtr.
page_set_max_trx_id(): Allow mtr to be NULL. When mtr==NULL, do not
attempt to write to the redo log. This only occurs when creating a
page or reorganizing a compressed page. In these cases, the
PAGE_MAX_TRX_ID will be set correctly during the application of redo
log records, even though there is no explicit log record about it.
btr_discard_only_page_on_level(): Preserve PAGE_MAX_TRX_ID. This
function should be unreachable, though.
btr_cur_pessimistic_update(): Update PAGE_MAX_TRX_ID.
Add some assertions for checking that PAGE_MAX_TRX_ID is set on all
secondary index leaf pages.
rb://115 tested by Michael, fixes Issue #211
2009-05-19 18:59:07 +00:00
|
|
|
/* The PAGE_MAX_TRX_ID must be set on leaf pages of secondary
|
|
|
|
indexes. It does not matter on other pages. */
|
|
|
|
ut_a(dict_index_is_clust(index) || !page_is_leaf(src)
|
|
|
|
|| !ut_dulint_is_zero(page_get_max_trx_id(src)));
|
|
|
|
|
branches/zip: Add some more Valgrind instrumentation.
page_zip_write_rec(), page_zip_write_blob_ptr(), page_zip_write_node_ptr(),
page_zip_write_trx_id_and_roll_ptr(), page_zip_clear_rec(),
page_zip_rec_set_deleted(), page_zip_rec_set_owned(), page_zip_dir_insert(),
page_zip_dir_delete(), page_zip_dir_add_slot(), page_zip_reorganize(),
page_zip_copy(), page_zip_get_trailer_len(), page_zip_write_header():
Assert that the complete contents of the compressed page is defined.
2007-10-31 13:19:38 +00:00
|
|
|
UNIV_MEM_ASSERT_W(page, UNIV_PAGE_SIZE);
|
|
|
|
UNIV_MEM_ASSERT_W(page_zip->data, page_zip_get_size(page_zip));
|
|
|
|
UNIV_MEM_ASSERT_RW(src, UNIV_PAGE_SIZE);
|
|
|
|
UNIV_MEM_ASSERT_RW(src_zip->data, page_zip_get_size(page_zip));
|
|
|
|
|
2008-09-25 06:29:08 +00:00
|
|
|
/* Copy those B-tree page header fields that are related to
|
2008-10-15 06:32:40 +00:00
|
|
|
the records stored in the page. Also copy the field
|
2008-09-25 06:29:08 +00:00
|
|
|
PAGE_MAX_TRX_ID. Skip the rest of the page header and
|
|
|
|
trailer. On the compressed page, there is no trailer. */
|
|
|
|
#if PAGE_MAX_TRX_ID + 8 != PAGE_HEADER_PRIV_END
|
|
|
|
# error "PAGE_MAX_TRX_ID + 8 != PAGE_HEADER_PRIV_END"
|
|
|
|
#endif
|
2008-09-25 06:15:36 +00:00
|
|
|
memcpy(PAGE_HEADER + page, PAGE_HEADER + src,
|
2008-10-15 06:32:40 +00:00
|
|
|
PAGE_HEADER_PRIV_END);
|
2008-09-25 06:15:36 +00:00
|
|
|
memcpy(PAGE_DATA + page, PAGE_DATA + src,
|
|
|
|
UNIV_PAGE_SIZE - PAGE_DATA - FIL_PAGE_DATA_END);
|
|
|
|
memcpy(PAGE_HEADER + page_zip->data, PAGE_HEADER + src_zip->data,
|
2008-10-15 06:32:40 +00:00
|
|
|
PAGE_HEADER_PRIV_END);
|
2008-09-25 06:15:36 +00:00
|
|
|
memcpy(PAGE_DATA + page_zip->data, PAGE_DATA + src_zip->data,
|
|
|
|
page_zip_get_size(page_zip) - PAGE_DATA);
|
2006-05-11 18:23:10 +00:00
|
|
|
|
2008-09-25 06:15:36 +00:00
|
|
|
/* Copy all fields of src_zip to page_zip, except the pointer
|
|
|
|
to the compressed data page. */
|
2006-11-30 14:09:29 +00:00
|
|
|
{
|
|
|
|
page_zip_t* data = page_zip->data;
|
|
|
|
memcpy(page_zip, src_zip, sizeof *page_zip);
|
|
|
|
page_zip->data = data;
|
|
|
|
}
|
2007-02-19 14:51:44 +00:00
|
|
|
ut_ad(page_zip_get_trailer_len(page_zip,
|
|
|
|
dict_index_is_clust(index), NULL)
|
2006-11-27 13:44:32 +00:00
|
|
|
+ page_zip->m_end < page_zip_get_size(page_zip));
|
2006-05-12 09:35:56 +00:00
|
|
|
|
2006-05-15 11:43:35 +00:00
|
|
|
if (!page_is_leaf(src)
|
2006-09-26 07:39:02 +00:00
|
|
|
&& UNIV_UNLIKELY(mach_read_from_4(src + FIL_PAGE_PREV) == FIL_NULL)
|
2006-08-29 09:30:31 +00:00
|
|
|
&& UNIV_LIKELY(mach_read_from_4(page
|
|
|
|
+ FIL_PAGE_PREV) != FIL_NULL)) {
|
2006-05-15 11:43:35 +00:00
|
|
|
/* Clear the REC_INFO_MIN_REC_FLAG of the first user record. */
|
2006-09-19 10:14:07 +00:00
|
|
|
ulint offs = rec_get_next_offs(page + PAGE_NEW_INFIMUM,
|
|
|
|
TRUE);
|
2006-05-15 11:43:35 +00:00
|
|
|
if (UNIV_LIKELY(offs != PAGE_NEW_SUPREMUM)) {
|
|
|
|
rec_t* rec = page + offs;
|
|
|
|
ut_a(rec[-REC_N_NEW_EXTRA_BYTES]
|
2006-08-29 09:30:31 +00:00
|
|
|
& REC_INFO_MIN_REC_FLAG);
|
2006-05-15 11:43:35 +00:00
|
|
|
rec[-REC_N_NEW_EXTRA_BYTES] &= ~ REC_INFO_MIN_REC_FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-05-12 09:35:56 +00:00
|
|
|
ut_a(page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-05-12 09:35:56 +00:00
|
|
|
|
2006-05-16 07:58:10 +00:00
|
|
|
page_zip_compress_write_log(page_zip, page, index, mtr);
|
2006-05-11 18:23:10 +00:00
|
|
|
}
|
2009-03-23 14:21:34 +00:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2006-05-11 18:23:10 +00:00
|
|
|
|
2006-04-11 12:27:06 +00:00
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Parses a log record of compressing an index page.
|
|
|
|
@return end of log record or NULL */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-04-11 12:27:06 +00:00
|
|
|
byte*
|
|
|
|
page_zip_parse_compress(
|
|
|
|
/*====================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
byte* ptr, /*!< in: buffer */
|
|
|
|
byte* end_ptr,/*!< in: buffer end */
|
|
|
|
page_t* page, /*!< out: uncompressed page */
|
|
|
|
page_zip_des_t* page_zip)/*!< out: compressed page */
|
2006-04-11 12:27:06 +00:00
|
|
|
{
|
|
|
|
ulint size;
|
2006-05-16 07:58:10 +00:00
|
|
|
ulint trailer_size;
|
2006-04-11 12:27:06 +00:00
|
|
|
|
|
|
|
ut_ad(ptr && end_ptr);
|
2006-05-16 07:58:10 +00:00
|
|
|
ut_ad(!page == !page_zip);
|
2006-04-11 12:27:06 +00:00
|
|
|
|
2006-05-16 07:58:10 +00:00
|
|
|
if (UNIV_UNLIKELY(ptr + (2 + 2) > end_ptr)) {
|
2006-04-11 12:27:06 +00:00
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
size = mach_read_from_2(ptr);
|
|
|
|
ptr += 2;
|
2006-05-16 07:58:10 +00:00
|
|
|
trailer_size = mach_read_from_2(ptr);
|
|
|
|
ptr += 2;
|
2006-04-11 12:27:06 +00:00
|
|
|
|
2006-05-16 07:58:10 +00:00
|
|
|
if (UNIV_UNLIKELY(ptr + 8 + size + trailer_size > end_ptr)) {
|
2006-04-11 12:27:06 +00:00
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page) {
|
|
|
|
if (UNIV_UNLIKELY(!page_zip)
|
2006-11-27 13:44:32 +00:00
|
|
|
|| UNIV_UNLIKELY(page_zip_get_size(page_zip) < size)) {
|
2006-04-11 12:27:06 +00:00
|
|
|
corrupt:
|
|
|
|
recv_sys->found_corrupt_log = TRUE;
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2006-05-16 07:58:10 +00:00
|
|
|
memcpy(page_zip->data + FIL_PAGE_PREV, ptr, 4);
|
|
|
|
memcpy(page_zip->data + FIL_PAGE_NEXT, ptr + 4, 4);
|
|
|
|
memcpy(page_zip->data + FIL_PAGE_TYPE, ptr + 8, size);
|
|
|
|
memset(page_zip->data + FIL_PAGE_TYPE + size, 0,
|
2006-11-27 13:44:32 +00:00
|
|
|
page_zip_get_size(page_zip) - trailer_size
|
2006-08-29 09:30:31 +00:00
|
|
|
- (FIL_PAGE_TYPE + size));
|
2006-11-27 13:44:32 +00:00
|
|
|
memcpy(page_zip->data + page_zip_get_size(page_zip)
|
|
|
|
- trailer_size, ptr + 8 + size, trailer_size);
|
2006-05-16 07:58:10 +00:00
|
|
|
|
2006-04-11 12:27:06 +00:00
|
|
|
if (UNIV_UNLIKELY(!page_zip_decompress(page_zip, page))) {
|
|
|
|
|
|
|
|
goto corrupt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-16 07:58:10 +00:00
|
|
|
return(ptr + 8 + size + trailer_size);
|
2006-04-11 12:27:06 +00:00
|
|
|
}
|
2006-05-02 11:44:39 +00:00
|
|
|
|
|
|
|
/**************************************************************************
|
2009-05-25 05:30:14 +00:00
|
|
|
Calculate the compressed page checksum.
|
|
|
|
@return page checksum */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-05-02 11:44:39 +00:00
|
|
|
ulint
|
|
|
|
page_zip_calc_checksum(
|
|
|
|
/*===================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const void* data, /*!< in: compressed page */
|
|
|
|
ulint size) /*!< in: size of compressed page */
|
2006-05-02 11:44:39 +00:00
|
|
|
{
|
2007-01-16 21:51:40 +00:00
|
|
|
/* Exclude FIL_PAGE_SPACE_OR_CHKSUM, FIL_PAGE_LSN,
|
|
|
|
and FIL_PAGE_FILE_FLUSH_LSN from the checksum. */
|
|
|
|
|
|
|
|
const Bytef* s = data;
|
|
|
|
uLong adler;
|
|
|
|
|
|
|
|
ut_ad(size > FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
|
|
|
|
|
|
|
|
adler = adler32(0L, s + FIL_PAGE_OFFSET,
|
|
|
|
FIL_PAGE_LSN - FIL_PAGE_OFFSET);
|
|
|
|
adler = adler32(adler, s + FIL_PAGE_TYPE, 2);
|
|
|
|
adler = adler32(adler, s + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID,
|
|
|
|
size - FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
|
|
|
|
|
|
|
|
return((ulint) adler);
|
2006-05-02 11:44:39 +00:00
|
|
|
}
|