1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "Undo_buffer.hpp"
20
#if ZPAGE_STATE_POS != 0
26
File_formats::Page_header m_page_header;
28
Uint32 m_state; // Used by buddy alg
31
Uint32 m_data[GLOBAL_PAGE_SIZE_WORDS-4-(sizeof(File_formats::Page_header)>>2)];
33
STATIC_CONST( DATA_WORDS = GLOBAL_PAGE_SIZE_WORDS-4-(sizeof(File_formats::Page_header)>>2) );
36
Undo_buffer::Undo_buffer(Dbtup* tup)
43
Undo_buffer::alloc_copy_tuple(Local_key* dst, Uint32 words)
47
if(m_first_free == RNIL)
50
m_tup->allocConsPages(1, count, m_first_free);
53
page= (UndoPage*)m_tup->c_page_pool.getPtr(m_first_free);
54
page->m_state= ~ZFREE_COMMON;
55
page->m_words_used= 0;
59
page= (UndoPage*)m_tup->c_page_pool.getPtr(m_first_free);
61
Uint32 pos= page->m_words_used;
62
if(words + pos > UndoPage::DATA_WORDS)
65
return alloc_copy_tuple(dst, words);
68
dst->m_page_no = m_first_free;
69
dst->m_page_idx = pos;
72
page->m_words_used = pos + words;
73
return page->m_data + pos;
77
Undo_buffer::shrink_copy_tuple(Local_key* key, Uint32 words)
79
assert(key->m_page_no == m_first_free);
80
UndoPage* page= (UndoPage*)m_tup->c_page_pool.getPtr(key->m_page_no);
81
assert(page->m_words_used >= words);
82
page->m_words_used -= words;
86
Undo_buffer::free_copy_tuple(Local_key* key)
88
UndoPage* page= (UndoPage*)m_tup->c_page_pool.getPtr(key->m_page_no);
89
Uint32 cnt= page->m_ref_count;
92
page->m_ref_count= cnt - 1;
96
page->m_words_used= 0;
97
if(m_first_free == key->m_page_no)
99
//ndbout_c("resetting page");
103
//ndbout_c("returning page");
104
m_tup->returnCommonArea(key->m_page_no, 1);
111
Undo_buffer::get_ptr(Local_key* key)
113
return ((UndoPage*)(m_tup->c_page_pool.getPtr(key->m_page_no)))->m_data+key->m_page_idx;