MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbApiLoad.java
1 /* -*- mode: java; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=4:tabstop=4:smarttab:
3  *
4  * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 package com.mysql.cluster.crund;
21 
22 public class NdbApiLoad extends NdbBase {
23 
24  // ----------------------------------------------------------------------
25  // NDB API intializers/finalizers
26  // ----------------------------------------------------------------------
27 
28  protected void initProperties() {
29  super.initProperties();
30  descr = "->ndbapi(" + mgmdConnect + ")";
31  }
32 
33  // initializes/finalizes the NDB benchmark class
34  // a non-zero value in case of an error, and zero otherwise
35  static protected native int ndbinit(String mgmd_host_portno);
36  static protected native int ndbclose();
37 
38  protected void initLoad() throws Exception {
39  // XXX support generic load class
40  //super.init();
41 
42  // load dependent libs first
43  out.println();
44  loadSystemLibrary("ndbclient");
45  loadSystemLibrary("crundndb");
46 
47  // initialize NDB resources
48  final int ret = ndbinit(mgmdConnect);
49  if (ret != 0) {
50  String msg = ("NdbApiLoad: failed initializing NDBAPI;"
51  + " return value = " + ret);
52  err.println(msg);
53  throw new Exception(msg);
54  }
55  }
56 
57  protected void closeLoad() throws Exception {
58  // release NDB resources
59  final int ret = ndbclose();
60  if (ret != 0) {
61  String msg = ("NdbApiLoad: failed closing NDBAPI;"
62  + " return value = " + ret);
63  err.println(msg);
64  throw new Exception(msg);
65  }
66 
67  // XXX support generic load class
68  //super.close();
69  }
70 
71  // ----------------------------------------------------------------------
72  // NDB API operations
73  // ----------------------------------------------------------------------
74 
75  protected native void delAllA(int nOps, boolean batch);
76  protected native void delAllB0(int nOps, boolean batch);
77  protected native void insA(int nOps, boolean setAttrs, boolean batch);
78  protected native void insB0(int nOps, boolean setAttrs, boolean batch);
79  protected native void delAByPK(int nOps, boolean batch);
80  protected native void delB0ByPK(int nOps, boolean batch);
81  protected native void setAByPK(int nOps, boolean batch);
82  protected native void setB0ByPK(int nOps, boolean batch);
83  protected native void getAByPK_bb(int nOps, boolean batch);
84  protected native void getB0ByPK_bb(int nOps, boolean batch);
85  protected native void getAByPK_ar(int nOps, boolean batch);
86  protected native void getB0ByPK_ar(int nOps, boolean batch);
87  protected native void setVarbinary(int nOps, boolean batch, int length);
88  protected native void getVarbinary(int nOps, boolean batch, int length);
89  protected native void setVarchar(int nOps, boolean batch, int length);
90  protected native void getVarchar(int nOps, boolean batch, int length);
91  protected native void setB0ToA(int nOps, boolean batch);
92  protected native void navB0ToA(int nOps, boolean batch);
93  protected native void navB0ToAalt(int nOps, boolean batch);
94  protected native void navAToB0(int nOps, boolean batch);
95  protected native void navAToB0alt(int nOps, boolean batch);
96  protected native void nullB0ToA(int nOps, boolean batch);
97 
98  protected void initOperations() {
99  out.print("initializing operations ...");
100  out.flush();
101 
102  for (boolean f = false, done = false; !done; done = f, f = true) {
103  // inner classes can only refer to a constant
104  final boolean batch = f;
105  final boolean forceSend = f;
106  final boolean setAttrs = true;
107 
108  ops.add(
109  new Op("insA" + (batch ? "_batch" : "")) {
110  public void run(int nOps) {
111  insA(nOps, !setAttrs, batch);
112  }
113  });
114 
115  ops.add(
116  new Op("insB0" + (batch ? "_batch" : "")) {
117  public void run(int nOps) {
118  insB0(nOps, !setAttrs, batch);
119  }
120  });
121 
122  ops.add(
123  new Op("setAByPK" + (batch ? "_batch" : "")) {
124  public void run(int nOps) {
125  setAByPK(nOps, batch);
126  }
127  });
128 
129  ops.add(
130  new Op("setB0ByPK" + (batch ? "_batch" : "")) {
131  public void run(int nOps) {
132  setB0ByPK(nOps, batch);
133  }
134  });
135 
136  ops.add(
137  new Op("getAByPK_bb" + (batch ? "_batch" : "")) {
138  public void run(int nOps) {
139  getAByPK_bb(nOps, batch);
140  }
141  });
142 
143  ops.add(
144  new Op("getAByPK_ar" + (batch ? "_batch" : "")) {
145  public void run(int nOps) {
146  getAByPK_ar(nOps, batch);
147  }
148  });
149 
150  ops.add(
151  new Op("getB0ByPK_bb" + (batch ? "_batch" : "")) {
152  public void run(int nOps) {
153  getB0ByPK_bb(nOps, batch);
154  }
155  });
156 
157  ops.add(
158  new Op("getB0ByPK_ar" + (batch ? "_batch" : "")) {
159  public void run(int nOps) {
160  getB0ByPK_ar(nOps, batch);
161  }
162  });
163 
164  for (int i = 1; i <= maxVarbinaryBytes; i *= 10) {
165  final int length = i;
166 
167  ops.add(
168  new Op("setVarbinary" + length + (batch ? "_batch" : "")) {
169  public void run(int nOps) {
170  setVarbinary(nOps, batch, length);
171  }
172  });
173 
174  ops.add(
175  new Op("getVarbinary" + length + (batch ? "_batch" : "")) {
176  public void run(int nOps) {
177  getVarbinary(nOps, batch, length);
178  }
179  });
180 
181  ops.add(
182  new Op("clearVarbinary" + length + (batch ? "_batch" : "")) {
183  public void run(int nOps) {
184  setVarbinary(nOps, batch, 0);
185  }
186  });
187  }
188 
189  for (int i = 1; i <= maxVarcharChars; i *= 10) {
190  final int length = i;
191 
192  ops.add(
193  new Op("setVarchar" + length + (batch ? "_batch" : "")) {
194  public void run(int nOps) {
195  setVarchar(nOps, batch, length);
196  }
197  });
198 
199  ops.add(
200  new Op("getVarchar" + length + (batch ? "_batch" : "")) {
201  public void run(int nOps) {
202  getVarchar(nOps, batch, length);
203  }
204  });
205 
206  ops.add(
207  new Op("clearVarchar" + length + (batch ? "_batch" : "")) {
208  public void run(int nOps) {
209  setVarchar(nOps, batch, 0);
210  }
211  });
212 
213  }
214 
215  ops.add(
216  new Op("setB0->A" + (batch ? "_batch" : "")) {
217  public void run(int nOps) {
218  setB0ToA(nOps, batch);
219  }
220  });
221 
222  ops.add(
223  new Op("navB0->A" + (batch ? "_batch" : "")) {
224  public void run(int nOps) {
225  navB0ToA(nOps, batch);
226  }
227  });
228 
229  ops.add(
230  new Op("navB0->A_alt" + (batch ? "_batch" : "")) {
231  public void run(int nOps) {
232  navB0ToAalt(nOps, batch);
233  }
234  });
235 
236  ops.add(
237  new Op("navA->B0" + (forceSend ? "_forceSend" : "")) {
238  public void run(int nOps) {
239  navAToB0(nOps, forceSend);
240  }
241  });
242 
243  ops.add(
244  new Op("navA->B0_alt" + (forceSend ? "_forceSend" : "")) {
245  public void run(int nOps) {
246  navAToB0alt(nOps, forceSend);
247  }
248  });
249 
250  ops.add(
251  new Op("nullB0->A" + (batch ? "_batch" : "")) {
252  public void run(int nOps) {
253  nullB0ToA(nOps, batch);
254  }
255  });
256 
257  ops.add(
258  new Op("delB0ByPK" + (batch ? "_batch" : "")) {
259  public void run(int nOps) {
260  delB0ByPK(nOps, batch);
261  }
262  });
263 
264  ops.add(
265  new Op("delAByPK" + (batch ? "_batch" : "")) {
266  public void run(int nOps) {
267  delAByPK(nOps, batch);
268  }
269  });
270 
271  ops.add(
272  new Op("insA_attr" + (batch ? "_batch" : "")) {
273  public void run(int nOps) {
274  insA(nOps, setAttrs, batch);
275  }
276  });
277 
278  ops.add(
279  new Op("insB0_attr" + (batch ? "_batch" : "")) {
280  public void run(int nOps) {
281  insB0(nOps, setAttrs, batch);
282  }
283  });
284 
285  ops.add(
286  new Op("delAllB0" + (batch ? "_batch" : "")) {
287  public void run(int nOps) {
288  delAllB0(nOps, batch);
289  }
290  });
291 
292  ops.add(
293  new Op("delAllA" + (batch ? "_batch" : "")) {
294  public void run(int nOps) {
295  delAllA(nOps, batch);
296  }
297  });
298  }
299 
300  out.println(" [Op: " + ops.size() + "]");
301  }
302 
303  protected void closeOperations() {
304  out.print("closing operations ...");
305  out.flush();
306  ops.clear();
307  out.println(" [ok]");
308  }
309 
310  // ----------------------------------------------------------------------
311  // NDB API datastore operations
312  // ----------------------------------------------------------------------
313 
314  protected native void initConnection(String catalog,
315  String schema,
316  int defaultLockMode);
317  protected void initConnection() {
318  // XXX add lockMode property to CrundDriver, switch then here
319  final int LM_Read = 0;
320  final int LM_Exclusive = 1;
321  final int LM_CommittedRead = 2;
322  initConnection(catalog, schema, LM_CommittedRead);
323  }
324  protected native void closeConnection();
325  protected native void clearData();
326 
327  // ----------------------------------------------------------------------
328 
329  static public void main(String[] args) {
330  System.out.println("NdbApiLoad.main()");
331  parseArguments(args);
332  new NdbApiLoad().run();
333  System.out.println();
334  System.out.println("NdbApiLoad.main(): done.");
335  }
336 }