MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DblqhCommon.cpp
1 /* Copyright (C) 2008 MySQL AB, 2008 Sun Microsystems, Inc.
2  All rights reserved. Use is subject to license terms.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 
17 #include <GlobalData.hpp>
18 #include <SimulatedBlock.hpp>
19 #include "DblqhCommon.hpp"
20 
21 NdbLogPartInfo::NdbLogPartInfo(Uint32 instanceNo)
22 {
23  lqhWorkers = globalData.ndbMtLqhWorkers;
24  partCount = 0;
25  partMask.clear();
26  Uint32 lpno;
27  for (lpno = 0; lpno < LogParts; lpno++) {
28  if (instanceNo != 0) {
29  Uint32 worker = instanceNo - 1;
30  assert(worker < lqhWorkers);
31  if (worker != lpno % lqhWorkers)
32  continue;
33  }
34  partNo[partCount++] = lpno;
35  partMask.set(lpno);
36  }
37 }
38 
39 Uint32
40 NdbLogPartInfo::partNoFromId(Uint32 lpid) const
41 {
42  return lpid % LogParts;
43 }
44 
45 bool
46 NdbLogPartInfo::partNoOwner(Uint32 lpno) const
47 {
48  assert(lpno < LogParts);
49  return partMask.get(lpno);
50 }
51 
52 bool
53 NdbLogPartInfo::partNoOwner(Uint32 tabId, Uint32 fragId)
54 {
55  Uint32 instanceKey = SimulatedBlock::getInstanceKey(tabId, fragId);
56  assert(instanceKey != 0);
57  Uint32 lpid = instanceKey - 1;
58  Uint32 lpno = partNoFromId(lpid);
59  return partNoOwner(lpno);
60 }
61 
62 Uint32
63 NdbLogPartInfo::partNoIndex(Uint32 lpno) const
64 {
65  assert(lpno < LogParts);
66  assert(partMask.get(lpno));
67  Uint32 i = 0;
68  if (lqhWorkers == 0)
69  i = lpno;
70  else
71  i = lpno / lqhWorkers;
72  assert(i < partCount);
73  assert(partNo[i] == lpno);
74  return i;
75 }
76 
77 Uint32
78 NdbLogPartInfo::instanceKey(Uint32 lpno) const
79 {
80  assert(lpno < LogParts);
81  return 1 + lpno;
82 }