Commit 91a81997 authored by unknown's avatar unknown

Postmerge fix (including changing type of LSN)

Some debug info and comments added


include/pagecache.h:
  postmerge fix
mysys/mf_pagecache.c:
  Postmerge fix (including changing type of LSN)
  Additional DBUG_ASSERTs added
  Comment about pinning mechanism added
storage/maria/ma_control_file.c:
  Used the same LSN storing procedure everywhere
  Postmerge fix (including changing type of LSN)
storage/maria/ma_control_file.h:
  Postmerge fix (including changing type of LSN)
storage/maria/ma_loghandler.c:
  Postmerge fix (including changing type of LSN)
storage/maria/ma_loghandler.h:
  Postmerge fix (including changing type of LSN)
storage/maria/ma_loghandler_lsn.h:
  Postmerge fix (including changing type of LSN)
storage/maria/unittest/Makefile.am:
  Postmerge fix
storage/maria/unittest/ma_control_file-t.c:
  Postmerge fix (including changing type of LSN)
storage/maria/unittest/ma_test_loghandler-t.c:
  Postmerge fix (including changing type of LSN)
storage/maria/unittest/ma_test_loghandler_multigroup-t.c:
  Postmerge fix (including changing type of LSN)
storage/maria/unittest/ma_test_loghandler_multithread-t.c:
  Postmerge fix (including changing type of LSN)
storage/maria/unittest/ma_test_loghandler_pagecache-t.c:
  Postmerge fix (including changing type of LSN)
storage/maria/unittest/mf_pagecache_consist.c:
  Postmerge fix (including changing type of LSN)
storage/maria/unittest/mf_pagecache_single.c:
  Postmerge fix (including changing type of LSN)
parent 199ea756
......@@ -21,6 +21,7 @@
C_MODE_START
#include "../storage/maria/ma_loghandler_lsn.h"
#include <m_string.h>
/* Type of the page */
enum pagecache_page_type
......@@ -73,8 +74,6 @@ enum pagecache_write_mode
typedef void *PAGECACHE_PAGE_LINK;
typedef uint64 LSN;
/* file descriptor for Maria */
typedef struct st_pagecache_file
{
......@@ -152,8 +151,8 @@ typedef struct st_pagecache
ulong param_division_limit; /* min. percentage of warm blocks */
ulong param_age_threshold; /* determines when hot block is downgraded */
/* Statistics variables. These are reset in reset_key_cache_counters(). */
ulong global_blocks_changed; /* number of currently dirty blocks */
/* Statistics variables. These are reset in reset_pagecache_counters(). */
ulong global_blocks_changed; /* number of currently dirty blocks */
ulonglong global_cache_w_requests;/* number of write requests (write hits) */
ulonglong global_cache_write; /* number of writes from cache to files */
ulonglong global_cache_r_requests;/* number of read requests (read hits) */
......@@ -200,14 +199,12 @@ extern void pagecache_unlock_page(PAGECACHE *pagecache,
pgcache_page_no_t pageno,
enum pagecache_page_lock lock,
enum pagecache_page_pin pin,
my_bool stamp_this_page,
LSN_PTR first_REDO_LSN_for_page);
LSN first_REDO_LSN_for_page);
extern void pagecache_unlock(PAGECACHE *pagecache,
PAGECACHE_PAGE_LINK *link,
enum pagecache_page_lock lock,
enum pagecache_page_pin pin,
my_bool stamp_this_page,
LSN_PTR first_REDO_LSN_for_page);
LSN first_REDO_LSN_for_page);
extern void pagecache_unpin_page(PAGECACHE *pagecache,
PAGECACHE_FILE *file,
pgcache_page_no_t pageno);
......@@ -225,6 +222,7 @@ extern void end_pagecache(PAGECACHE *keycache, my_bool cleanup);
extern my_bool pagecache_collect_changed_blocks_with_lsn(PAGECACHE *pagecache,
LEX_STRING *str,
LSN *max_lsn);
extern int reset_pagecache_counters(const char *name, PAGECACHE *pagecache);
C_MODE_END
#endif /* _keycache_h */
......@@ -538,7 +538,7 @@ static int ___pagecache_pthread_cond_signal(pthread_cond_t *cond);
#define pagecache_pthread_cond_signal pthread_cond_signal
#endif /* defined(PAGECACHE_DEBUG) */
extern my_bool translog_flush(LSN *lsn);
extern my_bool translog_flush(LSN lsn);
/*
Write page to the disk
......@@ -570,13 +570,13 @@ static uint pagecache_fwrite(PAGECACHE *pagecache,
DBUG_PRINT("info", ("Log handler call"));
/* TODO: integrate with page format */
#define PAGE_LSN_OFFSET 0
lsn7korr(&lsn, buffer + PAGE_LSN_OFFSET);
lsn= lsn7korr(buffer + PAGE_LSN_OFFSET);
/*
check CONTROL_FILE_IMPOSSIBLE_FILENO &
CONTROL_FILE_IMPOSSIBLE_LOG_OFFSET
*/
DBUG_ASSERT(lsn.file_no != 0 && lsn.rec_offset != 0);
translog_flush(&lsn);
DBUG_ASSERT(lsn != 0);
translog_flush(lsn);
}
DBUG_RETURN(my_pwrite(filedesc->file, buffer, pagecache->block_size,
(pageno)<<(pagecache->shift), flags));
......@@ -1354,6 +1354,7 @@ static void unreg_request(PAGECACHE *pagecache,
(ulong)block, BLOCK_NUMBER(pagecache, block),
block->status, block->requests));
BLOCK_INFO(block);
DBUG_ASSERT(block->requests > 0);
if (! --block->requests)
{
my_bool hot;
......@@ -1400,6 +1401,7 @@ static inline void remove_reader(PAGECACHE_BLOCK_LINK *block)
{
DBUG_ENTER("remove_reader");
BLOCK_INFO(block);
DBUG_ASSERT(block->hash_link->requests > 0);
#ifdef THREAD
if (! --block->hash_link->requests && block->condvar)
pagecache_pthread_cond_signal(block->condvar);
......@@ -1722,12 +1724,14 @@ static PAGECACHE_BLOCK_LINK *find_block(PAGECACHE *pagecache,
if (page_status != PAGE_READ)
{
/* We don't need the page in the cache: we are going to write on disk */
DBUG_ASSERT(hash_link->requests > 0);
hash_link->requests--;
unlink_hash(pagecache, hash_link);
return 0;
}
if (!(block->status & BLOCK_IN_FLUSH))
{
DBUG_ASSERT(hash_link->requests > 0);
hash_link->requests--;
/*
Remove block to invalidate the page in the block buffer
......@@ -1744,6 +1748,7 @@ static PAGECACHE_BLOCK_LINK *find_block(PAGECACHE *pagecache,
return 0;
}
/* Wait until the page is flushed on disk */
DBUG_ASSERT(hash_link->requests > 0);
hash_link->requests--;
{
#ifdef THREAD
......@@ -1795,6 +1800,7 @@ static PAGECACHE_BLOCK_LINK *find_block(PAGECACHE *pagecache,
}
else
{
DBUG_ASSERT(hash_link->requests > 0);
hash_link->requests--;
KEYCACHE_DBUG_PRINT("find_block",
("request waiting for old page to be saved"));
......@@ -1851,8 +1857,8 @@ static PAGECACHE_BLOCK_LINK *find_block(PAGECACHE *pagecache,
pagecache->blocks_used++;
}
pagecache->blocks_unused--;
DBUG_ASSERT((block->status & BLOCK_WRLOCK));
DBUG_ASSERT(block->pins > 0);
DBUG_ASSERT((block->status & BLOCK_WRLOCK) == 0);
DBUG_ASSERT(block->pins == 0);
block->status= 0;
#ifndef DBUG_OFF
block->type= PAGECACHE_EMPTY_PAGE;
......@@ -1911,18 +1917,19 @@ static PAGECACHE_BLOCK_LINK *find_block(PAGECACHE *pagecache,
block->hits_left= init_hits_left;
block->last_hit_time= 0;
if (reg_req)
reg_requests(pagecache, block,1);
reg_requests(pagecache, block, 1);
hash_link->block= block;
}
BLOCK_INFO(block);
DBUG_ASSERT((block->status & BLOCK_WRLOCK) == 0);
DBUG_ASSERT(block->pins > 0);
DBUG_ASSERT(block->pins == 0);
if (block->hash_link != hash_link &&
! (block->status & BLOCK_IN_SWITCH) )
{
/* this is a primary request for a new page */
DBUG_ASSERT((block->status & BLOCK_WRLOCK) == 0);
DBUG_ASSERT(block->pins > 0);
DBUG_ASSERT(block->pins == 0);
block->status|= (BLOCK_IN_SWITCH | BLOCK_WRLOCK);
KEYCACHE_DBUG_PRINT("find_block",
......@@ -2289,9 +2296,9 @@ static my_bool make_lock_and_pin(PAGECACHE *pagecache,
retry:
DBUG_PRINT("INFO", ("Retry block 0x%lx", (ulong)block));
BLOCK_INFO(block);
DBUG_ASSERT(block->hash_link->requests != 0);
DBUG_ASSERT(block->hash_link->requests > 0);
block->hash_link->requests--;
DBUG_ASSERT(block->requests != 0);
DBUG_ASSERT(block->requests > 0);
unreg_request(pagecache, block, 1);
BLOCK_INFO(block);
DBUG_RETURN(1);
......@@ -2412,8 +2419,19 @@ static void read_block(PAGECACHE *pagecache,
pageno number of the block of data in the file
lock lock change
pin pin page
stamp_this_page put LSN stamp on the page
first_REDO_LSN_for_page
first_REDO_LSN_for_page do not set it if it is zero
NOTE
Pininig uses requests registration mechanism it works following way:
| beginnig | ending |
| of func. | of func. |
----------------------------+-------------+---------------+
PAGECACHE_PIN_LEFT_PINNED | - | - |
PAGECACHE_PIN_LEFT_UNPINNED | reg request | unreg request |
PAGECACHE_PIN | reg request | - |
PAGECACHE_UNPIN | - | unreg request |
*/
void pagecache_unlock_page(PAGECACHE *pagecache,
......@@ -2421,8 +2439,7 @@ void pagecache_unlock_page(PAGECACHE *pagecache,
pgcache_page_no_t pageno,
enum pagecache_page_lock lock,
enum pagecache_page_pin pin,
my_bool stamp_this_page,
LSN_PTR first_REDO_LSN_for_page)
LSN first_REDO_LSN_for_page)
{
PAGECACHE_BLOCK_LINK *block;
int page_st;
......@@ -2444,15 +2461,15 @@ void pagecache_unlock_page(PAGECACHE *pagecache,
DBUG_ASSERT(pagecache->can_be_used);
inc_counter_for_resize_op(pagecache);
block= find_block(pagecache, file, pageno, 0, 0, 0, &page_st);
/* See NOTE for pagecache_unlock_page about registering requests */
block= find_block(pagecache, file, pageno, 0, 0,
test(pin == PAGECACHE_PIN_LEFT_UNPINNED), &page_st);
BLOCK_INFO(block);
DBUG_ASSERT(block != 0 && page_st == PAGE_READ);
if (stamp_this_page)
if (first_REDO_LSN_for_page)
{
DBUG_ASSERT(lock == PAGECACHE_LOCK_WRITE_UNLOCK &&
pin == PAGECACHE_UNPIN);
/* TODO: insert LSN writing code */
DBUG_ASSERT(first_REDO_LSN_for_page != 0);
set_if_bigger(block->rec_lsn, first_REDO_LSN_for_page);
}
......@@ -2472,7 +2489,8 @@ void pagecache_unlock_page(PAGECACHE *pagecache,
remove_reader(block);
/*
Link the block into the LRU chain if it's the last submitted request
for the block and block will not be pinned
for the block and block will not be pinned.
See NOTE for pagecache_unlock_page about registering requests.
*/
if (pin != PAGECACHE_PIN_LEFT_PINNED)
unreg_request(pagecache, block, 1);
......@@ -2504,7 +2522,6 @@ void pagecache_unpin_page(PAGECACHE *pagecache,
DBUG_ENTER("pagecache_unpin_page");
DBUG_PRINT("enter", ("fd: %u page: %lu",
(uint) file->file, (ulong) pageno));
pagecache_pthread_mutex_lock(&pagecache->cache_lock);
/*
As soon as we keep lock cache can be used, and we have lock bacause want
......@@ -2513,6 +2530,7 @@ void pagecache_unpin_page(PAGECACHE *pagecache,
DBUG_ASSERT(pagecache->can_be_used);
inc_counter_for_resize_op(pagecache);
/* See NOTE for pagecache_unlock_page about registering requests */
block= find_block(pagecache, file, pageno, 0, 0, 0, &page_st);
DBUG_ASSERT(block != 0 && page_st == PAGE_READ);
......@@ -2539,7 +2557,8 @@ void pagecache_unpin_page(PAGECACHE *pagecache,
remove_reader(block);
/*
Link the block into the LRU chain if it's the last submitted request
for the block and block will not be pinned
for the block and block will not be pinned.
See NOTE for pagecache_unlock_page about registering requests
*/
unreg_request(pagecache, block, 1);
......@@ -2561,16 +2580,14 @@ void pagecache_unpin_page(PAGECACHE *pagecache,
link direct link to page (returned by read or write)
lock lock change
pin pin page
stamp_this_page put LSN stamp on the page
first_REDO_LSN_for_page
first_REDO_LSN_for_page do not set it if it is zero
*/
void pagecache_unlock(PAGECACHE *pagecache,
PAGECACHE_PAGE_LINK *link,
enum pagecache_page_lock lock,
enum pagecache_page_pin pin,
my_bool stamp_this_page,
LSN_PTR first_REDO_LSN_for_page)
LSN first_REDO_LSN_for_page)
{
PAGECACHE_BLOCK_LINK *block= (PAGECACHE_BLOCK_LINK *)link;
DBUG_ENTER("pagecache_unlock");
......@@ -2580,8 +2597,12 @@ void pagecache_unlock(PAGECACHE *pagecache,
(ulong) block->hash_link->pageno,
page_cache_page_lock_str[lock],
page_cache_page_pin_str[pin]));
/* we do not allow any lock/pin increasing here */
/*
We do not allow any lock/pin increasing here and page can't be
unpinned because we use direct link.
*/
DBUG_ASSERT(pin != PAGECACHE_PIN &&
pin != PAGECACHE_PIN_LEFT_UNPINNED &&
lock != PAGECACHE_LOCK_READ &&
lock != PAGECACHE_LOCK_WRITE);
if (pin == PAGECACHE_PIN_LEFT_UNPINNED &&
......@@ -2611,12 +2632,10 @@ void pagecache_unlock(PAGECACHE *pagecache,
DBUG_ASSERT(pagecache->can_be_used);
inc_counter_for_resize_op(pagecache);
if (stamp_this_page)
if (first_REDO_LSN_for_page)
{
DBUG_ASSERT(lock == PAGECACHE_LOCK_WRITE_UNLOCK &&
pin == PAGECACHE_UNPIN);
/* TODO: insert LSN writing code */
DBUG_ASSERT(first_REDO_LSN_for_page != 0);
set_if_bigger(block->rec_lsn, first_REDO_LSN_for_page);
}
......@@ -2636,7 +2655,8 @@ void pagecache_unlock(PAGECACHE *pagecache,
remove_reader(block);
/*
Link the block into the LRU chain if it's the last submitted request
for the block and block will not be pinned
for the block and block will not be pinned.
See NOTE for pagecache_unlock_page about registering requests.
*/
if (pin != PAGECACHE_PIN_LEFT_PINNED)
unreg_request(pagecache, block, 1);
......@@ -2701,7 +2721,8 @@ void pagecache_unpin(PAGECACHE *pagecache,
remove_reader(block);
/*
Link the block into the LRU chain if it's the last submitted request
for the block and block will not be pinned
for the block and block will not be pinned.
See NOTE for pagecache_unlock_page about registering requests.
*/
unreg_request(pagecache, block, 1);
......@@ -2790,10 +2811,11 @@ byte *pagecache_valid_read(PAGECACHE *pagecache,
inc_counter_for_resize_op(pagecache);
pagecache->global_cache_r_requests++;
/* See NOTE for pagecache_unlock_page about registering requests. */
block= find_block(pagecache, file, pageno, level,
test(lock == PAGECACHE_LOCK_WRITE),
test((pin == PAGECACHE_PIN_LEFT_PINNED) ||
(pin == PAGECACHE_UNPIN)),
test((pin == PAGECACHE_PIN_LEFT_UNPINNED) ||
(pin == PAGECACHE_PIN)),
&page_st);
DBUG_ASSERT(block->type == PAGECACHE_EMPTY_PAGE ||
block->type == type);
......@@ -2836,9 +2858,10 @@ byte *pagecache_valid_read(PAGECACHE *pagecache,
remove_reader(block);
/*
Link the block into the LRU chain if it's the last submitted request
for the block and block will not be pinned
for the block and block will not be pinned.
See NOTE for pagecache_unlock_page about registering requests.
*/
if (pin != PAGECACHE_PIN_LEFT_PINNED && pin != PAGECACHE_PIN)
if (pin == PAGECACHE_PIN_LEFT_UNPINNED || pin == PAGECACHE_UNPIN)
unreg_request(pagecache, block, 1);
else
*link= (PAGECACHE_PAGE_LINK)block;
......@@ -2898,6 +2921,8 @@ my_bool pagecache_delete_page(PAGECACHE *pagecache,
page_cache_page_pin_str[pin]));
DBUG_ASSERT(lock == PAGECACHE_LOCK_WRITE ||
lock == PAGECACHE_LOCK_LEFT_WRITELOCKED);
DBUG_ASSERT(pin == PAGECACHE_PIN ||
pin == PAGECACHE_PIN_LEFT_PINNED);
restart:
......@@ -2920,6 +2945,9 @@ my_bool pagecache_delete_page(PAGECACHE *pagecache,
DBUG_RETURN(0);
}
block= link->block;
/* See NOTE for pagecache_unlock_page about registering requests. */
if (pin == PAGECACHE_PIN)
reg_requests(pagecache, block, 1);
DBUG_ASSERT(block != 0);
if (make_lock_and_pin(pagecache, block, lock, pin))
{
......@@ -2972,9 +3000,9 @@ my_bool pagecache_delete_page(PAGECACHE *pagecache,
make_lock_and_pin(pagecache, block,
PAGECACHE_LOCK_WRITE_UNLOCK,
PAGECACHE_UNPIN);
DBUG_ASSERT(link->requests > 0);
link->requests--;
if (pin == PAGECACHE_PIN_LEFT_PINNED)
unreg_request(pagecache, block, 1);
/* See NOTE for pagecache_unlock_page about registering requests. */
free_block(pagecache, block);
err:
......@@ -3119,16 +3147,15 @@ my_bool pagecache_write(PAGECACHE *pagecache,
inc_counter_for_resize_op(pagecache);
pagecache->global_cache_w_requests++;
{
int need_wrlock= (write_mode != PAGECACHE_WRITE_DONE &&
lock != PAGECACHE_LOCK_LEFT_WRITELOCKED &&
lock != PAGECACHE_LOCK_WRITE_UNLOCK &&
lock != PAGECACHE_LOCK_WRITE_TO_READ);
block= find_block(pagecache, file, pageno, level,
(need_wrlock ? 1 : 0),
(need_wrlock ? 1 : 0),
&page_st);
}
/* See NOTE for pagecache_unlock_page about registering requests. */
block= find_block(pagecache, file, pageno, level,
test(write_mode != PAGECACHE_WRITE_DONE &&
lock != PAGECACHE_LOCK_LEFT_WRITELOCKED &&
lock != PAGECACHE_LOCK_WRITE_UNLOCK &&
lock != PAGECACHE_LOCK_WRITE_TO_READ),
test((pin == PAGECACHE_PIN_LEFT_UNPINNED) ||
(pin == PAGECACHE_PIN)),
&page_st);
if (!block)
{
DBUG_ASSERT(write_mode != PAGECACHE_WRITE_DONE);
......@@ -3212,12 +3239,11 @@ my_bool pagecache_write(PAGECACHE *pagecache,
}
/* Unregister the request */
DBUG_ASSERT(block->hash_link->requests > 0);
block->hash_link->requests--;
if (pin != PAGECACHE_PIN_LEFT_PINNED && pin != PAGECACHE_PIN)
{
/* See NOTE for pagecache_unlock_page about registering requests. */
if (pin == PAGECACHE_PIN_LEFT_UNPINNED || pin == PAGECACHE_UNPIN)
unreg_request(pagecache, block, 1);
}
else
*link= (PAGECACHE_PAGE_LINK)block;
......@@ -3280,7 +3306,7 @@ static void free_block(PAGECACHE *pagecache, PAGECACHE_BLOCK_LINK *block)
unlink_changed(block);
DBUG_ASSERT((block->status & BLOCK_WRLOCK) == 0);
DBUG_ASSERT(block->pins > 0);
DBUG_ASSERT(block->pins == 0);
block->status= 0;
#ifndef DBUG_OFF
block->type= PAGECACHE_EMPTY_PAGE;
......@@ -3361,7 +3387,7 @@ static int flush_cached_blocks(PAGECACHE *pagecache,
}
/* if the block is not pinned then it is not write locked */
DBUG_ASSERT((block->status & BLOCK_WRLOCK) == 0);
DBUG_ASSERT(block->pins > 0);
DBUG_ASSERT(block->pins == 0);
#ifndef DBUG_OFF
{
int rc=
......@@ -3686,33 +3712,33 @@ int flush_pagecache_blocks(PAGECACHE *pagecache,
Reset the counters of a key cache.
SYNOPSIS
reset_key_cache_counters()
reset_pagecache_counters()
name the name of a key cache
key_cache pointer to the key kache to be reset
pagecache pointer to the pagecache to be reset
DESCRIPTION
This procedure is used by process_key_caches() to reset the counters of all
currently used key caches, both the default one and the named ones.
This procedure is used to reset the counters of all currently used key
caches, both the default one and the named ones.
RETURN
0 on success (always because it can't fail)
*/
static int reset_key_cache_counters(const char *name, PAGECACHE *key_cache)
int reset_pagecache_counters(const char *name, PAGECACHE *pagecache)
{
DBUG_ENTER("reset_key_cache_counters");
if (!key_cache->inited)
DBUG_ENTER("reset_pagecache_counters");
if (!pagecache->inited)
{
DBUG_PRINT("info", ("Key cache %s not initialized.", name));
DBUG_RETURN(0);
}
DBUG_PRINT("info", ("Resetting counters for key cache %s.", name));
key_cache->global_blocks_changed= 0; /* Key_blocks_not_flushed */
key_cache->global_cache_r_requests= 0; /* Key_read_requests */
key_cache->global_cache_read= 0; /* Key_reads */
key_cache->global_cache_w_requests= 0; /* Key_write_requests */
key_cache->global_cache_write= 0; /* Key_writes */
pagecache->global_blocks_changed= 0; /* Key_blocks_not_flushed */
pagecache->global_cache_r_requests= 0; /* Key_read_requests */
pagecache->global_cache_read= 0; /* Key_reads */
pagecache->global_cache_w_requests= 0; /* Key_write_requests */
pagecache->global_cache_write= 0; /* Key_writes */
DBUG_RETURN(0);
}
......
......@@ -37,7 +37,7 @@
#define CONTROL_FILE_CHECKSUM_OFFSET (CONTROL_FILE_MAGIC_STRING_OFFSET + CONTROL_FILE_MAGIC_STRING_SIZE)
#define CONTROL_FILE_CHECKSUM_SIZE 1
#define CONTROL_FILE_LSN_OFFSET (CONTROL_FILE_CHECKSUM_OFFSET + CONTROL_FILE_CHECKSUM_SIZE)
#define CONTROL_FILE_LSN_SIZE (4+4)
#define CONTROL_FILE_LSN_SIZE (3+4)
#define CONTROL_FILE_FILENO_OFFSET (CONTROL_FILE_LSN_OFFSET + CONTROL_FILE_LSN_SIZE)
#define CONTROL_FILE_FILENO_SIZE 4
#define CONTROL_FILE_SIZE (CONTROL_FILE_FILENO_OFFSET + CONTROL_FILE_FILENO_SIZE)
......@@ -59,20 +59,6 @@ uint32 last_logno;
*/
static int control_file_fd= -1;
static void lsn8store(char *buffer, const LSN *lsn)
{
int4store(buffer, lsn->file_no);
int4store(buffer + CONTROL_FILE_FILENO_SIZE, lsn->rec_offset);
}
static LSN lsn8korr(char *buffer)
{
LSN tmp;
tmp.file_no= uint4korr(buffer);
tmp.rec_offset= uint4korr(buffer + CONTROL_FILE_FILENO_SIZE);
return tmp;
}
static char simple_checksum(char *buffer, uint size)
{
/* TODO: improve this sum if we want */
......@@ -120,7 +106,7 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open()
"*store" and "*korr" calls in this file, and can even create backward
compatibility problems. Beware!
*/
DBUG_ASSERT(CONTROL_FILE_LSN_SIZE == (4+4));
DBUG_ASSERT(CONTROL_FILE_LSN_SIZE == (3+4));
DBUG_ASSERT(CONTROL_FILE_FILENO_SIZE == 4);
if (control_file_fd >= 0) /* already open */
......@@ -154,11 +140,9 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open()
usable as soon as it has been written to the log).
*/
LSN imposs_lsn= CONTROL_FILE_IMPOSSIBLE_LSN;
uint32 imposs_logno= CONTROL_FILE_IMPOSSIBLE_FILENO;
/* init the file with these "undefined" values */
DBUG_RETURN(ma_control_file_write_and_force(&imposs_lsn, imposs_logno,
DBUG_RETURN(ma_control_file_write_and_force(CONTROL_FILE_IMPOSSIBLE_LSN,
CONTROL_FILE_IMPOSSIBLE_FILENO,
CONTROL_FILE_UPDATE_ALL));
}
......@@ -216,7 +200,7 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open()
error= CONTROL_FILE_BAD_CHECKSUM;
goto err;
}
last_checkpoint_lsn= lsn8korr(buffer + CONTROL_FILE_LSN_OFFSET);
last_checkpoint_lsn= lsn7korr(buffer + CONTROL_FILE_LSN_OFFSET);
last_logno= uint4korr(buffer + CONTROL_FILE_FILENO_OFFSET);
DBUG_RETURN(0);
......@@ -253,7 +237,7 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open()
1 - Error
*/
int ma_control_file_write_and_force(const LSN *checkpoint_lsn, uint32 logno,
int ma_control_file_write_and_force(const LSN checkpoint_lsn, uint32 logno,
uint objs_to_write)
{
char buffer[CONTROL_FILE_SIZE];
......@@ -277,9 +261,9 @@ int ma_control_file_write_and_force(const LSN *checkpoint_lsn, uint32 logno,
DBUG_ASSERT(0);
if (update_checkpoint_lsn)
lsn8store(buffer + CONTROL_FILE_LSN_OFFSET, checkpoint_lsn);
lsn7store(buffer + CONTROL_FILE_LSN_OFFSET, checkpoint_lsn);
else /* store old value == change nothing */
lsn8store(buffer + CONTROL_FILE_LSN_OFFSET, &last_checkpoint_lsn);
lsn7store(buffer + CONTROL_FILE_LSN_OFFSET, last_checkpoint_lsn);
if (update_logno)
int4store(buffer + CONTROL_FILE_FILENO_OFFSET, logno);
......@@ -297,7 +281,7 @@ int ma_control_file_write_and_force(const LSN *checkpoint_lsn, uint32 logno,
/* TODO: you need some protection to be able to write last_* global vars */
if (update_checkpoint_lsn)
last_checkpoint_lsn= *checkpoint_lsn;
last_checkpoint_lsn= checkpoint_lsn;
if (update_logno)
last_logno= logno;
......
......@@ -30,16 +30,14 @@
#define CONTROL_FILE_IMPOSSIBLE_FILENO 0
/* logs always have a header */
#define CONTROL_FILE_IMPOSSIBLE_LOG_OFFSET 0
/*
indicate absence of LSN.
*/
#define CONTROL_FILE_IMPOSSIBLE_LSN ((LSN){CONTROL_FILE_IMPOSSIBLE_FILENO,CONTROL_FILE_IMPOSSIBLE_LOG_OFFSET})
/* indicate absence of LSN. */
#define CONTROL_FILE_IMPOSSIBLE_LSN ((LSN)0)
/* Here is the interface of this module */
/*
LSN of the last checkoint
(if last_checkpoint_lsn.file_no == CONTROL_FILE_IMPOSSIBLE_FILENO
(if last_checkpoint_lsn == CONTROL_FILE_IMPOSSIBLE_LSN
then there was never a checkpoint)
*/
extern LSN last_checkpoint_lsn;
......@@ -72,7 +70,7 @@ CONTROL_FILE_ERROR ma_control_file_create_or_open();
#define CONTROL_FILE_UPDATE_ALL 0
#define CONTROL_FILE_UPDATE_ONLY_LSN 1
#define CONTROL_FILE_UPDATE_ONLY_LOGNO 2
int ma_control_file_write_and_force(const LSN *checkpoint_lsn, uint32 logno,
int ma_control_file_write_and_force(const LSN checkpoint_lsn, uint32 logno,
uint objs_to_write);
......
......@@ -366,7 +366,7 @@ const char *maria_data_root;
pointer to path
*/
char *translog_filename_by_fileno(uint32 file_no, char *path)
static char *translog_filename_by_fileno(uint32 file_no, char *path)
{
char file_name[10 + 8 + 1];
char *res;
......@@ -391,7 +391,7 @@ char *translog_filename_by_fileno(uint32 file_no, char *path)
file descriptor number
*/
File open_logfile_by_number_no_cache(uint32 file_no)
static File open_logfile_by_number_no_cache(uint32 file_no)
{
File file;
char path[FN_REFLEN];
......@@ -421,7 +421,7 @@ File open_logfile_by_number_no_cache(uint32 file_no)
1 ERROR
*/
my_bool translog_write_file_header()
static my_bool translog_write_file_header()
{
ulonglong timestamp;
char page[TRANSLOG_PAGE_SIZE];
......@@ -441,7 +441,8 @@ my_bool translog_write_file_header()
/* loghandler page size/512 */
int2store(page + (8 + 8 + 4 + 4 + 4), TRANSLOG_PAGE_SIZE / 512);
/* file number */
int3store(page + (8 + 8 + 4 + 4 + 4 + 2), log_descriptor.horizon.file_no);
int3store(page + (8 + 8 + 4 + 4 + 4 + 2),
LSN_FILE_NO(log_descriptor.horizon));
bzero(page + (8 + 8 + 4 + 4 + 4 + 2 + 3),
TRANSLOG_PAGE_SIZE - (8 + 8 + 4 + 4 + 4 + 2 + 3));
......@@ -466,12 +467,11 @@ my_bool translog_write_file_header()
1 - Error
*/
my_bool translog_buffer_init(struct st_translog_buffer *buffer)
static my_bool translog_buffer_init(struct st_translog_buffer *buffer)
{
DBUG_ENTER("translog_buffer_init");
/* This buffer offset */
buffer->last_lsn.file_no= buffer->offset.file_no= 0;
buffer->last_lsn.rec_offset= buffer->offset.rec_offset= 0;
buffer->last_lsn= CONTROL_FILE_IMPOSSIBLE_LSN;
/* This Buffer File */
buffer->file= 0;
buffer->overlay= 0;
......@@ -528,9 +528,10 @@ static my_bool translog_close_log_file(File file)
1 Error
*/
my_bool translog_create_new_file()
static my_bool translog_create_new_file()
{
int i;
uint32 file_no= LSN_FILE_NO(log_descriptor.horizon);
DBUG_ENTER("translog_create_new_file");
......@@ -544,11 +545,11 @@ my_bool translog_create_new_file()
}
if ((log_descriptor.log_file_num[0]=
open_logfile_by_number_no_cache(log_descriptor.horizon.file_no)) <= 0 ||
open_logfile_by_number_no_cache(file_no)) <= 0 ||
translog_write_file_header())
DBUG_RETURN(1);
if (ma_control_file_write_and_force(NULL, log_descriptor.horizon.file_no,
if (ma_control_file_write_and_force(CONTROL_FILE_IMPOSSIBLE_LSN, file_no,
CONTROL_FILE_UPDATE_ONLY_LOGNO))
DBUG_RETURN(1);
......@@ -657,31 +658,32 @@ static void translog_new_page_header(TRANSLOG_ADDRESS *horizon,
ptr= cursor->ptr;
/* Page number */
int3store(ptr, horizon->rec_offset / TRANSLOG_PAGE_SIZE);
ptr +=3;
int3store(ptr, LSN_OFFSET(*horizon) / TRANSLOG_PAGE_SIZE);
ptr+= 3;
/* File number */
int3store(ptr, horizon->file_no);
ptr +=3;
int3store(ptr, LSN_FILE_NO(*horizon));
ptr+= 3;
*(ptr ++)= (uchar) log_descriptor.flags;
if (log_descriptor.flags & TRANSLOG_PAGE_CRC)
{
#ifndef DBUG_OFF
DBUG_PRINT("info", ("write 0x11223344 CRC to (%lu,0x%lx)",
(ulong) horizon->file_no, (ulong) horizon->rec_offset));
(ulong) LSN_FILE_NO(*horizon),
(ulong) LSN_OFFSET(*horizon)));
int4store(ptr, 0x11223344);
#endif
ptr +=4; /* CRC will be put when page
will be finished */
/* CRC will be put when page will be finished */
ptr+= 4;
}
if (log_descriptor.flags & TRANSLOG_SECTOR_PROTECTION)
{
time_t tm;
int2store(ptr, time(&tm) & 0xFFFF);
ptr +=(TRANSLOG_PAGE_SIZE / 512) * 2;
ptr+= (TRANSLOG_PAGE_SIZE / 512) * 2;
}
{
uint len= (ptr -cursor->ptr);
horizon->rec_offset+= len;
*horizon+= len; /* it is increasing of offset part of the address */
cursor->current_page_size= len;
if (!cursor->chaser)
cursor->buffer->size+= len;
......@@ -819,10 +821,10 @@ static void translog_finish_page(TRANSLOG_ADDRESS *horizon,
"Page addr: (%lu,0x%lx), "
"size %lu (%lu), Pg: %u, left: %u",
(uint) cursor->buffer_no, (ulong) cursor->buffer,
(ulong) cursor->buffer->offset.file_no,
(ulong) cursor->buffer->offset.rec_offset,
(ulong) horizon->file_no,
(ulong) (horizon->rec_offset -
(ulong) LSN_FILE_NO(cursor->buffer->offset),
(ulong) LSN_OFFSET(cursor->buffer->offset),
(ulong) LSN_FILE_NO(*horizon),
(ulong) (LSN_OFFSET(*horizon) -
cursor->current_page_size),
(ulong) cursor->buffer->size,
(ulong) (cursor->ptr -cursor->buffer->buffer),
......@@ -830,9 +832,9 @@ static void translog_finish_page(TRANSLOG_ADDRESS *horizon,
DBUG_ASSERT(cursor->ptr !=NULL);
DBUG_ASSERT((cursor->ptr -cursor->buffer->buffer) %TRANSLOG_PAGE_SIZE ==
cursor->current_page_size % TRANSLOG_PAGE_SIZE);
DBUG_ASSERT(horizon->file_no == cursor->buffer->offset.file_no);
DBUG_ASSERT(cursor->buffer->offset.rec_offset +
(cursor->ptr -cursor->buffer->buffer) == horizon->rec_offset);
DBUG_ASSERT(LSN_FILE_NO(*horizon) == LSN_FILE_NO(cursor->buffer->offset));
DBUG_ASSERT(LSN_OFFSET(cursor->buffer->offset) +
(cursor->ptr -cursor->buffer->buffer) == LSN_OFFSET(*horizon));
if (cursor->protected)
{
DBUG_PRINT("info", ("Already protected and finished"));
......@@ -843,7 +845,7 @@ static void translog_finish_page(TRANSLOG_ADDRESS *horizon,
DBUG_PRINT("info", ("left %u", (uint) left));
bzero(cursor->ptr, left);
cursor->ptr +=left;
horizon->rec_offset+= left;
*horizon+= left; /* offset increasing */
if (!cursor->chaser)
cursor->buffer->size+= left;
cursor->current_page_size= 0;
......@@ -888,6 +890,7 @@ static void translog_finish_page(TRANSLOG_ADDRESS *horizon,
NOTE
This buffer should be locked
*/
static void translog_wait_for_writers(struct st_translog_buffer *buffer)
{
struct st_my_thread_var *thread;
......@@ -908,7 +911,8 @@ static void translog_wait_for_writers(struct st_translog_buffer *buffer)
DBUG_PRINT("info", ("wait for writers... , thread 0x%lx, "
"buffer #%u 0x%lx, locked by 0x%lx (0x%lx), "
"mutex: 0x%lx",
thread, (uint) buffer->buffer_no, (ulong) buffer,
(ulong) thread,
(uint) buffer->buffer_no, (ulong) buffer,
(ulong) buffer->locked_by, (ulong) thread,
(ulong) &buffer->mutex));
#ifndef DBUG_OFF
......@@ -920,7 +924,8 @@ static void translog_wait_for_writers(struct st_translog_buffer *buffer)
DBUG_PRINT("info", ("wait for writers done, thread 0x%lx, "
"buffer #%u 0x%lx, locked by 0x%lx (0x%lx), "
"mutex: 0x%lx",
thread, (uint) buffer->buffer_no, (ulong) buffer,
(ulong) thread,
(uint) buffer->buffer_no, (ulong) buffer,
(ulong) buffer->locked_by, (ulong) thread,
(ulong) &buffer->mutex));
#ifndef DBUG_OFF
......@@ -966,7 +971,8 @@ static void translog_wait_for_buffer_free(struct st_translog_buffer *buffer)
DBUG_PRINT("info", ("wait for writers... , thread 0x%lx, "
"buffer #%u 0x%lx, locked by 0x%lx (0x%lx), "
"mutex: 0x%lx",
thread, (uint) buffer->buffer_no, (ulong) buffer,
(ulong) thread,
(uint) buffer->buffer_no, (ulong) buffer,
(ulong) buffer->locked_by, (ulong) thread,
(ulong) &buffer->mutex));
#ifndef DBUG_OFF
......@@ -978,7 +984,8 @@ static void translog_wait_for_buffer_free(struct st_translog_buffer *buffer)
DBUG_PRINT("info", ("wait for writers done, thread 0x%lx, "
"buffer #%u 0x%lx, locked by 0x%lx (0x%lx), "
"mutex: 0x%lx",
thread, (uint) buffer->buffer_no, (ulong) buffer,
(ulong) thread,
(uint) buffer->buffer_no, (ulong) buffer,
(ulong) buffer->locked_by, (ulong) thread,
(ulong) &buffer->mutex));
#ifndef DBUG_OFF
......@@ -1027,6 +1034,7 @@ static void translog_cursor_init(struct st_buffer_cursor *cursor,
cursor It's cursor
buffer_no Number of buffer
*/
static void translog_start_buffer(struct st_translog_buffer *buffer,
struct st_buffer_cursor *cursor,
uint8 buffer_no)
......@@ -1036,11 +1044,10 @@ static void translog_start_buffer(struct st_translog_buffer *buffer,
("Assign buffer #%u (0x%lx) to file %u, offset 0x%lx(%lu)",
(uint) buffer->buffer_no, (ulong) buffer,
(uint) log_descriptor.log_file_num[0],
(ulong) log_descriptor.horizon.rec_offset,
(ulong) log_descriptor.horizon.rec_offset));
(ulong) LSN_OFFSET(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon)));
DBUG_ASSERT(buffer_no == buffer->buffer_no);
buffer->last_lsn.file_no= 0;
buffer->last_lsn.rec_offset= 0;
buffer->last_lsn= CONTROL_FILE_IMPOSSIBLE_LSN;
buffer->offset= log_descriptor.horizon;
buffer->file= log_descriptor.log_file_num[0];
buffer->overlay= 0;
......@@ -1086,9 +1093,9 @@ static my_bool translog_buffer_next(TRANSLOG_ADDRESS *horizon,
my_bool chasing= cursor->chaser;
DBUG_ENTER("translog_buffer_next");
DBUG_PRINT("info", ("horizon (%u,0x%lx), chasing: %d",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset, chasing));
DBUG_PRINT("info", ("horizon (%lu,0x%lx), chasing: %d",
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon), chasing));
DBUG_ASSERT(cmp_translog_addr(log_descriptor.horizon, *horizon) >= 0);
......@@ -1105,8 +1112,9 @@ static my_bool translog_buffer_next(TRANSLOG_ADDRESS *horizon,
#endif
if (new_file)
{
horizon->file_no++;
horizon->rec_offset= TRANSLOG_PAGE_SIZE; /* header page */
/* move the horizon to the next file and its header page */
*horizon+= LSN_ONE_FILE;
*horizon= LSN_REPLACE_OFFSET(*horizon, TRANSLOG_PAGE_SIZE);
if (!chasing && translog_create_new_file())
{
DBUG_RETURN(1);
......@@ -1278,7 +1286,7 @@ static translog_size_t translog_variable_record_1group_decode_len(uchar **src)
0 - Error
*/
uint16 translog_get_total_chunk_length(uchar *page, uint16 offset)
static uint16 translog_get_total_chunk_length(uchar *page, uint16 offset)
{
DBUG_ENTER("translog_get_total_chunk_length");
switch (page[offset] & TRANSLOG_CHUNK_TYPE) {
......@@ -1380,9 +1388,10 @@ static my_bool translog_buffer_flush(struct st_translog_buffer *buffer)
("Buffer #%u 0x%lx: locked by 0x%lx (0x%lx), "
"file: %u, offset (%lu,0x%lx), size %lu",
(uint) buffer->buffer_no, (ulong) buffer,
(ulong) buffer->locked_by, my_thread_var,
(ulong) buffer->locked_by, (ulong) my_thread_var,
(uint) buffer->file,
(ulong) buffer->offset.file_no, (ulong) buffer->offset.rec_offset,
(ulong) LSN_FILE_NO(buffer->offset),
(ulong) LSN_OFFSET(buffer->offset),
(ulong) buffer->size));
DBUG_ASSERT(buffer->locked_by == my_thread_var);
......@@ -1407,7 +1416,7 @@ static my_bool translog_buffer_flush(struct st_translog_buffer *buffer)
};
if (pagecache_write(log_descriptor.pagecache,
&file,
(buffer->offset.rec_offset + i) / TRANSLOG_PAGE_SIZE,
(LSN_OFFSET(buffer->offset) + i) / TRANSLOG_PAGE_SIZE,
3,
buffer->buffer + i,
PAGECACHE_PLAIN_PAGE,
......@@ -1416,20 +1425,20 @@ static my_bool translog_buffer_flush(struct st_translog_buffer *buffer)
{
UNRECOVERABLE_ERROR(("Cant't write page (%lu,0x%lx) to pagecacte",
(ulong) buffer->file,
(ulong) (buffer->offset.rec_offset + i)));
(ulong) (LSN_OFFSET(buffer->offset)+ i)));
}
}
if (my_pwrite(buffer->file, (char*) buffer->buffer,
buffer->size, buffer->offset.rec_offset,
buffer->size, LSN_OFFSET(buffer->offset),
MYF(MY_WME)) != buffer->size)
{
UNRECOVERABLE_ERROR(("Cant't buffer (%lu,0x%lx) size %lu to the disk (%d)",
(ulong) buffer->file,
(ulong) buffer->offset.rec_offset,
(ulong) LSN_OFFSET(buffer->offset),
(ulong) buffer->size, errno));
DBUG_RETURN(1);
}
if (buffer->last_lsn.rec_offset != 0) /* if buffer->last_lsn is set */
if (LSN_OFFSET(buffer->last_lsn) != 0) /* if buffer->last_lsn is set */
translog_set_sent_to_file(&buffer->last_lsn);
/* Free buffer */
buffer->file= 0;
......@@ -1530,20 +1539,20 @@ static my_bool translog_page_validator(byte *page_addr, gptr data)
uint8 flags;
uchar *page= (uchar*) page_addr;
DBUG_ENTER("translog_page_validator");
TRANSLOG_ADDRESS *addr= ((TRANSLOG_VALIDATOR_DATA*) data)->addr;
TRANSLOG_ADDRESS addr= *((TRANSLOG_VALIDATOR_DATA*) data)->addr;
((TRANSLOG_VALIDATOR_DATA*) data)->was_recovered= 0;
if (uint3korr(page) != addr->rec_offset / TRANSLOG_PAGE_SIZE ||
uint3korr(page + 3) != addr->file_no)
if (uint3korr(page) != LSN_OFFSET(addr) / TRANSLOG_PAGE_SIZE ||
uint3korr(page + 3) != LSN_FILE_NO(addr))
{
UNRECOVERABLE_ERROR(("Page (%lu,0x%lx): "
"page address written in the page is incorrect :"
"File %lu instead of %lu or page %lu instead of %lu",
(ulong) addr->file_no, (ulong) addr->rec_offset,
(ulong) uint3korr(page + 3), (ulong) addr->file_no,
(ulong) LSN_FILE_NO(addr), (ulong) LSN_OFFSET(addr),
(ulong) uint3korr(page + 3), (ulong) LSN_FILE_NO(addr),
(ulong) uint3korr(page),
(ulong) addr->rec_offset / TRANSLOG_PAGE_SIZE));
(ulong) LSN_OFFSET(addr) / TRANSLOG_PAGE_SIZE));
DBUG_RETURN(1);
}
flags= page[3 + 3];
......@@ -1552,7 +1561,7 @@ static my_bool translog_page_validator(byte *page_addr, gptr data)
{
UNRECOVERABLE_ERROR(("Page (%lu,0x%lx): "
"Garbage in the page flags field detected : %x",
(ulong) addr->file_no, (ulong) addr->rec_offset,
(ulong) LSN_FILE_NO(addr), (ulong) LSN_OFFSET(addr),
(uint) flags));
DBUG_RETURN(1);
}
......@@ -1565,7 +1574,7 @@ static my_bool translog_page_validator(byte *page_addr, gptr data)
{
UNRECOVERABLE_ERROR(("Page (%lu,0x%lx): "
"CRC mismatch: calculated: %lx on the page %lx",
(ulong) addr->file_no, (ulong) addr->rec_offset,
(ulong) LSN_FILE_NO(addr), (ulong) LSN_OFFSET(addr),
(ulong) crc, (ulong) uint4korr(page + 3 + 3 + 1)));
DBUG_RETURN(1);
}
......@@ -1584,8 +1593,8 @@ static my_bool translog_page_validator(byte *page_addr, gptr data)
*/
uint16 test= uint2korr(page + offset);
DBUG_PRINT("info", ("sector #%u offset %u current %lx "
"read 0x%lx stored 0x%x%x",
i / 2, offset, current,
"read 0x%x stored 0x%x%x",
i / 2, offset, (ulong) current,
(uint) uint2korr(page + offset), (uint) table[i],
(uint) table[i + 1]));
if (test < current)
......@@ -1614,8 +1623,8 @@ static my_bool translog_page_validator(byte *page_addr, gptr data)
current= test;
DBUG_PRINT("info", ("sector #%u offset %u current %lx "
"read 0x%lx stored 0x%x%x",
i / 2, offset, current,
"read 0x%x stored 0x%x%x",
i / 2, offset, (ulong) current,
(uint) uint2korr(page + offset), (uint) table[i],
(uint) table[i + 1]));
}
......@@ -1623,6 +1632,7 @@ static my_bool translog_page_validator(byte *page_addr, gptr data)
DBUG_RETURN(0);
}
/*
Get log page by file number and offset of the beginning of the page
......@@ -1637,19 +1647,21 @@ static my_bool translog_page_validator(byte *page_addr, gptr data)
NULL - Error
*/
uchar *translog_get_page(TRANSLOG_VALIDATOR_DATA *data, uchar *buffer)
static uchar *translog_get_page(TRANSLOG_VALIDATOR_DATA *data, uchar *buffer)
{
TRANSLOG_ADDRESS addr= *(data->addr);
uint cache_index;
uint32 file_no= LSN_FILE_NO(addr);
DBUG_ENTER("translog_get_page");
DBUG_PRINT("enter", ("File %lu, Offset %lu(0x%lx)",
(ulong) data->addr->file_no,
(ulong) data->addr->rec_offset,
(ulong) data->addr->rec_offset));
(ulong) file_no,
(ulong) LSN_OFFSET(addr),
(ulong) LSN_OFFSET(addr)));
/* it is really page address */
DBUG_ASSERT(data->addr->rec_offset % TRANSLOG_PAGE_SIZE == 0);
DBUG_ASSERT(LSN_OFFSET(addr) % TRANSLOG_PAGE_SIZE == 0);
if ((cache_index= log_descriptor.horizon.file_no - data->addr->file_no) <
if ((cache_index= LSN_FILE_NO(log_descriptor.horizon) - file_no) <
OPENED_FILES_NUM)
{
PAGECACHE_FILE file;
......@@ -1657,7 +1669,7 @@ uchar *translog_get_page(TRANSLOG_VALIDATOR_DATA *data, uchar *buffer)
if (log_descriptor.log_file_num[cache_index] == 0)
{
if ((log_descriptor.log_file_num[cache_index]=
open_logfile_by_number_no_cache(data->addr->file_no)) == 0)
open_logfile_by_number_no_cache(file_no)) == 0)
{
DBUG_RETURN(NULL);
}
......@@ -1666,7 +1678,7 @@ uchar *translog_get_page(TRANSLOG_VALIDATOR_DATA *data, uchar *buffer)
buffer= (uchar*)
pagecache_valid_read(log_descriptor.pagecache, &file,
data->addr->rec_offset / TRANSLOG_PAGE_SIZE,
LSN_OFFSET(addr) / TRANSLOG_PAGE_SIZE,
3, (char*) buffer,
PAGECACHE_PLAIN_PAGE,
PAGECACHE_LOCK_LEFT_UNLOCKED, 0,
......@@ -1674,9 +1686,9 @@ uchar *translog_get_page(TRANSLOG_VALIDATOR_DATA *data, uchar *buffer)
}
else
{
File file= open_logfile_by_number_no_cache(data->addr->file_no);
File file= open_logfile_by_number_no_cache(file_no);
if (my_pread(file, (char*) buffer, TRANSLOG_PAGE_SIZE,
data->addr->rec_offset, MYF(MY_FNABP | MY_WME)))
LSN_OFFSET(addr), MYF(MY_FNABP | MY_WME)))
buffer= NULL;
else if (translog_page_validator((byte*) buffer, (gptr) data))
buffer= NULL;
......@@ -1705,25 +1717,28 @@ static my_bool translog_get_last_page_addr(TRANSLOG_ADDRESS *addr,
{
MY_STAT stat_buff, *stat;
char path[FN_REFLEN];
uint32 rec_offset;
uint32 file_no= LSN_FILE_NO(*addr);
DBUG_ENTER("translog_get_last_page_addr");
if ((stat= my_stat (translog_filename_by_fileno(addr->file_no,
if ((stat= my_stat (translog_filename_by_fileno(file_no,
path),
&stat_buff, MYF(MY_WME))) == NULL)
DBUG_RETURN(1);
DBUG_PRINT("info", ("File size %lu", (ulong) stat->st_size));
if (stat->st_size > TRANSLOG_PAGE_SIZE)
{
addr->rec_offset= (((stat->st_size / TRANSLOG_PAGE_SIZE) - 1) *
rec_offset= (((stat->st_size / TRANSLOG_PAGE_SIZE) - 1) *
TRANSLOG_PAGE_SIZE);
*last_page_ok= (stat->st_size == addr->rec_offset + TRANSLOG_PAGE_SIZE);
*last_page_ok= (stat->st_size == rec_offset + TRANSLOG_PAGE_SIZE);
}
else
{
*last_page_ok= 0;
addr->rec_offset= 0;
rec_offset= 0;
}
DBUG_PRINT("info", ("Last page: 0x%lx, ok %d", (ulong) addr->rec_offset,
*addr= MAKE_LSN(file_no, rec_offset);
DBUG_PRINT("info", ("Last page: 0x%lx, ok %d", (ulong) rec_offset,
*last_page_ok));
DBUG_RETURN(0);
}
......@@ -1739,6 +1754,7 @@ static my_bool translog_get_last_page_addr(TRANSLOG_ADDRESS *addr,
RETURN
1,3,4,5 - number of bytes to store given length
*/
static uint translog_variable_record_length_bytes(translog_size_t length)
{
if (length < 250)
......@@ -1764,7 +1780,7 @@ static uint translog_variable_record_length_bytes(translog_size_t length)
0 - Error
*/
uint16 translog_get_chunk_header_length(uchar *page, uint16 offset)
static uint16 translog_get_chunk_header_length(uchar *page, uint16 offset)
{
DBUG_ENTER("translog_get_chunk_header_length");
switch (page[offset] & TRANSLOG_CHUNK_TYPE) {
......@@ -1921,31 +1937,30 @@ my_bool translog_init(const char *directory,
/* TODO: check that last checkpoint within present log addresses space */
/* find the log end */
if (last_checkpoint_lsn.file_no == CONTROL_FILE_IMPOSSIBLE_FILENO)
if (LSN_FILE_NO(last_checkpoint_lsn) == CONTROL_FILE_IMPOSSIBLE_FILENO)
{
DBUG_ASSERT(last_checkpoint_lsn.rec_offset == 0);
DBUG_ASSERT(LSN_OFFSET(last_checkpoint_lsn) == 0);
/* there was no checkpoints we will read from the beginning */
sure_page.file_no= 1;
sure_page.rec_offset= TRANSLOG_PAGE_SIZE;
sure_page= (LSN_ONE_FILE | TRANSLOG_PAGE_SIZE);
}
else
{
sure_page= last_checkpoint_lsn;
DBUG_ASSERT(sure_page.rec_offset % TRANSLOG_PAGE_SIZE != 0);
sure_page.rec_offset-= sure_page.rec_offset % TRANSLOG_PAGE_SIZE;
DBUG_ASSERT(LSN_OFFSET(sure_page) % TRANSLOG_PAGE_SIZE != 0);
sure_page-= LSN_OFFSET(sure_page) % TRANSLOG_PAGE_SIZE;
}
log_descriptor.horizon.file_no= last_page.file_no= last_logno;
log_descriptor.horizon= last_page= MAKE_LSN(last_logno,0);
if (translog_get_last_page_addr(&last_page, &pageok))
DBUG_RETURN(1);
if (last_page.rec_offset == 0)
if (LSN_OFFSET(last_page) == 0)
{
if (last_page.file_no == 1)
if (LSN_FILE_NO(last_page) == 1)
{
logs_found= 0; /* file #1 has no pages */
}
else
{
last_page.file_no--;
last_page-= LSN_ONE_FILE;
if (translog_get_last_page_addr(&last_page, &pageok))
DBUG_RETURN(1);
}
......@@ -1956,25 +1971,22 @@ my_bool translog_init(const char *directory,
TRANSLOG_ADDRESS current_page= sure_page;
my_bool pageok;
DBUG_ASSERT(sure_page.file_no < last_page.file_no ||
(sure_page.file_no == last_page.file_no &&
sure_page.rec_offset <= last_page.rec_offset));
DBUG_ASSERT(sure_page <= last_page);
/* TODO: check page size */
last_valid_page.file_no= CONTROL_FILE_IMPOSSIBLE_FILENO;
last_valid_page.rec_offset= 0;
last_valid_page= CONTROL_FILE_IMPOSSIBLE_LSN;
/* scan and validate pages */
do
{
TRANSLOG_ADDRESS current_file_last_page;
current_file_last_page.file_no= current_page.file_no;
current_file_last_page= current_page;
if (translog_get_last_page_addr(&current_file_last_page, &pageok))
DBUG_RETURN(1);
if (!pageok)
{
DBUG_PRINT("error", ("File %u have no complete last page",
(uint) current_file_last_page.file_no));
DBUG_PRINT("error", ("File %lu have no complete last page",
(ulong) LSN_FILE_NO(current_file_last_page)));
old_log_was_recovered= 1;
/* This file is not written till the end so it should be last */
last_page= current_file_last_page;
......@@ -1992,36 +2004,36 @@ my_bool translog_init(const char *directory,
if (data.was_recovered)
{
DBUG_PRINT("error", ("file no %u (%d), rec_offset 0x%lx (%lu) (%d)",
(uint) current_page.file_no,
(uint3korr(page + 3) != current_page.file_no),
(ulong) current_page.rec_offset,
(ulong) (current_page.rec_offset /
(uint) LSN_FILE_NO(current_page),
(uint3korr(page + 3) !=
LSN_FILE_NO(current_page)),
(ulong) LSN_OFFSET(current_page),
(ulong) (LSN_OFFSET(current_page) /
TRANSLOG_PAGE_SIZE),
(uint3korr(page) !=
current_page.rec_offset / TRANSLOG_PAGE_SIZE)));
LSN_OFFSET(current_page) /
TRANSLOG_PAGE_SIZE)));
old_log_was_recovered= 1;
break;
}
last_valid_page= current_page;
current_page.rec_offset+= TRANSLOG_PAGE_SIZE;
} while (current_page.rec_offset <= current_file_last_page.rec_offset);
current_page.file_no++;
current_page.rec_offset= TRANSLOG_PAGE_SIZE;
} while (current_page.file_no <= last_page.file_no &&
current_page+= TRANSLOG_PAGE_SIZE; /* increase offset */
} while (current_page <= current_file_last_page);
current_page+= LSN_ONE_FILE;
current_page= LSN_REPLACE_OFFSET(current_page, TRANSLOG_PAGE_SIZE);
} while (LSN_FILE_NO(current_page) <= LSN_FILE_NO(last_page) &&
!old_log_was_recovered);
if (last_valid_page.file_no == CONTROL_FILE_IMPOSSIBLE_FILENO)
if (last_valid_page == CONTROL_FILE_IMPOSSIBLE_LSN)
{
DBUG_ASSERT(last_valid_page.rec_offset == 0);
/* Panic!!! Even page which should be valid is invalid */
/* TODO: issue error */
DBUG_RETURN(1);
}
DBUG_PRINT("info", ("Last valid page is in file %lu offset %lu (0x%lx), "
"Logs found: %d, was recovered: %d",
(ulong) last_valid_page.file_no,
(ulong) last_valid_page.rec_offset,
(ulong) last_valid_page.rec_offset,
(ulong) LSN_FILE_NO(last_valid_page),
(ulong) LSN_OFFSET(last_valid_page),
(ulong) LSN_OFFSET(last_valid_page),
logs_found, old_log_was_recovered));
/* TODO: check server ID */
......@@ -2034,7 +2046,8 @@ my_bool translog_init(const char *directory,
uchar buffer[TRANSLOG_PAGE_SIZE], *page;
uint16 chunk_offset;
/* continue old log */
DBUG_ASSERT(last_valid_page.file_no == log_descriptor.horizon.file_no);
DBUG_ASSERT(LSN_FILE_NO(last_valid_page)==
LSN_FILE_NO(log_descriptor.horizon));
if ((page= translog_get_page(&data,
buffer)) == NULL ||
(chunk_offset= translog_get_first_chunk_offset(page)) == 0)
......@@ -2064,8 +2077,9 @@ my_bool translog_init(const char *directory,
log_descriptor.bc.buffer->size+= chunk_offset;
log_descriptor.bc.ptr+= chunk_offset;
log_descriptor.bc.current_page_size= chunk_offset;
log_descriptor.horizon.rec_offset=
chunk_offset + last_valid_page.rec_offset;
log_descriptor.horizon= LSN_REPLACE_OFFSET(log_descriptor.horizon,
(chunk_offset +
LSN_OFFSET(last_valid_page)));
DBUG_PRINT("info", ("Move Page #%u: 0x%lx, chaser: %d, Size: %lu (%lu)",
(uint) log_descriptor.bc.buffer_no,
(ulong) log_descriptor.bc.buffer,
......@@ -2088,16 +2102,14 @@ my_bool translog_init(const char *directory,
if (!logs_found)
{
/* Start new log system from scratch */
/* Current log number */
log_descriptor.horizon.file_no= 1;
/* Used space */
log_descriptor.horizon.rec_offset= TRANSLOG_PAGE_SIZE; // header page
log_descriptor.horizon= MAKE_LSN(1, TRANSLOG_PAGE_SIZE); // header page
/* Current logs file number in page cache */
log_descriptor.log_file_num[0]=
open_logfile_by_number_no_cache(log_descriptor.horizon.file_no);
open_logfile_by_number_no_cache(1);
if (translog_write_file_header())
DBUG_RETURN(1);
if (ma_control_file_write_and_force(NULL, log_descriptor.horizon.file_no,
if (ma_control_file_write_and_force(CONTROL_FILE_IMPOSSIBLE_LSN, 1,
CONTROL_FILE_UPDATE_ONLY_LOGNO))
DBUG_RETURN(1);
/* assign buffer 0 */
......@@ -2124,9 +2136,11 @@ my_bool translog_init(const char *directory,
}
else
{
log_descriptor.horizon.file_no++; /* leave the demaged file
untouched */
log_descriptor.horizon.rec_offset= TRANSLOG_PAGE_SIZE; /* header page */
/* leave the demaged file untouched */
log_descriptor.horizon+= LSN_ONE_FILE;
/* header page */
log_descriptor.horizon= LSN_REPLACE_OFFSET(log_descriptor.horizon,
TRANSLOG_PAGE_SIZE);
if (translog_create_new_file())
DBUG_RETURN(1);
/*
......@@ -2140,8 +2154,8 @@ my_bool translog_init(const char *directory,
/* all LSNs that are on disk are flushed */
log_descriptor.sent_to_file= log_descriptor.flushed= log_descriptor.horizon;
log_descriptor.flushed.rec_offset--;
log_descriptor.sent_to_file.rec_offset--;
log_descriptor.flushed--; /* offset decreased */
log_descriptor.sent_to_file--; /* offset decreased */
DBUG_RETURN(0);
}
......@@ -2162,10 +2176,11 @@ static void translog_buffer_destroy(struct st_translog_buffer *buffer)
{
DBUG_ENTER("translog_buffer_destroy");
DBUG_PRINT("enter",
("Buffer #%u: 0x%lx, file: %u, offset (%u,0x%lx), size %lu",
("Buffer #%u: 0x%lx, file: %u, offset (%lu,0x%lx), size %lu",
(uint) buffer->buffer_no, (ulong) buffer,
(uint) buffer->file,
(ulong) buffer->offset.file_no, (ulong) buffer->offset.rec_offset,
(ulong) LSN_FILE_NO(buffer->offset),
(ulong) LSN_OFFSET(buffer->offset),
(ulong) buffer->size));
DBUG_ASSERT(buffer->waiting_filling_buffer.last_thread == 0);
if (buffer->file)
......@@ -2300,23 +2315,24 @@ static my_bool translog_page_next(TRANSLOG_ADDRESS *horizon,
if ((cursor->ptr +TRANSLOG_PAGE_SIZE >
cursor->buffer->buffer + TRANSLOG_WRITE_BUFFER) ||
(horizon->rec_offset + TRANSLOG_PAGE_SIZE >
log_descriptor.log_file_max_size))
(LSN_OFFSET(*horizon) >
log_descriptor.log_file_max_size - TRANSLOG_PAGE_SIZE))
{
DBUG_PRINT("info", ("Switch to next buffer, Buffer Size %lu (%lu) => %d, "
"File size %lu max %lu => %d",
(ulong) cursor->buffer->size,
(ulong) (cursor->ptr -cursor->buffer->buffer),
(cursor->ptr +TRANSLOG_PAGE_SIZE >
(cursor->ptr + TRANSLOG_PAGE_SIZE >
cursor->buffer->buffer + TRANSLOG_WRITE_BUFFER),
(ulong) horizon->rec_offset,
(ulong) LSN_OFFSET(*horizon),
(ulong) log_descriptor.log_file_max_size,
(horizon->rec_offset + TRANSLOG_PAGE_SIZE >
log_descriptor.log_file_max_size)));
(LSN_OFFSET(*horizon) >
(log_descriptor.log_file_max_size -
TRANSLOG_PAGE_SIZE))));
if (translog_buffer_next(horizon, cursor,
(horizon->rec_offset +
TRANSLOG_PAGE_SIZE) >
log_descriptor.log_file_max_size))
LSN_OFFSET(*horizon) >
(log_descriptor.log_file_max_size -
TRANSLOG_PAGE_SIZE)))
DBUG_RETURN(1);
*prev_buffer= buffer;
DBUG_PRINT("info", ("Buffer #%u (0x%lu) have to be flushed",
......@@ -2353,9 +2369,10 @@ static my_bool translog_page_next(TRANSLOG_ADDRESS *horizon,
1 - Error
*/
my_bool translog_write_data_on_page(TRANSLOG_ADDRESS *horizon,
struct st_buffer_cursor *cursor,
translog_size_t length, uchar *buffer)
static my_bool translog_write_data_on_page(TRANSLOG_ADDRESS *horizon,
struct st_buffer_cursor *cursor,
translog_size_t length,
uchar *buffer)
{
DBUG_ENTER("translog_write_data_on_page");
DBUG_PRINT("enter", ("Chunk length: %lu Page size %u",
......@@ -2367,7 +2384,7 @@ my_bool translog_write_data_on_page(TRANSLOG_ADDRESS *horizon,
memmove(cursor->ptr, buffer, length);
cursor->ptr+= length;
horizon->rec_offset+= length;
*horizon+= length; /* adds offset */
cursor->current_page_size+= length;
if (!cursor->chaser)
cursor->buffer->size+= length;
......@@ -2401,10 +2418,10 @@ my_bool translog_write_data_on_page(TRANSLOG_ADDRESS *horizon,
1 - Error
*/
my_bool translog_write_parts_on_page(TRANSLOG_ADDRESS *horizon,
struct st_buffer_cursor *cursor,
translog_size_t length,
struct st_translog_parts *parts)
static my_bool translog_write_parts_on_page(TRANSLOG_ADDRESS *horizon,
struct st_buffer_cursor *cursor,
translog_size_t length,
struct st_translog_parts *parts)
{
translog_size_t left= length;
uint cur= (uint) parts->current;
......@@ -2457,16 +2474,25 @@ my_bool translog_write_parts_on_page(TRANSLOG_ADDRESS *horizon,
cursor->ptr+= len;
} while (left);
DBUG_PRINT("info", ("Horizon (%lu,0x%lx) Length %lu(0x%lx)",
(ulong) LSN_FILE_NO(*horizon),
(ulong) LSN_OFFSET(*horizon),
(ulong) length, (ulong) length));
parts->current= cur;
horizon->rec_offset+= length;
*horizon+= length; /* offset increasing */
cursor->current_page_size+= length;
if (!cursor->chaser)
cursor->buffer->size+= length;
DBUG_PRINT("info", ("Write parts buffer #%u: 0x%lx, "
"chaser: %d, Size: %lu (%lu)",
DBUG_PRINT("info", ("Write parts buffer #%u: 0x%lx "
"chaser: %d Size: %lu (%lu) "
"Horizon (%lu,0x%lx) buff offset 0x%lx",
(uint) cursor->buffer->buffer_no, (ulong) cursor->buffer,
cursor->chaser, (ulong) cursor->buffer->size,
(ulong) (cursor->ptr -cursor->buffer->buffer)));
(ulong) (cursor->ptr -cursor->buffer->buffer),
(ulong) LSN_FILE_NO(*horizon),
(ulong) LSN_OFFSET(*horizon),
(ulong) (LSN_OFFSET(cursor->buffer->offset) +
cursor->buffer->size)));
DBUG_ASSERT(cursor->chaser ||
((ulong) (cursor->ptr -cursor->buffer->buffer) ==
cursor->buffer->size));
......@@ -2687,15 +2713,14 @@ static my_bool translog_advance_pointer(uint pages, uint16 last_page_data)
{
translog_size_t last_page_offset=
log_descriptor.page_overhead + last_page_data;
translog_size_t offset= TRANSLOG_PAGE_SIZE - log_descriptor.bc.current_page_size /* next
page
*/ +
pages * TRANSLOG_PAGE_SIZE + last_page_offset;
translog_size_t offset= (TRANSLOG_PAGE_SIZE -
log_descriptor.bc.current_page_size +
pages * TRANSLOG_PAGE_SIZE + last_page_offset);
translog_size_t buffer_end_offset, file_end_offset, min_offset;
DBUG_ENTER("translog_advance_pointer");
DBUG_PRINT("enter", ("Pointer: (%u, 0x%lx) + %u + %u pages + %u + %u",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset,
DBUG_PRINT("enter", ("Pointer: (%lu, 0x%lx) + %u + %u pages + %u + %u",
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon),
(uint) (TRANSLOG_PAGE_SIZE -
log_descriptor.bc.current_page_size),
pages, (uint) log_descriptor.page_overhead,
......@@ -2709,7 +2734,7 @@ static my_bool translog_advance_pointer(uint pages, uint16 last_page_data)
struct st_translog_buffer *old_buffer;
buffer_end_offset= TRANSLOG_WRITE_BUFFER - log_descriptor.bc.buffer->size;
file_end_offset=
log_descriptor.log_file_max_size - log_descriptor.horizon.rec_offset;
log_descriptor.log_file_max_size - LSN_OFFSET(log_descriptor.horizon);
DBUG_PRINT("info", ("offset: %lu, buffer_end_offs: %lu, "
"file_end_offs: %lu",
(ulong) offset, (ulong) buffer_end_offset,
......@@ -2719,14 +2744,14 @@ static my_bool translog_advance_pointer(uint pages, uint16 last_page_data)
(uint) log_descriptor.bc.buffer->buffer_no,
(uint) log_descriptor.bc.buffer_no,
(ulong) log_descriptor.bc.buffer,
(ulong) log_descriptor.bc.buffer->offset.rec_offset,
(ulong) LSN_OFFSET(log_descriptor.bc.buffer->offset),
(ulong) log_descriptor.bc.buffer->size,
(ulong) (log_descriptor.bc.buffer->offset.rec_offset +
(ulong) (LSN_OFFSET(log_descriptor.bc.buffer->offset) +
log_descriptor.bc.buffer->size),
(ulong) log_descriptor.horizon.rec_offset));
DBUG_ASSERT(log_descriptor.bc.buffer->offset.rec_offset +
(ulong) LSN_OFFSET(log_descriptor.horizon)));
DBUG_ASSERT(LSN_OFFSET(log_descriptor.bc.buffer->offset) +
log_descriptor.bc.buffer->size ==
log_descriptor.horizon.rec_offset);
LSN_OFFSET(log_descriptor.horizon));
if (offset <= buffer_end_offset && offset <= file_end_offset)
break;
......@@ -2740,7 +2765,7 @@ static my_bool translog_advance_pointer(uint pages, uint16 last_page_data)
min_offset= (buffer_end_offset < file_end_offset ?
buffer_end_offset : file_end_offset);
log_descriptor.bc.buffer->size+= min_offset;
log_descriptor.bc.ptr +=min_offset;
log_descriptor.bc.ptr+= min_offset;
DBUG_PRINT("info", ("NewP buffer #%u: 0x%lx, chaser: %d, Size: %lu (%lu)",
(uint) log_descriptor.bc.buffer->buffer_no,
(ulong) log_descriptor.bc.buffer,
......@@ -2757,9 +2782,11 @@ static my_bool translog_advance_pointer(uint pages, uint16 last_page_data)
if (file_end_offset <= buffer_end_offset)
{
log_descriptor.horizon.file_no++;
log_descriptor.horizon.rec_offset= TRANSLOG_PAGE_SIZE;
DBUG_PRINT("info", ("New file %d", log_descriptor.horizon.file_no));
log_descriptor.horizon+= LSN_ONE_FILE;
log_descriptor.horizon= LSN_REPLACE_OFFSET(log_descriptor.horizon,
TRANSLOG_PAGE_SIZE);
DBUG_PRINT("info", ("New file %lu",
(ulong) LSN_FILE_NO(log_descriptor.horizon)));
if (translog_create_new_file())
{
DBUG_RETURN(1);
......@@ -2768,7 +2795,7 @@ static my_bool translog_advance_pointer(uint pages, uint16 last_page_data)
else
{
DBUG_PRINT("info", ("The same file"));
log_descriptor.horizon.rec_offset+= min_offset;
log_descriptor.horizon+= min_offset; /* offset increasing */
}
translog_start_buffer(new_buffer, &log_descriptor.bc, new_buffer_no);
if (translog_buffer_unlock(old_buffer))
......@@ -2780,7 +2807,7 @@ static my_bool translog_advance_pointer(uint pages, uint16 last_page_data)
log_descriptor.bc.ptr+= offset;
log_descriptor.bc.buffer->size+= offset;
translog_buffer_increase_writers(log_descriptor.bc.buffer);
log_descriptor.horizon.rec_offset+= offset;
log_descriptor.horizon+= offset; /* offset increasing */
log_descriptor.bc.current_page_size= last_page_offset;
DBUG_PRINT("info", ("drop write_counter"));
log_descriptor.bc.write_counter= 0;
......@@ -2801,9 +2828,9 @@ static my_bool translog_advance_pointer(uint pages, uint16 last_page_data)
DBUG_ASSERT(log_descriptor.bc.buffer->buffer_no ==
log_descriptor.bc.buffer_no);
DBUG_PRINT("info",
("pointer moved to: (%u, 0x%lx)",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset));
("pointer moved to: (%lu, 0x%lx)",
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon)));
DBUG_ASSERT((log_descriptor.bc.ptr -log_descriptor.bc.buffer->
buffer) %TRANSLOG_PAGE_SIZE ==
log_descriptor.bc.current_page_size % TRANSLOG_PAGE_SIZE);
......@@ -2865,18 +2892,18 @@ static translog_size_t translog_get_current_group_size()
DBUG_ENTER("translog_get_current_group_size");
DBUG_PRINT("info", ("buffer_rest in pages %lu", buffer_rest));
DBUG_PRINT("info", ("buffer_rest in pages %u", buffer_rest));
buffer_rest*= log_descriptor.page_capacity_chunk_2;
/* in case of only half of buffer free we can write this and next buffer */
if (buffer_rest < log_descriptor.half_buffer_capacity_chunk_2)
{
DBUG_PRINT("info", ("buffer_rest %lu -> add %lu",
DBUG_PRINT("info", ("buffer_rest %u -> add %lu",
buffer_rest,
(ulong) log_descriptor.buffer_capacity_chunk_2));
buffer_rest+= log_descriptor.buffer_capacity_chunk_2;
}
DBUG_PRINT("info", ("buffer_rest %lu", buffer_rest));
DBUG_PRINT("info", ("buffer_rest %u", buffer_rest));
DBUG_RETURN(buffer_rest);
}
......@@ -2984,20 +3011,22 @@ translog_write_variable_record_1group(LSN *lsn,
translog_write_parts_on_page(&horizon, &cursor, first_page, parts);
DBUG_PRINT("info", ("absolute horizon (%u,0x%lx), local (%u,0x%lx)",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset,
(uint) horizon.file_no, (ulong) horizon.rec_offset));
DBUG_PRINT("info", ("absolute horizon (%lu,0x%lx), local (%lu,0x%lx)",
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon),
(ulong) LSN_FILE_NO(horizon),
(ulong) LSN_OFFSET(horizon)));
for (i= 0; i < full_pages; i++)
{
if (translog_write_variable_record_chunk2_page(parts, &horizon, &cursor))
DBUG_RETURN(1);
DBUG_PRINT("info", ("absolute horizon (%u,0x%lx), local (%u,0x%lx)",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset,
(uint) horizon.file_no, (ulong) horizon.rec_offset));
DBUG_PRINT("info", ("absolute horizon (%lu,0x%lx), local (%lu,0x%lx)",
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon),
(ulong) LSN_FILE_NO(horizon),
(ulong) LSN_OFFSET(horizon)));
}
if (additional_chunk3_page)
......@@ -3007,10 +3036,11 @@ translog_write_variable_record_1group(LSN *lsn,
page_capacity_chunk_2 - 2,
&horizon, &cursor))
DBUG_RETURN(1);
DBUG_PRINT("info", ("absolute horizon (%u,0x%lx), local (%u,0x%lx)",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset,
(uint) horizon.file_no, (ulong) horizon.rec_offset));
DBUG_PRINT("info", ("absolute horizon (%lu,0x%lx), local (%lu,0x%lx)",
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon),
(ulong) LSN_FILE_NO(horizon),
(ulong) LSN_OFFSET(horizon)));
DBUG_ASSERT(cursor.current_page_size == TRANSLOG_PAGE_SIZE);
}
......@@ -3018,10 +3048,11 @@ translog_write_variable_record_1group(LSN *lsn,
record_rest,
&horizon, &cursor))
DBUG_RETURN(1);
DBUG_PRINT("info", ("absolute horizon (%u,0x%lx), local (%u,0x%lx)",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset,
(uint) horizon.file_no, (ulong) horizon.rec_offset));
DBUG_PRINT("info", ("absolute horizon (%lu,0x%lx), local (%lu,0x%lx)",
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon),
(ulong) LSN_FILE_NO(horizon),
(ulong) LSN_OFFSET(horizon)));
rc= translog_buffer_lock(cursor.buffer);
if (!rc)
......@@ -3029,7 +3060,6 @@ translog_write_variable_record_1group(LSN *lsn,
/*
check if we wrote something on lst not full page and need to reconstruct
CRC and sector protection
if (buffer->offset.rec_offset + buffer->size - horizon->rec_offset >
*/
translog_buffer_decrease_writers(cursor.buffer);
}
......@@ -3129,19 +3159,19 @@ translog_write_variable_record_1chunk(LSN *lsn,
NULL - error
*/
static uchar *translog_put_LSN_diff(LSN *base_lsn, LSN *lsn, uchar *dst)
static uchar *translog_put_LSN_diff(LSN base_lsn, LSN lsn, uchar *dst)
{
DBUG_ENTER("translog_put_LSN_diff");
DBUG_PRINT("enter", ("Base: (0x%lx,0x%lx), val: (0x%lx,0x%lx), dst 0x%lx",
(ulong) base_lsn->file_no,
(ulong) base_lsn->rec_offset,
(ulong) lsn->file_no,
(ulong) lsn->rec_offset, (ulong) dst));
if (base_lsn->file_no == lsn->file_no)
DBUG_PRINT("enter", ("Base: (0x%lu,0x%lx), val: (0x%lu,0x%lx), dst 0x%lx",
(ulong) LSN_FILE_NO(base_lsn),
(ulong) LSN_OFFSET(base_lsn),
(ulong) LSN_FILE_NO(lsn),
(ulong) LSN_OFFSET(lsn), (ulong) dst));
if (LSN_FILE_NO(base_lsn) == LSN_FILE_NO(lsn))
{
uint32 diff;
DBUG_ASSERT(base_lsn->rec_offset > lsn->rec_offset);
diff= base_lsn->rec_offset - lsn->rec_offset;
DBUG_ASSERT(base_lsn > lsn);
diff= base_lsn - lsn;
if (diff <= 0x3FFF)
{
dst-= 2;
......@@ -3171,16 +3201,16 @@ static uchar *translog_put_LSN_diff(LSN *base_lsn, LSN *lsn, uchar *dst)
{
uint32 diff;
uint32 offset_diff;
ulonglong base_offset= base_lsn->rec_offset;
DBUG_ASSERT(base_lsn->file_no > lsn->file_no);
diff= base_lsn->file_no - lsn->file_no;
if (base_offset < lsn->rec_offset)
ulonglong base_offset= LSN_OFFSET(base_lsn);
DBUG_ASSERT(base_lsn > lsn);
diff= LSN_FILE_NO(base_lsn) - LSN_FILE_NO(lsn);
if (base_offset < LSN_OFFSET(lsn))
{
/* take 1 from file offset */
diff--;
base_offset+= 0x100000000LL;
}
offset_diff= base_offset - lsn->rec_offset;
offset_diff= base_offset - LSN_OFFSET(lsn);
if (diff > 0x3f)
{
/*TODO: error - too long transaction - panic!!! */
......@@ -3222,7 +3252,7 @@ static uchar *translog_put_LSN_diff(LSN *base_lsn, LSN *lsn, uchar *dst)
pointer to buffer after decoded LSN
*/
static uchar *translog_get_LSN_from_diff(LSN *base_lsn, uchar *src, uchar *dst)
static uchar *translog_get_LSN_from_diff(LSN base_lsn, uchar *src, uchar *dst)
{
LSN lsn;
uint32 diff;
......@@ -3230,42 +3260,39 @@ static uchar *translog_get_LSN_from_diff(LSN *base_lsn, uchar *src, uchar *dst)
uint8 code;
DBUG_ENTER("translog_get_LSN_from_diff");
DBUG_PRINT("enter", ("Base: (0x%lx,0x%lx), src: 0x%lx, dst 0x%lx",
(ulong) base_lsn->file_no,
(ulong) base_lsn->rec_offset, (ulong) src, (ulong) dst));
(ulong) LSN_FILE_NO(base_lsn),
(ulong) LSN_OFFSET(base_lsn),
(ulong) src, (ulong) dst));
first_byte= *((uint8*) src);
code= first_byte & 0xC0;
first_byte &= 0x3F;
switch (code) {
case 0x00:
lsn.file_no= base_lsn->file_no;
lsn.rec_offset=
base_lsn->rec_offset - ((first_byte << 8) + *((uint8*) (src + 1)));
lsn= base_lsn - ((first_byte << 8) + *((uint8*) (src + 1)));
src+= 2;
break;
case 0x40:
lsn.file_no= base_lsn->file_no;
diff= uint2korr(src + 1);
lsn.rec_offset= base_lsn->rec_offset - ((first_byte << 16) + diff);
lsn= base_lsn - ((first_byte << 16) + diff);
src+= 3;
break;
case 0x80:
lsn.file_no= base_lsn->file_no;
diff= uint3korr(src + 1);
lsn.rec_offset= base_lsn->rec_offset - ((first_byte << 24) + diff);
lsn= base_lsn - ((first_byte << 24) + diff);
src+= 4;
break;
case 0xC0:
{
ulonglong base_offset= base_lsn->rec_offset;
diff= uint4korr(src + 1);
if (diff > base_lsn->rec_offset)
ulonglong base_offset= LSN_OFFSET(base_lsn);
if (diff > LSN_OFFSET(base_lsn))
{
/* take 1 from file offset */
first_byte++;
base_offset+= 0x100000000LL;
}
lsn.file_no= base_lsn->file_no - first_byte;
lsn.rec_offset= base_offset - diff;
lsn= MAKE_LSN(LSN_FILE_NO(base_lsn) - first_byte,
base_offset - diff);
src+= 5;
break;
}
......@@ -3273,7 +3300,7 @@ static uchar *translog_get_LSN_from_diff(LSN *base_lsn, uchar *src, uchar *dst)
DBUG_ASSERT(0);
DBUG_RETURN(NULL);
}
lsn7store(dst, &lsn);
lsn7store(dst, lsn);
DBUG_PRINT("info", ("new src: 0x%lx", (ulong) dst));
DBUG_RETURN(src);
}
......@@ -3295,7 +3322,7 @@ static uchar *translog_get_LSN_from_diff(LSN *base_lsn, uchar *src, uchar *dst)
*/
static my_bool translog_relative_LSN_encode(struct st_translog_parts *parts,
LSN *base_lsn,
LSN base_lsn,
uint lsns, uchar *compressed_LSNs)
{
struct st_translog_part part;
......@@ -3345,8 +3372,8 @@ static my_bool translog_relative_LSN_encode(struct st_translog_parts *parts,
uint i;
for (i= 0; i < lsns; i++, ref_ptr-= 7)
{
lsn7korr(&ref, ref_ptr);
if ((dst_ptr= translog_put_LSN_diff(base_lsn, &ref, dst_ptr)) == NULL)
ref= lsn7korr(ref_ptr);
if ((dst_ptr= translog_put_LSN_diff(base_lsn, ref, dst_ptr)) == NULL)
DBUG_RETURN(1);
}
economy= (dst_ptr - part.buff);
......@@ -3462,14 +3489,15 @@ translog_write_variable_record_mgroup(LSN *lsn,
DBUG_RETURN(1);
}
DBUG_PRINT("info", ("chunk #%u first_page: %u (%u), full_pages: %u (%lu), "
DBUG_PRINT("info", ("chunk #%u first_page: %u (%u), full_pages: %lu (%lu), "
"Left %lu",
groups.elements,
first_page, first_page - 1,
full_pages,
(ulong) full_pages,
(ulong) full_pages *
log_descriptor.page_capacity_chunk_2,
parts->record_length - (first_page - 1 + buffer_rest) -
(ulong)parts->record_length -
(first_page - 1 + buffer_rest) -
done));
translog_advance_pointer(full_pages, 0);
......@@ -3493,12 +3521,12 @@ translog_write_variable_record_mgroup(LSN *lsn,
translog_write_data_on_page(&horizon, &cursor, 1, chunk2_header);
translog_write_parts_on_page(&horizon, &cursor, first_page - 1, parts);
DBUG_PRINT("info", ("absolute horizon (%u,0x%lx), local (%u,0x%lx) "
DBUG_PRINT("info", ("absolute horizon (%lu,0x%lx), local (%lu,0x%lx) "
"Left: %lu",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset,
(uint) horizon.file_no,
(ulong) horizon.rec_offset,
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon),
(ulong) LSN_FILE_NO(horizon),
(ulong) LSN_OFFSET(horizon),
(ulong) (parts->record_length - (first_page - 1) -
done)));
......@@ -3510,12 +3538,12 @@ translog_write_variable_record_mgroup(LSN *lsn,
DBUG_RETURN(1);
}
DBUG_PRINT("info", ("absolute horizon (%u,0x%lx), local (%u,0x%lx)"
DBUG_PRINT("info", ("absolute horizon (%lu,0x%lx), local (%lu,0x%lx)"
"Left: %lu",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset,
(uint) horizon.file_no,
(ulong) horizon.rec_offset,
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon),
(ulong) LSN_FILE_NO(horizon),
(ulong) LSN_OFFSET(horizon),
(ulong) (parts->record_length - (first_page - 1) -
i * log_descriptor.page_capacity_chunk_2 -
done)));
......@@ -3559,8 +3587,7 @@ translog_write_variable_record_mgroup(LSN *lsn,
group.addr= horizon= log_descriptor.horizon;
cursor= log_descriptor.bc;
cursor.chaser= 1;
group.num= 0; /* 0 because it does not matter
*/
group.num= 0; /* 0 because it does not matter */
if (insert_dynamic(&groups, (gptr) &group))
{
delete_dynamic(&groups);
......@@ -3643,12 +3670,12 @@ translog_write_variable_record_mgroup(LSN *lsn,
DBUG_PRINT("info", ("chunk 2 to finish first page"));
translog_write_data_on_page(&horizon, &cursor, 1, chunk2_header);
translog_write_parts_on_page(&horizon, &cursor, first_page - 1, parts);
DBUG_PRINT("info", ("absolute horizon (%u,0x%lx), local (%u,0x%lx) "
DBUG_PRINT("info", ("absolute horizon (%lu,0x%lx), local (%lu,0x%lx) "
"Left: %lu",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset,
(uint) horizon.file_no,
(ulong) horizon.rec_offset,
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon),
(ulong) LSN_FILE_NO(horizon),
(ulong) LSN_OFFSET(horizon),
(ulong) (parts->record_length - (first_page - 1) -
done)));
}
......@@ -3661,12 +3688,12 @@ translog_write_variable_record_mgroup(LSN *lsn,
int2store(chunk3_header + 1, chunk3_size);
translog_write_data_on_page(&horizon, &cursor, 3, chunk3_header);
translog_write_parts_on_page(&horizon, &cursor, chunk3_size, parts);
DBUG_PRINT("info", ("absolute horizon (%u,0x%lx), local (%u,0x%lx) "
DBUG_PRINT("info", ("absolute horizon (%lu,0x%lx), local (%lu,0x%lx) "
"Left: %lu",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset,
(uint) horizon.file_no,
(ulong) horizon.rec_offset,
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon),
(ulong) LSN_FILE_NO(horizon),
(ulong) LSN_OFFSET(horizon),
(ulong) (parts->record_length - chunk3_size - done)));
chunk3_pages= 0;
}
......@@ -3685,12 +3712,12 @@ translog_write_variable_record_mgroup(LSN *lsn,
DBUG_RETURN(1);
}
DBUG_PRINT("info", ("absolute horizon (%u,0x%lx), local (%u,0x%lx) "
DBUG_PRINT("info", ("absolute horizon (%lu,0x%lx), local (%lu,0x%lx) "
"Left: %lu",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset,
(uint) horizon.file_no,
(ulong) horizon.rec_offset,
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon),
(ulong) LSN_FILE_NO(horizon),
(ulong) LSN_OFFSET(horizon),
(ulong) (parts->record_length - (first_page - 1) -
i * log_descriptor.page_capacity_chunk_2 -
done)));
......@@ -3704,10 +3731,11 @@ translog_write_variable_record_mgroup(LSN *lsn,
delete_dynamic(&groups);
DBUG_RETURN(1);
}
DBUG_PRINT("info", ("absolute horizon (%u,0x%lx), local (%u,0x%lx)",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset,
(uint) horizon.file_no, (ulong) horizon.rec_offset));
DBUG_PRINT("info", ("absolute horizon (%lu,0x%lx), local (%lu,0x%lx)",
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon),
(ulong) LSN_FILE_NO(horizon),
(ulong) LSN_OFFSET(horizon)));
*chunk0_header= (uchar) (type |TRANSLOG_CHUNK_LSN);
......@@ -3783,7 +3811,7 @@ translog_write_variable_record_mgroup(LSN *lsn,
for (i= curr_group; i < limit + curr_group; i++)
{
get_dynamic(&groups, (gptr) &group, i);
lsn7store(group_desc, &group.addr);
lsn7store(group_desc, group.addr);
group_desc[7]= group.num;
translog_write_data_on_page(&horizon, &cursor, (7 + 1), group_desc);
}
......@@ -3840,9 +3868,9 @@ static my_bool translog_write_variable_record(LSN *lsn,
DBUG_ENTER("translog_write_variable_record");
translog_lock();
DBUG_PRINT("info", ("horizon (%u,0x%lx)",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset));
DBUG_PRINT("info", ("horizon (%lu,0x%lx)",
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon)));
page_rest= TRANSLOG_PAGE_SIZE - log_descriptor.bc.current_page_size;
DBUG_PRINT("info", ("header length %u, page_rest: %u",
header_length1, page_rest));
......@@ -3871,7 +3899,7 @@ static my_bool translog_write_variable_record(LSN *lsn,
*/
if (log_record_type_descriptor[type].compresed_LSN > 0)
{
if (translog_relative_LSN_encode(parts, &log_descriptor.horizon,
if (translog_relative_LSN_encode(parts, log_descriptor.horizon,
log_record_type_descriptor[type].
compresed_LSN, compressed_LSNs))
{
......@@ -3889,7 +3917,7 @@ static my_bool translog_write_variable_record(LSN *lsn,
translog_variable_record_length_bytes(parts->record_length);
DBUG_PRINT("info", ("after compressing LSN(s) header length %u, "
"record length %lu",
header_length1, parts->record_length));
header_length1, (ulong)parts->record_length));
}
/* TODO: check space on current page for header + few bytes */
......@@ -3960,9 +3988,9 @@ static my_bool translog_write_fixed_record(LSN *lsn,
log_record_type_descriptor[type].fixed_length));
translog_lock();
DBUG_PRINT("info", ("horizon (%u,0x%lx)",
(uint) log_descriptor.horizon.file_no,
(ulong) log_descriptor.horizon.rec_offset));
DBUG_PRINT("info", ("horizon (%lu,0x%lx)",
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) LSN_OFFSET(log_descriptor.horizon)));
DBUG_ASSERT(log_descriptor.bc.current_page_size <= TRANSLOG_PAGE_SIZE);
DBUG_PRINT("info",
......@@ -4002,7 +4030,7 @@ static my_bool translog_write_fixed_record(LSN *lsn,
if (log_record_type_descriptor[type].class == LOGRECTYPE_PSEUDOFIXEDLENGTH)
{
DBUG_ASSERT(log_record_type_descriptor[type].compresed_LSN > 0);
if (translog_relative_LSN_encode(parts, lsn,
if (translog_relative_LSN_encode(parts, *lsn,
log_record_type_descriptor[type].
compresed_LSN, compressed_LSNs))
{
......@@ -4185,7 +4213,7 @@ my_bool translog_write_record(LSN *lsn,
position in sources after decoded LSN(s)
*/
static uchar *translog_relative_LSN_decode(LSN *base_lsn,
static uchar *translog_relative_LSN_decode(LSN base_lsn,
uchar *src, uchar *dst, uint lsns)
{
uint i;
......@@ -4231,7 +4259,7 @@ translog_size_t translog_fixed_length_header(uchar *page,
if (desc->class == LOGRECTYPE_PSEUDOFIXEDLENGTH)
{
DBUG_ASSERT(lsns > 0);
src= translog_relative_LSN_decode(&buff->lsn, src, dst, lsns);
src= translog_relative_LSN_decode(buff->lsn, src, dst, lsns);
lsns*= 7;
dst+= lsns;
length-= lsns;
......@@ -4321,7 +4349,7 @@ static my_bool translog_scanner_set_last_page(struct st_translog_scanner_data
0 - OK
1 - Error
*/
static my_bool translog_init_scanner(LSN *lsn,
static my_bool translog_init_scanner(LSN lsn,
my_bool fixed_horizon,
struct st_translog_scanner_data *scanner)
{
......@@ -4331,25 +4359,24 @@ static my_bool translog_init_scanner(LSN *lsn,
};
DBUG_ENTER("translog_init_scanner");
DBUG_PRINT("enter", ("LSN: (0x%lx,0x%lx)",
(ulong) lsn->file_no, (ulong) lsn->rec_offset));
DBUG_ASSERT(lsn->rec_offset % TRANSLOG_PAGE_SIZE != 0);
scanner->page_offset= lsn->rec_offset % TRANSLOG_PAGE_SIZE;
DBUG_PRINT("enter", ("LSN: (0x%lu,0x%lx)",
(ulong) LSN_FILE_NO(lsn),
(ulong) LSN_OFFSET(lsn));
DBUG_ASSERT(LSN_OFFSET(lsn) % TRANSLOG_PAGE_SIZE != 0);
scanner->page_offset= LSN_OFFSET(lsn) % TRANSLOG_PAGE_SIZE;
scanner->fixed_horizon= fixed_horizon;
translog_scanner_set_horizon(scanner);
DBUG_PRINT("info", ("Horizon: (0x%lx,0x%lx)",
(ulong) scanner->horizon.file_no,
(ulong) scanner->horizon.rec_offset));
DBUG_PRINT("info", ("Horizon: (0x%lu,0x%lx)",
(ulong) LSN_FILE_NO(scanner->horizon),
(ulong) LSN_OFFSET(scanner->horizon)));
/* lsn < horizon */
DBUG_ASSERT(lsn->file_no < scanner->horizon.file_no ||
(lsn->file_no == scanner->horizon.file_no &&
lsn->rec_offset < scanner->horizon.rec_offset));
DBUG_ASSERT(lsn < scanner->horizon));
scanner->page_addr= *lsn;
scanner->page_addr.rec_offset-= scanner->page_offset;
scanner->page_addr= lsn;
scanner->page_addr-= scanner->page_offset; /*decrease offset */
if (translog_scanner_set_last_page(scanner))
DBUG_RETURN(1);
......@@ -4376,16 +4403,14 @@ static my_bool translog_scanner_eol(struct st_translog_scanner_data *scanner)
DBUG_ENTER("translog_scanner_eol");
DBUG_PRINT("enter",
("Horizon: (%lu, 0x%lx), Current: (%lu, 0x%lx+0x%x=0x%lx)",
(ulong) scanner->horizon.file_no,
(ulong) scanner->horizon.rec_offset,
(ulong) scanner->page_addr.file_no,
(ulong) scanner->page_addr.rec_offset,
(ulong) LSN_FILE_NO(scanner->horizon),
(ulong) LSN_OFFSET(scanner->horizon),
(ulong) LSN_FILE_NO(scanner->page_addr),
(ulong) LSN_OFFSET(scanner->page_addr),
(uint) scanner->page_offset,
(ulong) (scanner->page_addr.rec_offset + scanner->page_offset)));
if (scanner->horizon.file_no > scanner->page_addr.file_no ||
(scanner->horizon.file_no == scanner->page_addr.file_no &&
scanner->horizon.rec_offset > (scanner->page_addr.rec_offset +
scanner->page_offset)))
(ulong) (LSN_OFFSET(scanner->page_addr) + scanner->page_offset)));
if (scanner->horizon > (scanner->page_addr +
scanner->page_offset))
{
DBUG_PRINT("info", ("Horizon is not reached"));
DBUG_RETURN(0);
......@@ -4398,14 +4423,10 @@ static my_bool translog_scanner_eol(struct st_translog_scanner_data *scanner)
translog_scanner_set_horizon(scanner);
DBUG_PRINT("info",
("Horizon is re-read, EOL: %d",
scanner->horizon.file_no <= scanner->page_addr.file_no &&
(scanner->horizon.file_no != scanner->page_addr.file_no ||
scanner->horizon.rec_offset <= (scanner->page_addr.rec_offset +
scanner->page_offset))));
DBUG_RETURN(scanner->horizon.file_no <= scanner->page_addr.file_no &&
(scanner->horizon.file_no != scanner->page_addr.file_no ||
scanner->horizon.rec_offset <= (scanner->page_addr.rec_offset +
scanner->page_offset)));
scanner->horizon <= (scanner->page_addr +
scanner->page_offset)));
DBUG_RETURN(scanner->horizon <= (scanner->page_addr +
scanner->page_offset));
}
......@@ -4443,19 +4464,20 @@ static my_bool translog_scanner_eop(struct st_translog_scanner_data *scanner)
static my_bool translog_scanner_eof(struct st_translog_scanner_data *scanner)
{
DBUG_ENTER("translog_scanner_eof");
DBUG_ASSERT(scanner->page_addr.file_no == scanner->last_file_page.file_no);
DBUG_ASSERT(LSN_FILE_NO(scanner->page_addr) ==
LSN_FILE_NO(scanner->last_file_page));
DBUG_PRINT("enter", ("curr Page 0x%lx, last page 0x%lx, "
"normal EOF %d",
scanner->page_addr.rec_offset,
scanner->last_file_page.rec_offset,
scanner->page_addr.rec_offset ==
scanner->last_file_page.rec_offset));
(ulong) LSN_OFFSET(scanner->page_addr),
(ulong) LSN_OFFSET(scanner->last_file_page),
LSN_OFFSET(scanner->page_addr) ==
LSN_OFFSET(scanner->last_file_page)));
/*
TODO: detect damaged file EOF,
TODO: issue warning if damaged file EOF detected
*/
DBUG_RETURN(scanner->page_addr.rec_offset ==
scanner->last_file_page.rec_offset);
DBUG_RETURN(scanner->page_addr ==
scanner->last_file_page);
}
......@@ -4491,20 +4513,22 @@ static my_bool translog_get_next_chunk(struct st_translog_scanner_data *scanner)
if (translog_scanner_eof(scanner))
{
DBUG_PRINT("info", ("horizon (%lu,0x%lx) pageaddr (%lu,0x%lx)",
(ulong) scanner->horizon.file_no,
(ulong) scanner->horizon.rec_offset,
(ulong) scanner->page_addr.file_no,
(ulong) scanner->page_addr.rec_offset));
(ulong) LSN_FILE_NO(scanner->horizon),
(ulong) LSN_OFFSET(scanner->horizon),
(ulong) LSN_FILE_NO(scanner->page_addr),
(ulong) LSN_OFFSET(scanner->page_addr)));
/* if it is log end it have to be caught before */
DBUG_ASSERT(scanner->horizon.file_no > scanner->page_addr.file_no);
scanner->page_addr.file_no++;
scanner->page_addr.rec_offset= TRANSLOG_PAGE_SIZE;
DBUG_ASSERT(LSN_FILE_NO(scanner->horizon) >
LSN_FILE_NO(scanner->page_addr));
scanner->page_addr+= LSN_ONE_FILE;
scanner->page_addr= LSN_REPLACE_OFFSET(scanner->page_addr,
TRANSLOG_PAGE_SIZE);
if (translog_scanner_set_last_page(scanner))
DBUG_RETURN(1);
}
else
{
scanner->page_addr.rec_offset+= TRANSLOG_PAGE_SIZE;
scanner->page_addr+= TRANSLOG_PAGE_SIZE; /* offset increased */
}
{
TRANSLOG_VALIDATOR_DATA data=
......@@ -4614,12 +4638,12 @@ translog_size_t translog_variable_length_header(uchar *page,
for (i= 0; i < read; i++, curr++)
{
DBUG_ASSERT(curr < buff->groups_no);
lsn7korr(&buff->groups[curr].addr, src + i * (7 + 1));
buff->groups[curr].addr= lsn7korr(src + i * (7 + 1));
buff->groups[curr].num= src[i * (7 + 1) + 7];
DBUG_PRINT("info", ("group #%u (%u,0x%lx) chunks %u",
DBUG_PRINT("info", ("group #%u (%lu,0x%lx) chunks %u",
curr,
(uint) buff->groups[curr].addr.file_no,
(ulong) buff->groups[curr].addr.rec_offset,
(ulong) LSN_FILE_NO(buff->groups[curr].addr),
(ulong) LSN_OFFSET(buff->groups[curr].addr),
(uint) buff->groups[curr].num));
}
grp_no-= read;
......@@ -4628,18 +4652,19 @@ translog_size_t translog_variable_length_header(uchar *page,
if (scanner)
{
buff->chunk0_data_addr= scanner->page_addr;
buff->chunk0_data_addr.rec_offset+= (page_offset + header_to_skip +
i * (7 + 1));
buff->chunk0_data_addr+= (page_offset + header_to_skip +
i * (7 + 1)); /* offset increased */
}
else
{
buff->chunk0_data_addr= buff->lsn;
buff->chunk0_data_addr.rec_offset+= (header_to_skip + i * (7 + 1));
/* offset increased */
buff->chunk0_data_addr+= (header_to_skip + i * (7 + 1));
}
buff->chunk0_data_len= chunk_len - 2 - i * (7 + 1);
DBUG_PRINT("info", ("Data address (%u,0x%lx), len: %u",
(uint) buff->chunk0_data_addr.file_no,
(ulong) buff->chunk0_data_addr.rec_offset,
DBUG_PRINT("info", ("Data address (%lu,0x%lx), len: %u",
(ulong) LSN_FILE_NO(buff->chunk0_data_addr),
(ulong) LSN_OFFSET(buff->chunk0_data_addr),
buff->chunk0_data_len));
break;
}
......@@ -4647,7 +4672,7 @@ translog_size_t translog_variable_length_header(uchar *page,
{
DBUG_PRINT("info", ("use internal scanner for header reding"));
scanner= &internal_scanner;
translog_init_scanner(&buff->lsn, 1, scanner);
translog_init_scanner(buff->lsn, 1, scanner);
}
translog_get_next_chunk(scanner);
page= scanner->page;
......@@ -4665,7 +4690,7 @@ translog_size_t translog_variable_length_header(uchar *page,
}
base_lsn= buff->groups[0].addr;
translog_init_scanner(&base_lsn, 1, scanner);
translog_init_scanner(base_lsn, 1, scanner);
/* first group chunk is always chunk type 2 */
page= scanner->page;
page_offset= scanner->page_offset;
......@@ -4676,7 +4701,7 @@ translog_size_t translog_variable_length_header(uchar *page,
if (lsns)
{
uchar *start= src;
src= translog_relative_LSN_decode(&base_lsn, src, dst, lsns);
src= translog_relative_LSN_decode(base_lsn, src, dst, lsns);
lsns*= 7;
dst+= lsns;
length-= lsns;
......@@ -4730,9 +4755,10 @@ translog_read_record_header_from_buffer(uchar *page,
TRANSLOG_CHUNK_FIXED);
buff->type= (page[page_offset] & TRANSLOG_REC_TYPE);
buff->short_trid= uint2korr(page + page_offset + 1);
DBUG_PRINT("info", ("Type %u, Sort TrID %u, LSN (%u,0x%lx)",
DBUG_PRINT("info", ("Type %u, Sort TrID %u, LSN (%lu,0x%lx)",
(uint) buff->type, (uint)buff->short_trid,
buff->lsn.file_no, buff->lsn.rec_offset));
(ulong) LSN_FILE_NO(buff->lsn),
(ulong) LSN_OFFSET(buff->lsn)));
/* Read required bytes from the header and call hook */
switch (log_record_type_descriptor[buff->type].class)
{
......@@ -4773,26 +4799,26 @@ translog_read_record_header_from_buffer(uchar *page,
part of the header
*/
translog_size_t translog_read_record_header(LSN *lsn,
translog_size_t translog_read_record_header(LSN lsn,
TRANSLOG_HEADER_BUFFER *buff)
{
uchar buffer[TRANSLOG_PAGE_SIZE], *page;
translog_size_t page_offset= lsn->rec_offset % TRANSLOG_PAGE_SIZE;
translog_size_t page_offset= LSN_OFFSET(lsn) % TRANSLOG_PAGE_SIZE;
DBUG_ENTER("translog_read_record_header");
DBUG_PRINT("enter", ("LSN: (0x%lx,0x%lx)",
(ulong) lsn->file_no, (ulong) lsn->rec_offset));
DBUG_ASSERT(lsn->rec_offset % TRANSLOG_PAGE_SIZE != 0);
DBUG_PRINT("enter", ("LSN: (0x%lu,0x%lx)",
(ulong) LSN_FILE_NO(lsn), (ulong) LSN_OFFSET(lsn)));
DBUG_ASSERT(LSN_OFFSET(lsn) % TRANSLOG_PAGE_SIZE != 0);
buff->lsn= *lsn;
buff->lsn= lsn;
buff->groups_no= 0;
{
TRANSLOG_ADDRESS addr= *lsn;
TRANSLOG_ADDRESS addr= lsn;
TRANSLOG_VALIDATOR_DATA data=
{
&addr, 0
};
addr.rec_offset-= page_offset;
addr-= page_offset; /* offset decreasing */
if ((page= translog_get_page(&data, buffer)) == NULL)
DBUG_RETURN(0);
}
......@@ -4832,19 +4858,19 @@ translog_read_record_header_scan(struct st_translog_scanner_data
my_bool move_scanner)
{
DBUG_ENTER("translog_read_record_header_scan");
DBUG_PRINT("enter", ("Scanner: Cur: (%u, 0x%lx), Hrz: (%u, 0x%lx), "
"Lst: (%u, 0x%lx), Offset: %u(%x), fixed %d",
(uint) scanner->page_addr.file_no,
(ulong) scanner->page_addr.rec_offset,
(uint) scanner->horizon.file_no,
(ulong) scanner->horizon.rec_offset,
(uint) scanner->last_file_page.file_no,
(ulong) scanner->last_file_page.rec_offset,
DBUG_PRINT("enter", ("Scanner: Cur: (%lu,0x%lx), Hrz: (%lu,0x%lx), "
"Lst: (%lu,0x%lx), Offset: %u(%x), fixed %d",
(ulong) LSN_FILE_NO(scanner->page_addr),
(ulong) LSN_OFFSET(scanner->page_addr),
(ulong) LSN_FILE_NO(scanner->horizon),
(ulong) LSN_OFFSET(scanner->horizon),
(ulong) LSN_FILE_NO(scanner->last_file_page),
(ulong) LSN_OFFSET(scanner->last_file_page),
(uint) scanner->page_offset,
(uint) scanner->page_offset, scanner->fixed_horizon));
buff->groups_no= 0;
buff->lsn= scanner->page_addr;
buff->lsn.rec_offset+= scanner->page_offset;
buff->lsn+= scanner->page_offset; /* offset increasing */
DBUG_RETURN(translog_read_record_header_from_buffer(scanner->page,
scanner->page_offset,
buff,
......@@ -4884,7 +4910,8 @@ translog_read_record_header_scan(struct st_translog_scanner_data
number of bytes in TRANSLOG_HEADER_BUFFER::header where stored decoded
part of the header
*/
translog_size_t translog_read_next_record_header(LSN *lsn,
translog_size_t translog_read_next_record_header(LSN lsn,
TRANSLOG_HEADER_BUFFER *buff,
my_bool fixed_horizon,
struct
......@@ -4894,30 +4921,29 @@ translog_size_t translog_read_next_record_header(LSN *lsn,
struct st_translog_scanner_data internal_scanner;
uint8 chunk_type;
buff->groups_no= 0; /* to be sure that we will free
it right */
buff->groups_no= 0; /* to be sure that we will free it right */
DBUG_ENTER("translog_read_next_record_header");
DBUG_PRINT("enter", ("scanner: 0x%lx", (ulong) scanner));
if (scanner == NULL)
{
DBUG_ASSERT(lsn != NULL);
DBUG_ASSERT(lsn != CONTROL_FILE_IMPOSSIBLE_LSN);
scanner= &internal_scanner;
}
if (lsn)
{
if (translog_init_scanner(lsn, fixed_horizon, scanner))
DBUG_RETURN(0);
DBUG_ASSERT(lsn->rec_offset % TRANSLOG_PAGE_SIZE != 0);
DBUG_ASSERT(LSN_OFFSET(lsn) % TRANSLOG_PAGE_SIZE != 0);
}
DBUG_PRINT("info", ("Scanner: Cur: (%u, 0x%lx), Hrz: (%u, 0x%lx), "
"Lst: (%u, 0x%lx), Offset: %u(%x), fixed %d",
(uint) scanner->page_addr.file_no,
(ulong) scanner->page_addr.rec_offset,
(uint) scanner->horizon.file_no,
(ulong) scanner->horizon.rec_offset,
(uint) scanner->last_file_page.file_no,
(ulong) scanner->last_file_page.rec_offset,
DBUG_PRINT("info", ("Scanner: Cur: (%lu,0x%lx), Hrz: (%lu,0x%lx), "
"Lst: (%lu,0x%lx), Offset: %u(%x), fixed %d",
(ulong) LSN_FILE_NO(scanner->page_addr),
(ulong) LSN_OFFSET(scanner->page_addr),
(ulong) LSN_FILE_NO(scanner->horizon),
(ulong) LSN_OFFSET(scanner->horizon),
(ulong) LSN_FILE_NO(scanner->last_file_page),
(ulong) LSN_OFFSET(scanner->last_file_page),
(uint) scanner->page_offset,
(uint) scanner->page_offset, scanner->fixed_horizon));
......@@ -4934,10 +4960,8 @@ translog_size_t translog_read_next_record_header(LSN *lsn,
if (scanner->page[scanner->page_offset] == 0)
{
/* Last record was read */
buff->lsn.file_no= CONTROL_FILE_IMPOSSIBLE_FILENO;
buff->lsn.rec_offset= 0;
DBUG_RETURN(TRANSLOG_RECORD_HEADER_MAX_SIZE + 1); /* just it is not error
*/
buff->lsn= CONTROL_FILE_IMPOSSIBLE_LSN;
DBUG_RETURN(TRANSLOG_RECORD_HEADER_MAX_SIZE + 1); /* just it is not error */
}
DBUG_RETURN(translog_read_record_header_scan(scanner, buff, 0));
}
......@@ -4955,6 +4979,7 @@ translog_size_t translog_read_next_record_header(LSN *lsn,
0 - OK
1 - Error
*/
static my_bool translog_record_read_next_chunk(struct st_translog_reader_data
*data)
{
......@@ -4978,7 +5003,7 @@ static my_bool translog_record_read_next_chunk(struct st_translog_reader_data
data->current_group++;
data->current_chunk= 0;
DBUG_PRINT("info", ("skip to group #%u", data->current_group));
translog_init_scanner(&data->header.groups[data->current_group].addr,
translog_init_scanner(data->header.groups[data->current_group].addr,
1, &data->scanner);
}
else
......@@ -4996,10 +5021,9 @@ static my_bool translog_record_read_next_chunk(struct st_translog_reader_data
data->header.chunk0_data_len, data->scanner.page_offset,
data->current_group, data->header.groups_no - 1));
DBUG_ASSERT(data->header.groups_no - 1 == data->current_group);
DBUG_ASSERT(data->header.lsn.file_no == data->scanner.page_addr.file_no &&
data->header.lsn.rec_offset ==
data->scanner.page_addr.rec_offset + data->scanner.page_offset);
translog_init_scanner(&data->header.chunk0_data_addr, 1, &data->scanner);
DBUG_ASSERT(data->header.lsn ==
data->scanner.page_addr + data->scanner.page_offset);
translog_init_scanner(data->header.chunk0_data_addr, 1, &data->scanner);
data->chunk_size= data->header.chunk0_data_len;
data->body_offset= data->scanner.page_offset;
data->current_offset= new_current_offset;
......@@ -5044,7 +5068,7 @@ static my_bool translog_record_read_next_chunk(struct st_translog_reader_data
1 - Error
*/
static my_bool translog_init_reader_data(LSN *lsn,
static my_bool translog_init_reader_data(LSN lsn,
struct st_translog_reader_data *data)
{
DBUG_ENTER("translog_init_reader_data");
......@@ -5085,7 +5109,7 @@ static my_bool translog_init_reader_data(LSN *lsn,
length of data actually read
*/
translog_size_t translog_read_record(LSN *lsn,
translog_size_t translog_read_record(LSN lsn,
translog_size_t offset,
translog_size_t length,
uchar *buffer,
......@@ -5099,7 +5123,7 @@ translog_size_t translog_read_record(LSN *lsn,
if (data == NULL)
{
DBUG_ASSERT(lsn != NULL);
DBUG_ASSERT(lsn != CONTROL_FILE_IMPOSSIBLE_LSN);
data= &internal_data;
}
if (lsn ||
......@@ -5110,15 +5134,15 @@ translog_size_t translog_read_record(LSN *lsn,
DBUG_RETURN(0);
}
DBUG_PRINT("info", ("Offset %lu, length %lu "
"Scanner: Cur: (%u, 0x%lx), Hrz: (%u, 0x%lx), "
"Lst: (%u, 0x%lx), Offset: %u(%x), fixed %d",
"Scanner: Cur: (%lu,0x%lx), Hrz: (%lu,0x%lx), "
"Lst: (%lu,0x%lx), Offset: %u(%x), fixed %d",
(ulong) offset, (ulong) length,
(uint) data->scanner.page_addr.file_no,
(ulong) data->scanner.page_addr.rec_offset,
(uint) data->scanner.horizon.file_no,
(ulong) data->scanner.horizon.rec_offset,
(uint) data->scanner.last_file_page.file_no,
(ulong) data->scanner.last_file_page.rec_offset,
(ulong) LSN_FILE_NO(data->scanner.page_addr),
(ulong) LSN_OFFSET(data->scanner.page_addr),
(ulong) LSN_FILE_NO(data->scanner.horizon),
(ulong) LSN_OFFSET(data->scanner.horizon),
(ulong) LSN_FILE_NO(data->scanner.last_file_page),
(ulong) LSN_OFFSET(data->scanner.last_file_page),
(uint) data->scanner.page_offset,
(uint) data->scanner.page_offset,
data->scanner.fixed_horizon));
......@@ -5193,7 +5217,7 @@ static void translog_force_current_buffer_to_finish()
uint16 current_page_size;
new_buff_begunning= log_descriptor.bc.buffer->offset;
new_buff_begunning.rec_offset+= log_descriptor.bc.buffer->size;
new_buff_begunning+= log_descriptor.bc.buffer->size; /* increase offset */
DBUG_ENTER("translog_force_current_buffer_to_finish");
DBUG_PRINT("enter", ("Buffer #%u 0x%lx, "
......@@ -5203,13 +5227,13 @@ static void translog_force_current_buffer_to_finish()
"size %lu (%lu), Pg: %u, left: %u",
(uint) log_descriptor.bc.buffer_no,
(ulong) log_descriptor.bc.buffer,
(ulong) log_descriptor.bc.buffer->offset.file_no,
(ulong) log_descriptor.bc.buffer->offset.rec_offset,
(ulong) log_descriptor.horizon.file_no,
(ulong) (log_descriptor.horizon.rec_offset -
(ulong) LSN_FILE_NO(log_descriptor.bc.buffer->offset),
(ulong) LSN_OFFSET(log_descriptor.bc.buffer->offset),
(ulong) LSN_FILE_NO(log_descriptor.horizon),
(ulong) (LSN_OFFSET(log_descriptor.horizon) -
log_descriptor.bc.current_page_size),
(ulong) new_buff_begunning.file_no,
(ulong) new_buff_begunning.rec_offset,
(ulong) LSN_FILE_NO(new_buff_begunning),
(ulong) LSN_OFFSET(new_buff_begunning),
(ulong) log_descriptor.bc.buffer->size,
(ulong) (log_descriptor.bc.ptr -log_descriptor.bc.
buffer->buffer),
......@@ -5219,11 +5243,11 @@ static void translog_force_current_buffer_to_finish()
DBUG_ASSERT((log_descriptor.bc.ptr -log_descriptor.bc.buffer->buffer)
%TRANSLOG_PAGE_SIZE ==
log_descriptor.bc.current_page_size % TRANSLOG_PAGE_SIZE);
DBUG_ASSERT(log_descriptor.horizon.file_no ==
log_descriptor.bc.buffer->offset.file_no);
DBUG_ASSERT(log_descriptor.bc.buffer->offset.rec_offset +
DBUG_ASSERT(LSN_FILE_NO(log_descriptor.horizon) ==
LSN_FILE_NO(log_descriptor.bc.buffer->offset));
DBUG_ASSERT(LSN_OFFSET(log_descriptor.bc.buffer->offset) +
(log_descriptor.bc.ptr -log_descriptor.bc.buffer->buffer) ==
log_descriptor.horizon.rec_offset);
LSN_OFFSET(log_descriptor.horizon));
if (left != TRANSLOG_PAGE_SIZE && left != 0)
{
/*
......@@ -5232,7 +5256,8 @@ static void translog_force_current_buffer_to_finish()
*/
DBUG_PRINT("info", ("left %u", (uint) left));
new_buff_begunning.rec_offset-= log_descriptor.bc.current_page_size;
/* decrease offset */
new_buff_begunning-= log_descriptor.bc.current_page_size;
current_page_size= log_descriptor.bc.current_page_size;
bzero(log_descriptor.bc.ptr, left);
......@@ -5315,7 +5340,7 @@ static void translog_force_current_buffer_to_finish()
1 - Error
*/
my_bool translog_flush(LSN *lsn)
my_bool translog_flush(LSN lsn)
{
LSN old_flushed, sent_to_file;
int rc= 0;
......@@ -5323,8 +5348,9 @@ my_bool translog_flush(LSN *lsn)
my_bool full_circle= 0;
DBUG_ENTER("translog_flush");
DBUG_PRINT("enter", ("Flush up to LSN (%u,0x%lx)",
(uint) lsn->file_no, (ulong) lsn->rec_offset));
DBUG_PRINT("enter", ("Flush up to LSN (%lu,0x%lx)",
(ulong) LSN_FILE_NO(lsn),
(ulong) LSN_OFFSET(lsn)));
translog_lock();
old_flushed= log_descriptor.flushed;
......@@ -5336,18 +5362,18 @@ my_bool translog_flush(LSN *lsn)
struct st_translog_buffer *buffer= log_descriptor.bc.buffer;
/* we can't flush in future */
DBUG_ASSERT(cmp_translog_addr(log_descriptor.horizon, *lsn) >= 0);
if (cmp_translog_addr(log_descriptor.flushed, *lsn) >= 0)
DBUG_ASSERT(cmp_translog_addr(log_descriptor.horizon, lsn) >= 0);
if (cmp_translog_addr(log_descriptor.flushed, lsn) >= 0)
{
DBUG_PRINT("info", ("already flushed (%u,0x%lx)",
(uint) log_descriptor.flushed.file_no,
(ulong) log_descriptor.flushed.rec_offset));
DBUG_PRINT("info", ("already flushed (%lu,0x%lx)",
(ulong) LSN_FILE_NO(log_descriptor.flushed),
(ulong) LSN_OFFSET(log_descriptor.flushed)));
translog_unlock();
DBUG_RETURN(0);
}
/* send to the file if it is not sent */
translog_get_sent_to_file(&sent_to_file);
if (cmp_translog_addr(sent_to_file, *lsn) >= 0)
if (cmp_translog_addr(sent_to_file, lsn) >= 0)
break;
do
......@@ -5369,7 +5395,7 @@ my_bool translog_flush(LSN *lsn)
break;
}
} while ((buffer_start != buffer_no) &&
cmp_translog_addr(log_descriptor.flushed, *lsn) < 0);
cmp_translog_addr(log_descriptor.flushed, lsn) < 0);
if (buffer_unlock != NULL)
translog_buffer_unlock(buffer_unlock);
if (translog_buffer_flush(buffer))
......@@ -5382,12 +5408,13 @@ my_bool translog_flush(LSN *lsn)
translog_lock();
}
for (i= old_flushed.file_no; i <= lsn->file_no; i++)
for (i= LSN_FILE_NO(old_flushed); i <= LSN_FILE_NO(lsn); i++)
{
uint cache_index;
File file;
if ((cache_index= log_descriptor.horizon.file_no - i) < OPENED_FILES_NUM)
if ((cache_index= LSN_FILE_NO(log_descriptor.horizon) - i) <
OPENED_FILES_NUM)
{
/* file in the cache */
if (log_descriptor.log_file_num[cache_index] == 0)
......
......@@ -218,7 +218,7 @@ void translog_destroy();
part of the header
*/
translog_size_t translog_read_record_header(LSN *lsn,
translog_size_t translog_read_record_header(LSN lsn,
TRANSLOG_HEADER_BUFFER *buff);
......@@ -249,7 +249,7 @@ void translog_free_record_header(TRANSLOG_HEADER_BUFFER *buff);
length of data actually read
*/
translog_size_t translog_read_record(LSN *lsn,
translog_size_t translog_read_record(LSN lsn,
translog_size_t offset,
translog_size_t length,
uchar *buffer,
......@@ -269,7 +269,7 @@ translog_size_t translog_read_record(LSN *lsn,
1 - Error
*/
my_bool translog_flush(LSN *lsn);
my_bool translog_flush(LSN lsn);
/*
......@@ -304,7 +304,7 @@ my_bool translog_flush(LSN *lsn);
part of the header
*/
translog_size_t translog_read_next_record_header(LSN *lsn,
translog_size_t translog_read_next_record_header(LSN lsn,
TRANSLOG_HEADER_BUFFER *buff,
my_bool fixed_horizon,
struct
......
......@@ -2,11 +2,7 @@
#define _ma_loghandler_lsn_h
/* Transaction log record address (file_no is int24 on the disk) */
typedef struct st_translog_address
{
uint32 file_no;
uint32 rec_offset;
} TRANSLOG_ADDRESS;
typedef int64 TRANSLOG_ADDRESS;
/*
Compare addresses
......@@ -14,26 +10,39 @@ typedef struct st_translog_address
A1 == A2 -> 0
A1 < A2 -> result < 0
*/
#define cmp_translog_addr(A1,A2) \
((A1).file_no == (A2).file_no ? \
((int64)(A1).rec_offset) - (int64)(A2).rec_offset : \
((int64)(A1).file_no - (int64)(A2).file_no))
#define cmp_translog_addr(A1,A2) ((A1) - (A2))
/* LSN type (address of certain log record chank */
typedef TRANSLOG_ADDRESS LSN;
/* Gets file number part of a LSN/log address */
#define LSN_FILE_NO(L) ((L) >> 32)
/* Gets raw file number part of a LSN/log address */
#define LSN_FINE_NO_PART(L) ((L) & ((int64)0xFFFFFF00000000LL))
/* Gets record offset of a LSN/log address */
#define LSN_OFFSET(L) ((L) & 0xFFFFFFFFL)
/* Makes lsn/log address from file number and record offset */
#define MAKE_LSN(F,S) ((((uint64)(F)) << 32) | (S))
/* checks LSN */
#define LSN_VALID(L) DBUG_ASSERT((L) >= 0 && (L) < (uint64)0xFFFFFFFFFFFFFFLL)
/* Puts LSN into buffer (dst) */
#define lsn7store(dst, lsn) \
do { \
int3store((dst), (lsn)->file_no); \
int4store((dst) + 3, (lsn)->rec_offset); \
int3store((dst), LSN_FILE_NO(lsn)); \
int4store((dst) + 3, LSN_OFFSET(lsn)); \
} while (0)
/* Unpacks LSN from the buffer (P) */
#define lsn7korr(lsn, P) \
do { \
(lsn)->file_no= uint3korr(P); \
(lsn)->rec_offset= uint4korr((P) + 3); \
} while (0)
#define lsn7korr(P) MAKE_LSN(uint3korr(P), uint4korr((P) + 3))
/* what we need to add to LSN to increase it on one file */
#define LSN_ONE_FILE ((int64)0x100000000LL)
#define LSN_REPLACE_OFFSET(L, S) (LSN_FINE_NO_PART(L) | (S))
#endif
......@@ -30,14 +30,15 @@ LDADD= $(top_builddir)/unittest/mytap/libmytap.a \
$(top_builddir)/storage/maria/ma_loghandler.o
noinst_PROGRAMS = ma_control_file-t trnman-t lockman2-t \
mf_pagecache_single_1k-t mf_pagecache_single_8k-t \
mf_pagecache_single_64k-t \
mf_pagecache_consist_1k-t mf_pagecache_consist_64k-t \
mf_pagecache_consist_1kHC-t \
mf_pagecache_consist_64kHC-t \
mf_pagecache_consist_1kRD-t \
mf_pagecache_consist_64kRD-t \
mf_pagecache_consist_1kWR-t \
mf_pagecache_consist_64kWR-t \
mf_pagecache_single_64k-t-big \
mf_pagecache_consist_1k-t-big \
mf_pagecache_consist_64k-t-big \
mf_pagecache_consist_1kHC-t-big \
mf_pagecache_consist_64kHC-t-big \
mf_pagecache_consist_1kRD-t-big \
mf_pagecache_consist_64kRD-t-big \
mf_pagecache_consist_1kWR-t-big \
mf_pagecache_consist_64kWR-t-big \
ma_test_loghandler-t \
ma_test_loghandler_multigroup-t \
ma_test_loghandler_multithread-t \
......@@ -49,34 +50,33 @@ mf_pagecache_common_cppflags = -DEXTRA_DEBUG -DPAGECACHE_DEBUG -DMAIN
mf_pagecache_single_1k_t_SOURCES = $(mf_pagecache_single_src)
mf_pagecache_single_8k_t_SOURCES = $(mf_pagecache_single_src)
mf_pagecache_single_64k_t_SOURCES = $(mf_pagecache_single_src)
mf_pagecache_single_64k_t_big_SOURCES = $(mf_pagecache_single_src)
mf_pagecache_single_1k_t_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=1024
mf_pagecache_single_8k_t_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=8192
mf_pagecache_single_64k_t_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=65536
mf_pagecache_single_64k_t_big_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=65536
mf_pagecache_consist_1k_t_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_1k_t_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=1024
mf_pagecache_consist_64k_t_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_64k_t_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=65536
mf_pagecache_consist_1k_t_big_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_1k_t_big_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=1024
mf_pagecache_consist_64k_t_big_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_64k_t_big_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=65536
mf_pagecache_consist_1kHC_t_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_1kHC_t_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=1024 -DTEST_HIGH_CONCURENCY
mf_pagecache_consist_64kHC_t_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_64kHC_t_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=65536 -DTEST_HIGH_CONCURENCY
mf_pagecache_consist_1kHC_t_big_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_1kHC_t_big_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=1024 -DTEST_HIGH_CONCURENCY
mf_pagecache_consist_64kHC_t_big_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_64kHC_t_big_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=65536 -DTEST_HIGH_CONCURENCY
mf_pagecache_consist_1kRD_t_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_1kRD_t_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=1024 -DTEST_READERS
mf_pagecache_consist_64kRD_t_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_64kRD_t_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=65536 -DTEST_READERS
mf_pagecache_consist_1kRD_t_big_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_1kRD_t_big_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=1024 -DTEST_READERS
mf_pagecache_consist_64kRD_t_big_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_64kRD_t_big_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=65536 -DTEST_READERS
mf_pagecache_consist_1kWR_t_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_1kWR_t_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=1024 -DTEST_WRITERS
mf_pagecache_consist_64kWR_t_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_64kWR_t_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=65536 -DTEST_WRITERS
mf_pagecache_consist_1kWR_t_big_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_1kWR_t_big_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=1024 -DTEST_WRITERS
mf_pagecache_consist_64kWR_t_big_SOURCES = $(mf_pagecache_consist_src)
mf_pagecache_consist_64kWR_t_big_CPPFLAGS = $(mf_pagecache_common_cppflags) -DPAGE_SIZE=65536 -DTEST_WRITERS
# the generic lock manager may not be used in the end and lockman1-t crashes,
# so we don't build lockman-t and lockman1-t
CLEANFILES = maria_control page_cache_test_file_1 \
maria_log.???????? maria_control
noinst_PROGRAMS = ma_control_file-t trnman-t lockman2-t
maria_log.????????
......@@ -133,10 +133,8 @@ static int delete_file(myf my_flags)
static int verify_module_values_match_expected()
{
RET_ERR_UNLESS(last_logno == expect_logno);
RET_ERR_UNLESS(last_checkpoint_lsn.file_no ==
expect_checkpoint_lsn.file_no);
RET_ERR_UNLESS(last_checkpoint_lsn.rec_offset ==
expect_checkpoint_lsn.rec_offset);
RET_ERR_UNLESS(last_checkpoint_lsn ==
expect_checkpoint_lsn);
return 0;
}
......@@ -148,10 +146,8 @@ static int verify_module_values_match_expected()
static int verify_module_values_are_impossible()
{
RET_ERR_UNLESS(last_logno == CONTROL_FILE_IMPOSSIBLE_FILENO);
RET_ERR_UNLESS(last_checkpoint_lsn.file_no ==
CONTROL_FILE_IMPOSSIBLE_FILENO);
RET_ERR_UNLESS(last_checkpoint_lsn.rec_offset ==
CONTROL_FILE_IMPOSSIBLE_LOG_OFFSET);
RET_ERR_UNLESS(last_checkpoint_lsn ==
CONTROL_FILE_IMPOSSIBLE_LSN);
return 0;
}
......@@ -173,9 +169,9 @@ static int create_or_open_file()
return 0;
}
static int write_file(const LSN *checkpoint_lsn,
uint32 logno,
uint objs_to_write)
static int write_file(const LSN checkpoint_lsn,
uint32 logno,
uint objs_to_write)
{
RET_ERR_UNLESS(ma_control_file_write_and_force(checkpoint_lsn, logno,
objs_to_write) == 0);
......@@ -191,8 +187,9 @@ static int test_one_log()
RET_ERR_UNLESS(create_or_open_file() == CONTROL_FILE_OK);
objs_to_write= CONTROL_FILE_UPDATE_ONLY_LOGNO;
expect_logno= 123;
RET_ERR_UNLESS(write_file(NULL, expect_logno,
objs_to_write) == 0);
RET_ERR_UNLESS(write_file(CONTROL_FILE_IMPOSSIBLE_LSN,
expect_logno,
objs_to_write) == 0);
RET_ERR_UNLESS(close_file() == 0);
return 0;
}
......@@ -208,8 +205,8 @@ static int test_five_logs()
for (i= 0; i<5; i++)
{
expect_logno*= 3;
RET_ERR_UNLESS(write_file(NULL, expect_logno,
objs_to_write) == 0);
RET_ERR_UNLESS(write_file(CONTROL_FILE_IMPOSSIBLE_LSN, expect_logno,
objs_to_write) == 0);
}
RET_ERR_UNLESS(close_file() == 0);
return 0;
......@@ -224,29 +221,29 @@ static int test_3_checkpoints_and_2_logs()
*/
RET_ERR_UNLESS(create_or_open_file() == CONTROL_FILE_OK);
objs_to_write= CONTROL_FILE_UPDATE_ONLY_LSN;
expect_checkpoint_lsn= (LSN){5, 10000};
RET_ERR_UNLESS(write_file(&expect_checkpoint_lsn,
expect_logno, objs_to_write) == 0);
expect_checkpoint_lsn= MAKE_LSN(5, 10000);
RET_ERR_UNLESS(write_file(expect_checkpoint_lsn,
expect_logno, objs_to_write) == 0);
objs_to_write= CONTROL_FILE_UPDATE_ONLY_LOGNO;
expect_logno= 17;
RET_ERR_UNLESS(write_file(&expect_checkpoint_lsn,
expect_logno, objs_to_write) == 0);
RET_ERR_UNLESS(write_file(expect_checkpoint_lsn,
expect_logno, objs_to_write) == 0);
objs_to_write= CONTROL_FILE_UPDATE_ONLY_LSN;
expect_checkpoint_lsn= (LSN){17, 20000};
RET_ERR_UNLESS(write_file(&expect_checkpoint_lsn,
expect_logno, objs_to_write) == 0);
expect_checkpoint_lsn= MAKE_LSN(17, 20000);
RET_ERR_UNLESS(write_file(expect_checkpoint_lsn,
expect_logno, objs_to_write) == 0);
objs_to_write= CONTROL_FILE_UPDATE_ONLY_LSN;
expect_checkpoint_lsn= (LSN){17, 45000};
RET_ERR_UNLESS(write_file(&expect_checkpoint_lsn,
expect_logno, objs_to_write) == 0);
expect_checkpoint_lsn= MAKE_LSN(17, 45000);
RET_ERR_UNLESS(write_file(expect_checkpoint_lsn,
expect_logno, objs_to_write) == 0);
objs_to_write= CONTROL_FILE_UPDATE_ONLY_LOGNO;
expect_logno= 19;
RET_ERR_UNLESS(write_file(&expect_checkpoint_lsn,
expect_logno, objs_to_write) == 0);
RET_ERR_UNLESS(write_file(expect_checkpoint_lsn,
expect_logno, objs_to_write) == 0);
RET_ERR_UNLESS(close_file() == 0);
return 0;
}
......@@ -274,9 +271,9 @@ static int test_binary_content()
RET_ERR_UNLESS(my_close(fd, MYF(MY_WME)) == 0);
RET_ERR_UNLESS(create_or_open_file() == CONTROL_FILE_OK);
i= uint4korr(buffer+5);
RET_ERR_UNLESS(i == last_checkpoint_lsn.file_no);
RET_ERR_UNLESS(i == LSN_FILE_NO(last_checkpoint_lsn));
i= uint4korr(buffer+9);
RET_ERR_UNLESS(i == last_checkpoint_lsn.rec_offset);
RET_ERR_UNLESS(i == LSN_OFFSET(last_checkpoint_lsn));
i= uint4korr(buffer+13);
RET_ERR_UNLESS(i == last_logno);
RET_ERR_UNLESS(close_file() == 0);
......
#include "../maria_def.h"
#include <stdio.h>
#include <errno.h>
#include <tap.h>
#ifndef DBUG_OFF
static const char *default_dbug_option;
......@@ -83,7 +84,7 @@ static my_bool read_and_check_content(TRANSLOG_HEADER_BUFFER *rec,
uchar *buffer, uint skip)
{
DBUG_ASSERT(rec->record_length < LONG_BUFFER_SIZE * 2 + 7 * 2 + 2);
if (translog_read_record(&rec->lsn, 0, rec->record_length, buffer, NULL) !=
if (translog_read_record(rec->lsn, 0, rec->record_length, buffer, NULL) !=
rec->record_length)
return 1;
return check_content(buffer + skip, rec->record_length - skip);
......@@ -103,7 +104,7 @@ int main(int argc, char *argv[])
};
uchar long_buffer[LONG_BUFFER_SIZE * 2 + 7 * 2 + 2];
PAGECACHE pagecache;
LSN lsn, lsn_base, first_lsn, *lsn_ptr;
LSN lsn, lsn_base, first_lsn, lsn_ptr;
TRANSLOG_HEADER_BUFFER rec;
struct st_translog_scanner_data scanner;
int rc;
......@@ -172,7 +173,7 @@ int main(int argc, char *argv[])
printf("write %d\n", i);
if (i % 2)
{
lsn7store(lsn_buff, &lsn_base);
lsn7store(lsn_buff, lsn_base);
if (translog_write_record(&lsn,
LOGREC_CLR_END,
(i % 0xFFFF), NULL, 7, lsn_buff, 0))
......@@ -182,7 +183,7 @@ int main(int argc, char *argv[])
translog_destroy();
exit(1);
}
lsn7store(lsn_buff, &lsn_base);
lsn7store(lsn_buff, lsn_base);
if ((rec_len= random() / (RAND_MAX / (LONG_BUFFER_SIZE + 1))) < 12)
rec_len= 12;
if (translog_write_record(&lsn,
......@@ -198,8 +199,8 @@ int main(int argc, char *argv[])
}
else
{
lsn7store(lsn_buff, &lsn_base);
lsn7store(lsn_buff + 7, &first_lsn);
lsn7store(lsn_buff, lsn_base);
lsn7store(lsn_buff + 7, first_lsn);
if (translog_write_record(&lsn,
LOGREC_UNDO_ROW_DELETE,
(i % 0xFFFF), NULL, 23, lsn_buff, 0))
......@@ -209,8 +210,8 @@ int main(int argc, char *argv[])
translog_destroy();
exit(1);
}
lsn7store(lsn_buff, &lsn_base);
lsn7store(lsn_buff + 7, &first_lsn);
lsn7store(lsn_buff, lsn_base);
lsn7store(lsn_buff + 7, first_lsn);
if ((rec_len= random() / (RAND_MAX / (LONG_BUFFER_SIZE + 1))) < 19)
rec_len= 19;
if (translog_write_record(&lsn,
......@@ -246,7 +247,7 @@ int main(int argc, char *argv[])
translog_destroy();
exit(1);
}
if (translog_flush(&lsn))
if (translog_flush(lsn))
{
fprintf(stderr, "Can't flush #%lu\n", (ulong) i);
translog_destroy();
......@@ -282,7 +283,7 @@ int main(int argc, char *argv[])
rc= 1;
{
translog_size_t len= translog_read_record_header(&first_lsn, &rec);
translog_size_t len= translog_read_record_header(first_lsn, &rec);
if (len == 0)
{
fprintf(stderr, "translog_read_record_header failed (%d)\n", errno);
......@@ -291,19 +292,19 @@ int main(int argc, char *argv[])
if (rec.type !=LOGREC_LONG_TRANSACTION_ID || rec.short_trid != 0 ||
rec.record_length != 6 || uint4korr(rec.header) != 0 ||
(uint)rec.header[4] != 0 || rec.header[5] != 0xFF ||
first_lsn.file_no != rec.lsn.file_no ||
first_lsn.rec_offset != rec.lsn.rec_offset)
first_lsn != rec.lsn)
{
fprintf(stderr, "Incorrect LOGREC_LONG_TRANSACTION_ID data read(0)\n"
"type %u, strid %u, len %u, i: %u, 4: %u 5: %u, "
"lsn(0x%lx,0x%lx)\n",
"lsn(%lu,0x%lx)\n",
(uint) rec.type, (uint) rec.short_trid, (uint) rec.record_length,
uint4korr(rec.header), (uint) rec.header[4], (uint) rec.header[5],
(ulong) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(uint) uint4korr(rec.header), (uint) rec.header[4],
(uint) rec.header[5],
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
goto err;
}
lsn= first_lsn;
lsn_ptr= &first_lsn;
lsn_ptr= first_lsn;
for (i= 1;; i++)
{
if (i % 1000 == 0)
......@@ -315,7 +316,7 @@ int main(int argc, char *argv[])
i, errno);
goto err;
}
if (rec.lsn.file_no == CONTROL_FILE_IMPOSSIBLE_FILENO)
if (rec.lsn == CONTROL_FILE_IMPOSSIBLE_LSN)
{
if (i != ITERATIONS)
{
......@@ -325,37 +326,35 @@ int main(int argc, char *argv[])
}
break;
}
lsn_ptr= NULL; /* use scanner after its
initialization */
/* use scanner after its initialization */
lsn_ptr= 0;
if (i % 2)
{
LSN ref;
lsn7korr(&ref, rec.header);
ref= lsn7korr(rec.header);
if (rec.type !=LOGREC_CLR_END || rec.short_trid != (i % 0xFFFF) ||
rec.record_length != 7 || ref.file_no != lsn.file_no ||
ref.rec_offset != lsn.rec_offset)
rec.record_length != 7 || ref != lsn)
{
fprintf(stderr, "Incorrect LOGREC_CLR_END data read(%d)"
"type %u, strid %u, len %u, ref(%u,0x%lx), lsn(%u,0x%lx)\n",
fprintf(stderr, "Incorrect LOGREC_CLR_END data read(%d) "
"type %u, strid %u, len %u, ref(%lu,0x%lx), "
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(uint) rec.record_length,
(uint) ref.file_no, (ulong) ref.rec_offset,
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(ulong) LSN_FILE_NO(ref), (ulong) LSN_OFFSET(ref),
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
goto err;
}
}
else
{
LSN ref1, ref2;
lsn7korr(&ref1, rec.header);
lsn7korr(&ref2, rec.header + 7);
ref1= lsn7korr(rec.header);
ref2= lsn7korr(rec.header + 7);
if (rec.type !=LOGREC_UNDO_ROW_DELETE ||
rec.short_trid != (i % 0xFFFF) ||
rec.record_length != 23 ||
ref1.file_no != lsn.file_no ||
ref1.rec_offset != lsn.rec_offset ||
ref2.file_no != first_lsn.file_no ||
ref2.rec_offset != first_lsn.rec_offset ||
ref1 != lsn ||
ref2 != first_lsn ||
rec.header[22] != 0x55 || rec.header[21] != 0xAA ||
rec.header[20] != 0x55 || rec.header[19] != 0xAA ||
rec.header[18] != 0x55 || rec.header[17] != 0xAA ||
......@@ -363,19 +362,19 @@ int main(int argc, char *argv[])
rec.header[14] != 0x55)
{
fprintf(stderr, "Incorrect LOGREC_UNDO_ROW_DELETE data read(%d)"
"type %u, strid %u, len %u, ref1(%u,0x%lx), "
"ref2(%u,0x%lx) %x%x%x%x%x%x%x%x%x "
"lsn(%u,0x%lx)\n",
"type %u, strid %u, len %u, ref1(%lu,0x%lx), "
"ref2(%lu,0x%lx) %x%x%x%x%x%x%x%x%x "
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(uint) rec.record_length,
(uint) ref1.file_no, (ulong) ref1.rec_offset,
(uint) ref2.file_no, (ulong) ref2.rec_offset,
(ulong) LSN_FILE_NO(ref1), (ulong) LSN_OFFSET(ref1),
(ulong) LSN_FILE_NO(ref2), (ulong) LSN_OFFSET(ref2),
(uint) rec.header[14], (uint) rec.header[15],
(uint) rec.header[16], (uint) rec.header[17],
(uint) rec.header[18], (uint) rec.header[19],
(uint) rec.header[20], (uint) rec.header[21],
(uint) rec.header[22],
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
goto err;
}
}
......@@ -386,7 +385,7 @@ int main(int argc, char *argv[])
"failed (%d)\n", i, errno);
goto err;
}
if (rec.lsn.file_no == CONTROL_FILE_IMPOSSIBLE_FILENO)
if (rec.lsn == CONTROL_FILE_IMPOSSIBLE_LSN)
{
fprintf(stderr, "EOL met at the middle of iteration (first var) %u "
"instead of beginning of %u\n", i, ITERATIONS);
......@@ -395,20 +394,19 @@ int main(int argc, char *argv[])
if (i % 2)
{
LSN ref;
lsn7korr(&ref, rec.header);
ref= lsn7korr(rec.header);
if ((rec_len= random() / (RAND_MAX / (LONG_BUFFER_SIZE + 1))) < 12)
rec_len= 12;
if (rec.type !=LOGREC_UNDO_KEY_INSERT ||
rec.short_trid != (i % 0xFFFF) ||
rec.record_length != rec_len + 7 ||
len != 12 || ref.file_no != lsn.file_no ||
ref.rec_offset != lsn.rec_offset ||
len != 12 || ref != lsn ||
check_content(rec.header + 7, len - 7))
{
fprintf(stderr, "Incorrect LOGREC_UNDO_KEY_INSERT data read(%d)"
"type %u (%d), strid %u (%d), len %lu, %lu + 7 (%d), "
"hdr len: %u (%d), "
"ref(%u,0x%lx), lsn(%u,0x%lx) (%d), content: %d\n",
"ref(%lu,0x%lx), lsn(%lu,0x%lx) (%d), content: %d\n",
i, (uint) rec.type,
rec.type !=LOGREC_UNDO_KEY_INSERT,
(uint) rec.short_trid,
......@@ -417,10 +415,9 @@ int main(int argc, char *argv[])
rec.record_length != rec_len + 7,
(uint) len,
len != 12,
(uint) ref.file_no, (ulong) ref.rec_offset,
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset,
(len != 12 || ref.file_no != lsn.file_no ||
ref.rec_offset != lsn.rec_offset),
(ulong) LSN_FILE_NO(ref), (ulong) LSN_OFFSET(ref),
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn),
(len != 12 || ref != lsn),
check_content(rec.header + 7, len - 7));
goto err;
}
......@@ -428,46 +425,44 @@ int main(int argc, char *argv[])
{
fprintf(stderr,
"Incorrect LOGREC_UNDO_KEY_INSERT in whole rec read "
"lsn(%u,0x%lx)\n",
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
"lsn(%lu,0x%lx)\n",
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
goto err;
}
}
else
{
LSN ref1, ref2;
lsn7korr(&ref1, rec.header);
lsn7korr(&ref2, rec.header + 7);
ref1= lsn7korr(rec.header);
ref2= lsn7korr(rec.header + 7);
if ((rec_len= random() / (RAND_MAX / (LONG_BUFFER_SIZE + 1))) < 19)
rec_len= 19;
if (rec.type !=LOGREC_UNDO_KEY_DELETE ||
rec.short_trid != (i % 0xFFFF) ||
rec.record_length != rec_len + 14 ||
len != 19 ||
ref1.file_no != lsn.file_no ||
ref1.rec_offset != lsn.rec_offset ||
ref2.file_no != first_lsn.file_no ||
ref2.rec_offset != first_lsn.rec_offset ||
ref1 != lsn ||
ref2 != first_lsn ||
check_content(rec.header + 14, len - 14))
{
fprintf(stderr, "Incorrect LOGREC_UNDO_KEY_DELETE data read(%d)"
"type %u, strid %u, len %lu != %lu + 7, hdr len: %u, "
"ref1(%u,0x%lx), ref2(%u,0x%lx), "
"lsn(%u,0x%lx)\n",
"ref1(%lu,0x%lx), ref2(%lu,0x%lx), "
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(ulong) rec.record_length, (ulong) rec_len,
(uint) len,
(uint) ref1.file_no, (ulong) ref1.rec_offset,
(uint) ref2.file_no, (ulong) ref2.rec_offset,
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(ulong) LSN_FILE_NO(ref1), (ulong) LSN_OFFSET(ref1),
(ulong) LSN_FILE_NO(ref2), (ulong) LSN_OFFSET(ref2),
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
goto err;
}
if (read_and_check_content(&rec, long_buffer, 14))
{
fprintf(stderr,
"Incorrect LOGREC_UNDO_KEY_DELETE in whole rec read "
"lsn(%u,0x%lx)\n",
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
"lsn(%lu,0x%lx)\n",
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
goto err;
}
}
......@@ -479,7 +474,7 @@ int main(int argc, char *argv[])
i, errno);
goto err;
}
if (rec.lsn.file_no == CONTROL_FILE_IMPOSSIBLE_FILENO)
if (rec.lsn == CONTROL_FILE_IMPOSSIBLE_LSN)
{
fprintf(stderr, "EOL met at the middle of iteration %u "
"instead of beginning of %u\n", i, ITERATIONS);
......@@ -492,12 +487,12 @@ int main(int argc, char *argv[])
{
fprintf(stderr, "Incorrect LOGREC_LONG_TRANSACTION_ID data read(%d)\n"
"type %u, strid %u, len %u, i: %u, 4: %u 5: %u "
"lsn(%u,0x%lx)\n",
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(uint) rec.record_length,
uint4korr(rec.header), (uint) rec.header[4],
(uint) uint4korr(rec.header), (uint) rec.header[4],
(uint) rec.header[5],
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
goto err;
}
......@@ -513,18 +508,19 @@ int main(int argc, char *argv[])
{
fprintf(stderr, "Incorrect LOGREC_REDO_INSERT_ROW_HEAD data read(%d)"
"type %u, strid %u, len %lu != %lu, hdr len: %u, "
"lsn(%u,0x%lx)\n",
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(ulong) rec.record_length, (ulong) rec_len,
(uint) len, (uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(uint) len,
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
goto err;
}
if (read_and_check_content(&rec, long_buffer, 0))
{
fprintf(stderr,
"Incorrect LOGREC_UNDO_KEY_DELETE in whole rec read "
"lsn(%u,0x%lx)\n",
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
"lsn(%lu,0x%lx)\n",
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
goto err;
}
}
......
#include "../maria_def.h"
#include <stdio.h>
#include <errno.h>
#include <tap.h>
#ifndef DBUG_OFF
static const char *default_dbug_option;
......@@ -84,7 +85,7 @@ static my_bool read_and_check_content(TRANSLOG_HEADER_BUFFER *rec,
translog_size_t len;
DBUG_ENTER("read_and_check_content");
DBUG_ASSERT(rec->record_length < LONG_BUFFER_SIZE + 7 * 2 + 2);
if ((len= translog_read_record(&rec->lsn, 0, rec->record_length,
if ((len= translog_read_record(rec->lsn, 0, rec->record_length,
buffer, NULL)) != rec->record_length)
{
fprintf(stderr, "Requested %lu byte, read %lu\n",
......@@ -121,7 +122,7 @@ int main(int argc, char *argv[])
};
uchar *long_buffer= malloc(LONG_BUFFER_SIZE + 7 * 2 + 2);
PAGECACHE pagecache;
LSN lsn, lsn_base, first_lsn, *lsn_ptr;
LSN lsn, lsn_base, first_lsn, lsn_ptr;
TRANSLOG_HEADER_BUFFER rec;
struct st_translog_scanner_data scanner;
int rc;
......@@ -194,7 +195,7 @@ int main(int argc, char *argv[])
printf("write %d\n", i);
if (i % 2)
{
lsn7store(lsn_buff, &lsn_base);
lsn7store(lsn_buff, lsn_base);
if (translog_write_record(&lsn,
LOGREC_CLR_END,
(i % 0xFFFF), NULL, 7, lsn_buff, 0))
......@@ -204,7 +205,7 @@ int main(int argc, char *argv[])
translog_destroy();
exit(1);
}
lsn7store(lsn_buff, &lsn_base);
lsn7store(lsn_buff, lsn_base);
rec_len= get_len();
if (translog_write_record(&lsn,
LOGREC_UNDO_KEY_INSERT,
......@@ -219,8 +220,8 @@ int main(int argc, char *argv[])
}
else
{
lsn7store(lsn_buff, &lsn_base);
lsn7store(lsn_buff + 7, &first_lsn);
lsn7store(lsn_buff, lsn_base);
lsn7store(lsn_buff + 7, first_lsn);
if (translog_write_record(&lsn,
LOGREC_UNDO_ROW_DELETE,
(i % 0xFFFF), NULL, 23, lsn_buff, 0))
......@@ -230,8 +231,8 @@ int main(int argc, char *argv[])
translog_destroy();
exit(1);
}
lsn7store(lsn_buff, &lsn_base);
lsn7store(lsn_buff + 7, &first_lsn);
lsn7store(lsn_buff, lsn_base);
lsn7store(lsn_buff + 7, first_lsn);
rec_len= get_len();
if (translog_write_record(&lsn,
LOGREC_UNDO_KEY_DELETE,
......@@ -294,7 +295,7 @@ int main(int argc, char *argv[])
rc= 1;
{
translog_size_t len= translog_read_record_header(&first_lsn, &rec);
translog_size_t len= translog_read_record_header(first_lsn, &rec);
if (len == 0)
{
fprintf(stderr, "translog_read_record_header failed (%d)\n", errno);
......@@ -304,21 +305,21 @@ int main(int argc, char *argv[])
if (rec.type !=LOGREC_LONG_TRANSACTION_ID || rec.short_trid != 0 ||
rec.record_length != 6 || uint4korr(rec.header) != 0 ||
(uint)rec.header[4] != 0 || rec.header[5] != 0xFF ||
first_lsn.file_no != rec.lsn.file_no ||
first_lsn.rec_offset != rec.lsn.rec_offset)
first_lsn != rec.lsn)
{
fprintf(stderr, "Incorrect LOGREC_LONG_TRANSACTION_ID data read(0)\n"
"type %u, strid %u, len %u, i: %u, 4: %u 5: %u, "
"lsn(0x%lx,0x%lx)\n",
"lsn(0x%lu,0x%lx)\n",
(uint) rec.type, (uint) rec.short_trid, (uint) rec.record_length,
uint4korr(rec.header), (uint) rec.header[4], (uint) rec.header[5],
(ulong) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(uint)uint4korr(rec.header), (uint) rec.header[4],
(uint) rec.header[5],
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
translog_free_record_header(&rec);
goto err;
}
translog_free_record_header(&rec);
lsn= first_lsn;
lsn_ptr= &first_lsn;
lsn_ptr= first_lsn;
for (i= 1;; i++)
{
if (i % SHOW_DIVIDER == 0)
......@@ -331,7 +332,7 @@ int main(int argc, char *argv[])
translog_free_record_header(&rec);
goto err;
}
if (rec.lsn.file_no == CONTROL_FILE_IMPOSSIBLE_FILENO)
if (rec.lsn == CONTROL_FILE_IMPOSSIBLE_LSN)
{
if (i != ITERATIONS)
{
......@@ -342,23 +343,22 @@ int main(int argc, char *argv[])
}
break;
}
lsn_ptr= NULL; /* use scanner after its
initialization */
/* use scanner after its initialization */
lsn_ptr= 0;
if (i % 2)
{
LSN ref;
lsn7korr(&ref, rec.header);
if (rec.type !=LOGREC_CLR_END || rec.short_trid != (i % 0xFFFF) ||
rec.record_length != 7 || ref.file_no != lsn.file_no ||
ref.rec_offset != lsn.rec_offset)
ref= lsn7korr(rec.header);
if (rec.type != LOGREC_CLR_END || rec.short_trid != (i % 0xFFFF) ||
rec.record_length != 7 || ref != lsn)
{
fprintf(stderr, "Incorrect LOGREC_CLR_END data read(%d)"
"type %u, strid %u, len %u, ref(%u,0x%lx), lsn(%u,0x%lx)\n",
"type %u, strid %u, len %u, ref(%lu,0x%lx), lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(uint) rec.record_length,
(uint) ref.file_no, (ulong) ref.rec_offset,
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(ulong) LSN_FILE_NO(ref), (ulong) LSN_OFFSET(ref),
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
translog_free_record_header(&rec);
goto err;
}
......@@ -366,15 +366,13 @@ int main(int argc, char *argv[])
else
{
LSN ref1, ref2;
lsn7korr(&ref1, rec.header);
lsn7korr(&ref2, rec.header + 7);
ref1= lsn7korr(rec.header);
ref2= lsn7korr(rec.header + 7);
if (rec.type !=LOGREC_UNDO_ROW_DELETE ||
rec.short_trid != (i % 0xFFFF) ||
rec.record_length != 23 ||
ref1.file_no != lsn.file_no ||
ref1.rec_offset != lsn.rec_offset ||
ref2.file_no != first_lsn.file_no ||
ref2.rec_offset != first_lsn.rec_offset ||
ref1 != lsn ||
ref2 != first_lsn ||
rec.header[22] != 0x55 || rec.header[21] != 0xAA ||
rec.header[20] != 0x55 || rec.header[19] != 0xAA ||
rec.header[18] != 0x55 || rec.header[17] != 0xAA ||
......@@ -382,19 +380,19 @@ int main(int argc, char *argv[])
rec.header[14] != 0x55)
{
fprintf(stderr, "Incorrect LOGREC_UNDO_ROW_DELETE data read(%d)"
"type %u, strid %u, len %u, ref1(%u,0x%lx), "
"ref2(%u,0x%lx) %x%x%x%x%x%x%x%x%x "
"lsn(%u,0x%lx)\n",
"type %u, strid %u, len %u, ref1(%lu,0x%lx), "
"ref2(%lu,0x%lx) %x%x%x%x%x%x%x%x%x "
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(uint) rec.record_length,
(uint) ref1.file_no, (ulong) ref1.rec_offset,
(uint) ref2.file_no, (ulong) ref2.rec_offset,
(ulong) LSN_FILE_NO(ref1), (ulong) LSN_OFFSET(ref1),
(ulong) LSN_FILE_NO(ref2), (ulong) LSN_OFFSET(ref2),
(uint) rec.header[14], (uint) rec.header[15],
(uint) rec.header[16], (uint) rec.header[17],
(uint) rec.header[18], (uint) rec.header[19],
(uint) rec.header[20], (uint) rec.header[21],
(uint) rec.header[22],
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
translog_free_record_header(&rec);
goto err;
}
......@@ -408,7 +406,7 @@ int main(int argc, char *argv[])
"failed (%d)\n", i, errno);
goto err;
}
if (rec.lsn.file_no == CONTROL_FILE_IMPOSSIBLE_FILENO)
if (rec.lsn == CONTROL_FILE_IMPOSSIBLE_LSN)
{
fprintf(stderr, "EOL met at the middle of iteration (first var) %u "
"instead of beginning of %u\n", i, ITERATIONS);
......@@ -417,19 +415,18 @@ int main(int argc, char *argv[])
if (i % 2)
{
LSN ref;
lsn7korr(&ref, rec.header);
ref= lsn7korr(rec.header);
rec_len= get_len();
if (rec.type !=LOGREC_UNDO_KEY_INSERT ||
rec.short_trid != (i % 0xFFFF) ||
rec.record_length != rec_len + 7 ||
len != 12 || ref.file_no != lsn.file_no ||
ref.rec_offset != lsn.rec_offset ||
len != 12 || ref != lsn ||
check_content(rec.header + 7, len - 7))
{
fprintf(stderr, "Incorrect LOGREC_UNDO_KEY_INSERT data read(%d)"
"type %u (%d), strid %u (%d), len %lu, %lu + 7 (%d), "
"hdr len: %u (%d), "
"ref(%u,0x%lx), lsn(%u,0x%lx) (%d), content: %d\n",
"ref(%lu,0x%lx), lsn(%lu,0x%lx) (%d), content: %d\n",
i, (uint) rec.type,
rec.type !=LOGREC_UNDO_KEY_INSERT,
(uint) rec.short_trid,
......@@ -438,10 +435,9 @@ int main(int argc, char *argv[])
rec.record_length != rec_len + 7,
(uint) len,
len != 12,
(uint) ref.file_no, (ulong) ref.rec_offset,
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset,
(ref.file_no != lsn.file_no ||
ref.rec_offset != lsn.rec_offset),
(ulong) LSN_FILE_NO(ref), (ulong) LSN_OFFSET(ref),
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn),
(ref != lsn),
check_content(rec.header + 7, len - 7));
translog_free_record_header(&rec);
goto err;
......@@ -450,8 +446,8 @@ int main(int argc, char *argv[])
{
fprintf(stderr,
"Incorrect LOGREC_UNDO_KEY_INSERT in whole rec read "
"lsn(%u,0x%lx)\n",
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
"lsn(%lu,0x%lx)\n",
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
translog_free_record_header(&rec);
goto err;
}
......@@ -459,29 +455,27 @@ int main(int argc, char *argv[])
else
{
LSN ref1, ref2;
lsn7korr(&ref1, rec.header);
lsn7korr(&ref2, rec.header + 7);
ref1= lsn7korr(rec.header);
ref2= lsn7korr(rec.header + 7);
rec_len= get_len();
if (rec.type !=LOGREC_UNDO_KEY_DELETE ||
rec.short_trid != (i % 0xFFFF) ||
rec.record_length != rec_len + 14 ||
len != 19 ||
ref1.file_no != lsn.file_no ||
ref1.rec_offset != lsn.rec_offset ||
ref2.file_no != first_lsn.file_no ||
ref2.rec_offset != first_lsn.rec_offset ||
ref1 != lsn ||
ref2 != first_lsn ||
check_content(rec.header + 14, len - 14))
{
fprintf(stderr, "Incorrect LOGREC_UNDO_KEY_DELETE data read(%d)"
"type %u, strid %u, len %lu != %lu + 7, hdr len: %u, "
"ref1(%u,0x%lx), ref2(%u,0x%lx), "
"lsn(%u,0x%lx)\n",
"ref1(%lu,0x%lx), ref2(%lu,0x%lx), "
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(ulong) rec.record_length, (ulong) rec_len,
(uint) len,
(uint) ref1.file_no, (ulong) ref1.rec_offset,
(uint) ref2.file_no, (ulong) ref2.rec_offset,
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(ulong) LSN_FILE_NO(ref1), (ulong) LSN_OFFSET(ref1),
(ulong) LSN_FILE_NO(ref2), (ulong) LSN_OFFSET(ref2),
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
translog_free_record_header(&rec);
goto err;
}
......@@ -489,8 +483,8 @@ int main(int argc, char *argv[])
{
fprintf(stderr,
"Incorrect LOGREC_UNDO_KEY_DELETE in whole rec read "
"lsn(%u,0x%lx)\n",
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
"lsn(%lu,0x%lx)\n",
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
translog_free_record_header(&rec);
goto err;
}
......@@ -505,7 +499,7 @@ int main(int argc, char *argv[])
translog_free_record_header(&rec);
goto err;
}
if (rec.lsn.file_no == CONTROL_FILE_IMPOSSIBLE_FILENO)
if (rec.lsn == CONTROL_FILE_IMPOSSIBLE_LSN)
{
fprintf(stderr, "EOL met at the middle of iteration %u "
"instead of beginning of %u\n", i, ITERATIONS);
......@@ -519,12 +513,12 @@ int main(int argc, char *argv[])
{
fprintf(stderr, "Incorrect LOGREC_LONG_TRANSACTION_ID data read(%d)\n"
"type %u, strid %u, len %u, i: %u, 4: %u 5: %u "
"lsn(%u,0x%lx)\n",
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(uint) rec.record_length,
uint4korr(rec.header), (uint) rec.header[4],
(uint)uint4korr(rec.header), (uint) rec.header[4],
(uint) rec.header[5],
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
translog_free_record_header(&rec);
goto err;
}
......@@ -541,10 +535,11 @@ int main(int argc, char *argv[])
{
fprintf(stderr, "Incorrect LOGREC_REDO_INSERT_ROW_HEAD data read(%d)"
"type %u, strid %u, len %lu != %lu, hdr len: %u, "
"lsn(%u,0x%lx)\n",
"lsn(%lu,0x%lx)\n",
i, (uint) rec.type, (uint) rec.short_trid,
(ulong) rec.record_length, (ulong) rec_len,
(uint) len, (uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
(uint) len,
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
translog_free_record_header(&rec);
goto err;
}
......@@ -552,8 +547,8 @@ int main(int argc, char *argv[])
{
fprintf(stderr,
"Incorrect LOGREC_UNDO_KEY_DELETE in whole rec read "
"lsn(%u,0x%lx)\n",
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
"lsn(%lu,0x%lx)\n",
(ulong) LSN_FILE_NO(rec.lsn), (ulong) LSN_OFFSET(rec.lsn));
translog_free_record_header(&rec);
goto err;
}
......
#include "../maria_def.h"
#include <stdio.h>
#include <errno.h>
#include <tap.h>
#ifndef DBUG_OFF
static const char *default_dbug_option;
......@@ -102,7 +103,7 @@ static my_bool read_and_check_content(TRANSLOG_HEADER_BUFFER *rec,
translog_size_t len;
DBUG_ENTER("read_and_check_content");
DBUG_ASSERT(rec->record_length < LONG_BUFFER_SIZE + 7 * 2 + 2);
if ((len= translog_read_record(&rec->lsn, 0, rec->record_length,
if ((len= translog_read_record(rec->lsn, 0, rec->record_length,
buffer, NULL)) != rec->record_length)
{
fprintf(stderr, "Requested %lu byte, read %lu\n",
......@@ -149,16 +150,17 @@ void writer(int num)
DBUG_PRINT("info", ("thread: %u, iteration: %u, len: %lu, "
"lsn1 (%lu,0x%lx) lsn2 (%lu,0x%lx)",
num, i, (ulong) lens[num][i],
(ulong) lsns1[num][i].file_no,
(ulong) lsns1[num][i].rec_offset,
(ulong) lsns2[num][i].file_no,
(ulong) lsns2[num][i].rec_offset));
(ulong) LSN_FILE_NO(lsns1[num][i]),
(ulong) LSN_OFFSET(lsns1[num][i]),
(ulong) LSN_FILE_NO(lsns2[num][i]),
(ulong) LSN_OFFSET(lsns2[num][i])));
printf("thread: %u, iteration: %u, len: %lu, "
"lsn1 (%lu,0x%lx) lsn2 (%lu,0x%lx)\n",
num, i, (ulong) lens[num][i],
(ulong) lsns1[num][i].file_no,
(ulong) lsns1[num][i].rec_offset,
(ulong) lsns2[num][i].file_no, (ulong) lsns2[num][i].rec_offset);
(ulong) LSN_FILE_NO(lsns1[num][i]),
(ulong) LSN_OFFSET(lsns1[num][i]),
(ulong) LSN_FILE_NO(lsns2[num][i]),
(ulong) LSN_OFFSET(lsns2[num][i]));
}
DBUG_VOID_RETURN;
}
......@@ -191,7 +193,7 @@ int main(int argc, char **argv __attribute__ ((unused)))
uint32 i;
uint pagen;
PAGECACHE pagecache;
LSN first_lsn, *lsn_ptr;
LSN first_lsn, lsn_ptr;
TRANSLOG_HEADER_BUFFER rec;
struct st_translog_scanner_data scanner;
pthread_t tid;
......@@ -344,20 +346,18 @@ int main(int argc, char **argv __attribute__ ((unused)))
/* Find last LSN and flush up to it (all our log) */
{
LSN max=
{
0, 0
};
LSN max= 0;
for (i= 0; i < WRITERS; i++)
{
if (cmp_translog_addr(lsns2[i][ITERATIONS - 1], max) > 0)
max= lsns2[i][ITERATIONS - 1];
}
DBUG_PRINT("info", ("first lsn: (%lu,0x%lx), max lsn: (%lu,0x%lx)",
(ulong) first_lsn.file_no,
(ulong) first_lsn.rec_offset,
(ulong) max.file_no, (ulong) max.rec_offset));
translog_flush(&max);
(ulong) LSN_FILE_NO(first_lsn),
(ulong) LSN_OFFSET(first_lsn),
(ulong) LSN_FILE_NO(max),
(ulong) LSN_OFFSET(max)));
translog_flush(max);
}
rc= 1;
......@@ -369,11 +369,11 @@ int main(int argc, char **argv __attribute__ ((unused)))
bzero(indeces, sizeof(indeces));
lsn_ptr= &first_lsn;
lsn_ptr= first_lsn;
for (i= 0;; i++)
{
len= translog_read_next_record_header(lsn_ptr, &rec, 1, &scanner);
lsn_ptr= NULL;
lsn_ptr= 0;
if (len == 0)
{
......@@ -382,7 +382,7 @@ int main(int argc, char **argv __attribute__ ((unused)))
translog_free_record_header(&rec);
goto err;
}
if (rec.lsn.file_no == CONTROL_FILE_IMPOSSIBLE_FILENO)
if (rec.lsn == CONTROL_FILE_IMPOSSIBLE_LSN)
{
if (i != WRITERS * ITERATIONS * 2)
{
......@@ -412,9 +412,10 @@ int main(int argc, char **argv __attribute__ ((unused)))
(uint) rec.short_trid, (uint) uint2korr(rec.header),
(uint) rec.record_length,
(uint) index, (uint) uint4korr(rec.header + 2),
(ulong) rec.lsn.file_no, (ulong) rec.lsn.rec_offset,
(ulong) lsns1[rec.short_trid][index].file_no,
(ulong) lsns1[rec.short_trid][index].rec_offset);
(ulong) LSN_FILE_NO(rec.lsn),
(ulong) LSN_OFFSET(rec.lsn),
(ulong) LSN_FILE_NO(lsns1[rec.short_trid][index]),
(ulong) LSN_OFFSET(lsns1[rec.short_trid][index]));
translog_free_record_header(&rec);
goto err;
}
......@@ -437,9 +438,10 @@ int main(int argc, char **argv __attribute__ ((unused)))
(uint) len,
(ulong) rec.record_length, lens[rec.short_trid][index],
(rec.record_length != lens[rec.short_trid][index]),
(ulong) rec.lsn.file_no, (ulong) rec.lsn.rec_offset,
(ulong) lsns2[rec.short_trid][index].file_no,
(ulong) lsns2[rec.short_trid][index].rec_offset);
(ulong) LSN_FILE_NO(rec.lsn),
(ulong) LSN_OFFSET(rec.lsn),
(ulong) LSN_FILE_NO(lsns2[rec.short_trid][index]),
(ulong) LSN_OFFSET(lsns2[rec.short_trid][index]));
translog_free_record_header(&rec);
goto err;
}
......@@ -447,8 +449,9 @@ int main(int argc, char **argv __attribute__ ((unused)))
{
fprintf(stderr,
"Incorrect LOGREC_REDO_INSERT_ROW_HEAD in whole rec read "
"lsn(%u,0x%lx)\n",
(uint) rec.lsn.file_no, (ulong) rec.lsn.rec_offset);
"lsn(%lu,0x%lx)\n",
(ulong) LSN_FILE_NO(rec.lsn),
(ulong) LSN_OFFSET(rec.lsn));
translog_free_record_header(&rec);
goto err;
}
......
#include "../maria_def.h"
#include <stdio.h>
#include <errno.h>
#include <tap.h>
#ifndef DBUG_OFF
static const char *default_dbug_option;
......@@ -106,7 +107,7 @@ int main(int argc, char *argv[])
bzero(page, PCACHE_PAGE);
#define PAGE_LSN_OFFSET 0
lsn7store(page + PAGE_LSN_OFFSET, &lsn);
lsn7store(page + PAGE_LSN_OFFSET, lsn);
pagecache_write(&pagecache, &file1, 0, 3, (char*)page,
PAGECACHE_LSN_PAGE,
PAGECACHE_LOCK_LEFT_UNLOCKED,
......
......@@ -8,6 +8,7 @@
#include <my_sys.h>
#include <m_string.h>
#include "test_file.h"
#include <tap.h>
#define PCACHE_SIZE (PAGE_SIZE*1024*8)
......
......@@ -7,6 +7,7 @@
#include <my_sys.h>
#include <m_string.h>
#include "test_file.h"
#include <tap.h>
#define PCACHE_SIZE (PAGE_SIZE*1024*10)
......@@ -235,7 +236,7 @@ int simple_pin_test()
0,
PAGECACHE_LOCK_READ_UNLOCK,
PAGECACHE_UNPIN,
0, 0);
0);
if (flush_pagecache_blocks(&pagecache, &file1, FLUSH_FORCE_WRITE))
{
diag("Got error in flush_pagecache_blocks\n");
......@@ -364,7 +365,7 @@ int simple_big_test()
0);
}
desc[i].length= 0;
desc[i].content= NULL;
desc[i].content= '\0';
ok(1, "Simple big file write");
/* check written pages sequentally read */
for (i= 0; i < PCACHE_SIZE/(PAGE_SIZE/2); i++)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment