mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 13:32:33 +01:00
8f39541e7d
Added logging and pinning of pages to block format. Integration of transaction manager, log handler. Better page cache intergration Split trnman.h into two files, so that we don't have to include my_atomic.h into C++ programs. Renaming of structures, more comments, more debugging etc. Fixed problem with small head block + long varchar. Added extra argument to delete_record() and update_record() (needed for UNDO logging) Small changes to interface of pagecache and log handler. Change initialization of log_record_type_descriptors to not be depending on enum order. Use array of LEX_STRING's to send data to log handler Added 'dummy' transaction option to MARIA_INFO so that we can always assume 'trn' exists. include/lf.h: Interface fixes Rename of structures (Patch from Sergei via Sanja) include/my_atomic.h: More comments include/my_global.h: Added MY_ERRPTR include/pagecache.h: Added undo LSN when unlocking pages mysql-test/r/maria.result: Updated results mysql-test/t/maria.test: Added autocommit around lock tables (Patch from Sanja) mysys/lf_alloc-pin.c: Post-review fixes, simple optimizations More comments Struct slot renames Check amount of memory on stack (Patch from Sergei) mysys/lf_dynarray.c: More comments mysys/lf_hash.c: More comments After review fixes (Patch from Sergei) storage/maria/ha_maria.cc: Split trnman.h into two files, so that we don't have to include my_atomic.h into the .cc program. (Temporary fix to avoid bug in gcc) Move out all deferencing of the transaction structure. Transaction manager integrated (Patch from Sergei) storage/maria/ha_maria.h: Added prototype for start_stmt() storage/maria/lockman.c: Function call rename storage/maria/ma_bitmap.c: Mark deleted pages free from page cache storage/maria/ma_blockrec.c: Offset -> rownr More debugging Fixed problem with small head block + long varchar Added logging of changed pages Added logging of undo (Including only loggging of changed fields in case of update) Added pinning/unpinning of all changed pages More comments Added free_full_pages() as the same code was used in several places. fill_rows_parts() renamed as fill_insert_undo_parts() offset -> rownr Added some optimization of not transactional tables _ma_update_block_record() has new parameter, as we need original row to do efficent undo for update storage/maria/ma_blockrec.h: Added ROW_EXTENTS_ON_STACK Changed prototype for update and delete of row storage/maria/ma_check.c: Added original row to delete_record() call storage/maria/ma_control_file.h: Added ifdefs for C++ storage/maria/ma_delete.c: Added original row to delete_record() call (Needed for efficent undo logging) storage/maria/ma_dynrec.c: Added extra argument to delete_record() and update_record() Removed not used variable storage/maria/ma_init.c: Initialize log handler storage/maria/ma_loghandler.c: Removed not used variable Change initialization of log_record_type_descriptors to not be depending on enum order Use array of LEX_STRING's to send data to log handler storage/maria/ma_loghandler.h: New defines Use array of LEX_STRING's to send data to log handler storage/maria/ma_open.c: Added 'dummy' transaction option to MARIA_INFO so that we can always assume 'trn' exists. Store in MARIA_SHARE->page_type if pages will have up to date LSN's storage/maria/ma_pagecache.c: Don't decrease number of readers when using pagecache_write()/pagecache_read() In pagecache_write() decrement request count if page was left pinned Added pagecache_delete_pages() Removed some casts Make trace output consistent with rest of code Simplify calling of DBUG_ASSERT(0) Only update LSN if the LSN is bigger than what's already on the page Added LSN parameter pagecache_unpin_page(), pagecache_unpin(), and pagecache_unlock() (Part of patch from Sanja) storage/maria/ma_static.c: Added 'dummy' transaction option to MARIA_INFO so that we can always assume 'trn' exists. Added default page cache storage/maria/ma_statrec.c: Added extra argument to delete_record() and update_record() storage/maria/ma_test1.c: Added option -T for transactions storage/maria/ma_test2.c: Added option -T for transactions storage/maria/ma_test_all.sh: Test with transactions storage/maria/ma_update.c: Changed prototype for update of row storage/maria/maria_def.h: Changed prototype for update & delete of row as block records need to access the old row Store in MARIA_SHARE->page_type if pages will have up to date LSN's Added MARIA_MAX_TREE_LEVELS to allow us to calculate the number of possible pinned pages we may need. Removed not used 'empty_bits_buffer' Added pointer to transaction object Added array for pinned pages Added log_row_parts array for logging of field data. Added MARIA_PINNED_PAGE to store pinned pages storage/maria/trnman.c: Added accessor functions to transaction object Added missing DBUG_RETURN() More debugging More comments Changed // comment of code to #ifdef NOT_USED Transaction manager integrated. Post review fixes Part of patch originally from Sergei storage/maria/trnman.h: Split trnman.h into two files, so that we don't have to include my_atomic.h into the .cc program. (Temporary fix to avoid bug in gcc) storage/maria/unittest/ma_pagecache_single.c: Added missing argument Added SKIP_BIG_TESTS (Patch from Sanja) storage/maria/unittest/ma_test_loghandler-t.c: Test logging with new LEX_STRING parameter (Patch from Sanja) storage/maria/unittest/ma_test_loghandler_multigroup-t.c: Test logging with new LEX_STRING parameter (Patch from Sanja) storage/maria/unittest/ma_test_loghandler_multithread-t.c: Test logging with new LEX_STRING parameter (Patch from Sanja) storage/maria/unittest/ma_test_loghandler_pagecache-t.c: Test logging with new LEX_STRING parameter (Patch from Sanja) storage/maria/unittest/trnman-t.c: Stack overflow detection (Patch from Sergei) unittest/unit.pl: Command-line options --big and --verbose (Patch from Sergei) unittest/mytap/tap.c: Detect --big (Patch from Sergei) unittest/mytap/tap.h: Skip_big_tests and SKIP_BIG_TESTS (Patch from Sergei) storage/maria/trnman_public.h: New BitKeeper file ``storage/maria/trnman_public.h''
194 lines
4.9 KiB
C
194 lines
4.9 KiB
C
/* Copyright (C) 2006 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
#include <tap.h>
|
|
|
|
#include <my_global.h>
|
|
#include <my_sys.h>
|
|
#include <my_atomic.h>
|
|
#include <lf.h>
|
|
#include <m_string.h>
|
|
#include "../trnman.h"
|
|
|
|
pthread_mutex_t rt_mutex;
|
|
pthread_attr_t attr;
|
|
size_t stacksize= 0;
|
|
#define STACK_SIZE (((int)stacksize-2048)*STACK_DIRECTION)
|
|
|
|
int rt_num_threads;
|
|
int litmus;
|
|
|
|
/*
|
|
create and end (commit or rollback) transactions randomly
|
|
*/
|
|
#define MAX_ITER 100
|
|
pthread_handler_t test_trnman(void *arg)
|
|
{
|
|
uint x, y, i, n;
|
|
TRN *trn[MAX_ITER];
|
|
pthread_mutex_t mutexes[MAX_ITER];
|
|
pthread_cond_t conds[MAX_ITER];
|
|
int m= (*(int *)arg);
|
|
|
|
for (i= 0; i < MAX_ITER; i++)
|
|
{
|
|
pthread_mutex_init(&mutexes[i], MY_MUTEX_INIT_FAST);
|
|
pthread_cond_init(&conds[i], 0);
|
|
}
|
|
|
|
for (x= ((int)(intptr)(&m)); m > 0; )
|
|
{
|
|
y= x= (x*LL(3628273133) + LL(1500450271)) % LL(9576890767); /* three prime numbers */
|
|
m-= n= x % MAX_ITER;
|
|
for (i= 0; i < n; i++)
|
|
{
|
|
trn[i]= trnman_new_trn(&mutexes[i], &conds[i], &m + STACK_SIZE);
|
|
if (!trn[i])
|
|
{
|
|
diag("trnman_new_trn() failed");
|
|
litmus++;
|
|
}
|
|
}
|
|
for (i= 0; i < n; i++)
|
|
{
|
|
y= (y*19 + 7) % 31;
|
|
trnman_end_trn(trn[i], y & 1);
|
|
}
|
|
}
|
|
for (i= 0; i < MAX_ITER; i++)
|
|
{
|
|
pthread_mutex_destroy(&mutexes[i]);
|
|
pthread_cond_destroy(&conds[i]);
|
|
}
|
|
pthread_mutex_lock(&rt_mutex);
|
|
rt_num_threads--;
|
|
pthread_mutex_unlock(&rt_mutex);
|
|
|
|
return 0;
|
|
}
|
|
#undef MAX_ITER
|
|
|
|
void run_test(const char *test, pthread_handler handler, int n, int m)
|
|
{
|
|
pthread_t *threads;
|
|
ulonglong now= my_getsystime();
|
|
int i;
|
|
|
|
litmus= 0;
|
|
|
|
threads= (pthread_t *)my_malloc(sizeof(void *)*n, MYF(0));
|
|
if (!threads)
|
|
{
|
|
diag("Out of memory");
|
|
abort();
|
|
}
|
|
|
|
diag("Testing %s with %d threads, %d iterations... ", test, n, m);
|
|
rt_num_threads= n;
|
|
for (i= 0; i < n ; i++)
|
|
if (pthread_create(threads+i, &attr, handler, &m))
|
|
{
|
|
diag("Could not create thread");
|
|
abort();
|
|
}
|
|
for (i= 0 ; i < n ; i++)
|
|
pthread_join(threads[i], 0);
|
|
now= my_getsystime()-now;
|
|
ok(litmus == 0, "Tested %s in %g secs (%d)", test, ((double)now)/1e7, litmus);
|
|
my_free((void*)threads, MYF(0));
|
|
}
|
|
|
|
#define ok_read_from(T1, T2, RES) \
|
|
i= trnman_can_read_from(trn[T1], trn[T2]->trid); \
|
|
ok(i == RES, "trn" #T1 " %s read from trn" #T2, i ? "can" : "cannot")
|
|
#define start_transaction(T) \
|
|
trn[T]= trnman_new_trn(&mutexes[T], &conds[T], &i + STACK_SIZE)
|
|
#define commit(T) trnman_commit_trn(trn[T])
|
|
#define abort(T) trnman_abort_trn(trn[T])
|
|
|
|
#define Ntrns 4
|
|
void test_trnman_read_from()
|
|
{
|
|
TRN *trn[Ntrns];
|
|
pthread_mutex_t mutexes[Ntrns];
|
|
pthread_cond_t conds[Ntrns];
|
|
int i;
|
|
|
|
for (i= 0; i < Ntrns; i++)
|
|
{
|
|
pthread_mutex_init(&mutexes[i], MY_MUTEX_INIT_FAST);
|
|
pthread_cond_init(&conds[i], 0);
|
|
}
|
|
|
|
start_transaction(0); /* start trn1 */
|
|
start_transaction(1); /* start trn2 */
|
|
ok_read_from(1, 0, 0);
|
|
commit(0); /* commit trn1 */
|
|
start_transaction(2); /* start trn4 */
|
|
abort(2); /* abort trn4 */
|
|
start_transaction(3); /* start trn5 */
|
|
ok_read_from(3, 0, 1);
|
|
ok_read_from(3, 1, 0);
|
|
ok_read_from(3, 2, 0);
|
|
commit(1); /* commit trn2 */
|
|
ok_read_from(3, 1, 0);
|
|
commit(3); /* commit trn5 */
|
|
|
|
for (i= 0; i < Ntrns; i++)
|
|
{
|
|
pthread_mutex_destroy(&mutexes[i]);
|
|
pthread_cond_destroy(&conds[i]);
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
my_init();
|
|
|
|
plan(6);
|
|
|
|
if (my_atomic_initialize())
|
|
return exit_status();
|
|
|
|
pthread_mutex_init(&rt_mutex, 0);
|
|
pthread_attr_init(&attr);
|
|
#ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE
|
|
pthread_attr_getstacksize(&attr, &stacksize);
|
|
if (stacksize == 0)
|
|
#endif
|
|
stacksize= PTHREAD_STACK_MIN;
|
|
|
|
#define CYCLES 10000
|
|
#define THREADS 10
|
|
|
|
trnman_init();
|
|
|
|
test_trnman_read_from();
|
|
run_test("trnman", test_trnman, THREADS, CYCLES);
|
|
|
|
diag("mallocs: %d", trnman_allocated_transactions);
|
|
{
|
|
ulonglong now= my_getsystime();
|
|
trnman_destroy();
|
|
now= my_getsystime()-now;
|
|
diag("trnman_destroy: %g", ((double)now)/1e7);
|
|
}
|
|
|
|
pthread_mutex_destroy(&rt_mutex);
|
|
my_end(0);
|
|
return exit_status();
|
|
}
|
|
|