diff options
author | monty@donna.mysql.com <> | 2001-02-17 14:19:19 +0200 |
---|---|---|
committer | monty@donna.mysql.com <> | 2001-02-17 14:19:19 +0200 |
commit | c533308a158795f91247e9fe3c7304fa5e7d2b3c (patch) | |
tree | bfe39951a73e906579ab819bf5198ad8f3a64a36 /innobase/read | |
parent | 024e2f39c9a3812243778ebe64b43e8edd22a4a1 (diff) | |
download | mariadb-git-c533308a158795f91247e9fe3c7304fa5e7d2b3c.tar.gz |
Added Innobase to source distribution
Diffstat (limited to 'innobase/read')
-rw-r--r-- | innobase/read/Makefile.am | 24 | ||||
-rw-r--r-- | innobase/read/makefilewin | 7 | ||||
-rw-r--r-- | innobase/read/read0read.c | 201 |
3 files changed, 232 insertions, 0 deletions
diff --git a/innobase/read/Makefile.am b/innobase/read/Makefile.am new file mode 100644 index 00000000000..16224f4f7f4 --- /dev/null +++ b/innobase/read/Makefile.am @@ -0,0 +1,24 @@ +# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +# & Innobase Oy +# +# 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 ../include/Makefile.i + +libs_LIBRARIES = libread.a + +libread_a_SOURCES = read0read.c + +EXTRA_PROGRAMS = diff --git a/innobase/read/makefilewin b/innobase/read/makefilewin new file mode 100644 index 00000000000..39593993a67 --- /dev/null +++ b/innobase/read/makefilewin @@ -0,0 +1,7 @@ +include ..\include\makefile.i + +read.lib: read0read.obj + lib -out:..\libs\read.lib read0read.obj + +read0read.obj: read0read.c + $(CCOM) $(CFL) -c read0read.c diff --git a/innobase/read/read0read.c b/innobase/read/read0read.c new file mode 100644 index 00000000000..84e2c93b30c --- /dev/null +++ b/innobase/read/read0read.c @@ -0,0 +1,201 @@ +/****************************************************** +Cursor read + +(c) 1997 Innobase Oy + +Created 2/16/1997 Heikki Tuuri +*******************************************************/ + +#include "read0read.h" + +#ifdef UNIV_NONINL +#include "read0read.ic" +#endif + +#include "srv0srv.h" +#include "trx0sys.h" + +/************************************************************************* +Creates a read view object. */ +UNIV_INLINE +read_view_t* +read_view_create_low( +/*=================*/ + /* out, own: read view struct */ + ulint n, /* in: number of cells in the trx_ids array */ + mem_heap_t* heap) /* in: memory heap from which allocated */ +{ + read_view_t* view; + + view = mem_heap_alloc(heap, sizeof(read_view_t)); + + view->n_trx_ids = n; + view->trx_ids = mem_heap_alloc(heap, n * sizeof(dulint)); + + return(view); +} + +/************************************************************************* +Makes a copy of the oldest existing read view, with the exception that also +the creating trx of the oldest view is set as not visible in the 'copied' +view. Opens a new view if no views currently exist. The view must be +closed with ..._close. This is used in purge. */ + +read_view_t* +read_view_oldest_copy_or_open_new( +/*==============================*/ + /* out, own: read view struct */ + trx_t* cr_trx, /* in: creating transaction, or NULL */ + mem_heap_t* heap) /* in: memory heap from which allocated */ +{ + read_view_t* old_view; + read_view_t* view_copy; + ibool needs_insert = TRUE; + ulint insert_done = 0; + ulint n; + ulint i; + + ut_ad(mutex_own(&kernel_mutex)); + + old_view = UT_LIST_GET_LAST(trx_sys->view_list); + + if (old_view == NULL) { + + return(read_view_open_now(cr_trx, heap)); + } + + n = old_view->n_trx_ids; + + if (old_view->creator) { + n++; + } else { + needs_insert = FALSE; + } + + view_copy = read_view_create_low(n, heap); + + /* Insert the id of the creator in the right place of the descending + array of ids, if needs_insert is TRUE: */ + + i = 0; + while (i < n) { + if (needs_insert + && (i >= old_view->n_trx_ids + || ut_dulint_cmp(old_view->creator->id, + read_view_get_nth_trx_id(old_view, i)) + > 0)) { + + read_view_set_nth_trx_id(view_copy, i, + old_view->creator->id); + needs_insert = FALSE; + insert_done = 1; + } else { + read_view_set_nth_trx_id(view_copy, i, + read_view_get_nth_trx_id(old_view, + i - insert_done)); + } + + i++; + } + + view_copy->creator = cr_trx; + + view_copy->low_limit_no = old_view->low_limit_no; + view_copy->low_limit_id = old_view->low_limit_id; + + view_copy->can_be_too_old = FALSE; + + if (n > 0) { + /* The last active transaction has the smallest id: */ + view_copy->up_limit_id = read_view_get_nth_trx_id( + view_copy, n - 1); + } else { + view_copy->up_limit_id = old_view->up_limit_id; + } + + UT_LIST_ADD_LAST(view_list, trx_sys->view_list, view_copy); + + return(view_copy); +} + +/************************************************************************* +Opens a read view where exactly the transactions serialized before this +point in time are seen in the view. */ + +read_view_t* +read_view_open_now( +/*===============*/ + /* out, own: read view struct */ + trx_t* cr_trx, /* in: creating transaction, or NULL */ + mem_heap_t* heap) /* in: memory heap from which allocated */ +{ + read_view_t* view; + trx_t* trx; + ulint n; + + ut_ad(mutex_own(&kernel_mutex)); + + view = read_view_create_low(UT_LIST_GET_LEN(trx_sys->trx_list), heap); + + view->creator = cr_trx; + + /* No future transactions should be visible in the view */ + + view->low_limit_no = trx_sys->max_trx_id; + view->low_limit_id = view->low_limit_no; + + view->can_be_too_old = FALSE; + + n = 0; + trx = UT_LIST_GET_FIRST(trx_sys->trx_list); + + /* No active transaction should be visible, except cr_trx */ + + while (trx) { + if (trx != cr_trx && trx->conc_state == TRX_ACTIVE) { + + read_view_set_nth_trx_id(view, n, trx->id); + + n++; + + /* NOTE that a transaction whose trx number is < + trx_sys->max_trx_id can still be active, if it is + in the middle of the commit! Note that when a + transaction starts, we initialize trx->no to + ut_dulint_max. */ + + if (ut_dulint_cmp(view->low_limit_no, trx->no) > 0) { + + view->low_limit_no = trx->no; + } + } + + trx = UT_LIST_GET_NEXT(trx_list, trx); + } + + view->n_trx_ids = n; + + if (n > 0) { + /* The last active transaction has the smallest id: */ + view->up_limit_id = read_view_get_nth_trx_id(view, n - 1); + } else { + view->up_limit_id = view->low_limit_id; + } + + UT_LIST_ADD_FIRST(view_list, trx_sys->view_list, view); + + return(view); +} + +/************************************************************************* +Closes a read view. */ + +void +read_view_close( +/*============*/ + read_view_t* view) /* in: read view */ +{ + ut_ad(mutex_own(&kernel_mutex)); + + UT_LIST_REMOVE(view_list, trx_sys->view_list, view); +} |