~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/blocks/dbtup/Undo_buffer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
 
15
 
 
16
#include "Undo_buffer.hpp"
 
17
#define DBTUP_C
 
18
#include "Dbtup.hpp"
 
19
 
 
20
#if ZPAGE_STATE_POS != 0
 
21
#error "PROBLEM!"
 
22
#endif
 
23
 
 
24
struct UndoPage
 
25
{
 
26
  File_formats::Page_header m_page_header;
 
27
  Uint32 _tupdata1;
 
28
  Uint32 m_state; // Used by buddy alg
 
29
  Uint32 m_words_used;
 
30
  Uint32 m_ref_count;
 
31
  Uint32 m_data[GLOBAL_PAGE_SIZE_WORDS-4-(sizeof(File_formats::Page_header)>>2)];
 
32
  
 
33
  STATIC_CONST( DATA_WORDS = GLOBAL_PAGE_SIZE_WORDS-4-(sizeof(File_formats::Page_header)>>2) );
 
34
};
 
35
 
 
36
Undo_buffer::Undo_buffer(Dbtup* tup)
 
37
{
 
38
  m_tup= tup;
 
39
  m_first_free= RNIL;
 
40
}
 
41
 
 
42
Uint32 *
 
43
Undo_buffer::alloc_copy_tuple(Local_key* dst, Uint32 words)
 
44
{
 
45
  UndoPage* page;
 
46
  assert(words);
 
47
  if(m_first_free == RNIL)
 
48
  {
 
49
    Uint32 count;
 
50
    m_tup->allocConsPages(1, count, m_first_free);
 
51
    if(count == 0)
 
52
      return 0;
 
53
    page= (UndoPage*)m_tup->c_page_pool.getPtr(m_first_free);
 
54
    page->m_state= ~ZFREE_COMMON;
 
55
    page->m_words_used= 0;
 
56
    page->m_ref_count= 0;
 
57
  }
 
58
  
 
59
  page= (UndoPage*)m_tup->c_page_pool.getPtr(m_first_free);
 
60
  
 
61
  Uint32 pos= page->m_words_used;
 
62
  if(words + pos > UndoPage::DATA_WORDS)
 
63
  {
 
64
    m_first_free= RNIL;
 
65
    return alloc_copy_tuple(dst, words);
 
66
  }
 
67
  
 
68
  dst->m_page_no = m_first_free;
 
69
  dst->m_page_idx = pos;
 
70
  
 
71
  page->m_ref_count++;
 
72
  page->m_words_used = pos + words;
 
73
  return page->m_data + pos;
 
74
}
 
75
 
 
76
void
 
77
Undo_buffer::shrink_copy_tuple(Local_key* key, Uint32 words)
 
78
{
 
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;
 
83
}
 
84
 
 
85
void
 
86
Undo_buffer::free_copy_tuple(Local_key* key)
 
87
{
 
88
  UndoPage* page= (UndoPage*)m_tup->c_page_pool.getPtr(key->m_page_no);
 
89
  Uint32 cnt= page->m_ref_count;
 
90
  assert(cnt);
 
91
 
 
92
  page->m_ref_count= cnt - 1;
 
93
  
 
94
  if(cnt - 1 == 0)
 
95
  {
 
96
    page->m_words_used= 0;
 
97
    if(m_first_free == key->m_page_no)
 
98
    {
 
99
      //ndbout_c("resetting page");
 
100
    }
 
101
    else 
 
102
    {
 
103
      //ndbout_c("returning page");
 
104
      m_tup->returnCommonArea(key->m_page_no, 1);
 
105
    }
 
106
  }
 
107
  key->setNull();
 
108
}
 
109
 
 
110
Uint32 *
 
111
Undo_buffer::get_ptr(Local_key* key)
 
112
{
 
113
  return ((UndoPage*)(m_tup->c_page_pool.getPtr(key->m_page_no)))->m_data+key->m_page_idx;
 
114
}
 
115