1 /* Copyright (c) 2008, 2021, Oracle and/or its affiliates.
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, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
22 
23 #include <GlobalData.hpp>
24 #include <SimulatedBlock.hpp>
25 #include "DblqhCommon.hpp"
26 
27 #define JAM_FILE_ID 444
28 
29 
NdbLogPartInfo(Uint32 instanceNo)30 NdbLogPartInfo::NdbLogPartInfo(Uint32 instanceNo)
31 {
32   LogParts = globalData.ndbLogParts;
33   lqhWorkers = globalData.ndbMtLqhWorkers;
34   partCount = 0;
35   partMask.clear();
36   Uint32 lpno;
37   for (lpno = 0; lpno < LogParts; lpno++) {
38     if (instanceNo != 0) {
39       Uint32 worker = instanceNo - 1;
40       assert(worker < lqhWorkers);
41       if (worker != lpno % lqhWorkers)
42         continue;
43     }
44     partNo[partCount++] = lpno;
45     partMask.set(lpno);
46   }
47 }
48 
49 Uint32
partNoFromId(Uint32 lpid) const50 NdbLogPartInfo::partNoFromId(Uint32 lpid) const
51 {
52   return lpid % LogParts;
53 }
54 
55 bool
partNoOwner(Uint32 lpno) const56 NdbLogPartInfo::partNoOwner(Uint32 lpno) const
57 {
58   assert(lpno < LogParts);
59   return partMask.get(lpno);
60 }
61 
62 Uint32
partNoIndex(Uint32 lpno) const63 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