2
Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
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.
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.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
18
#ifndef NdbTransaction_H
19
#define NdbTransaction_H
21
#include <ndb_types.h>
22
#include "NdbError.hpp"
23
#include "NdbDictionary.hpp"
25
#include "NdbOperation.hpp"
26
#include "NdbIndexScanOperation.hpp"
29
class NdbScanOperation;
30
class NdbIndexScanOperation;
31
class NdbIndexOperation;
35
class NdbInterpretedCode;
39
class NdbQueryParamValue;
42
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
43
// to be documented later
45
* NdbAsynchCallback functions are used when executing asynchronous
46
* transactions (using NdbTransaction::executeAsynchPrepare, or
47
* NdbTransaction::executeAsynch).
48
* The functions are called when the execute has finished.
49
* See @ref secAsync for more information.
51
typedef void (* NdbAsynchCallback)(int, NdbTransaction*, void*);
54
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
56
DefaultAbortOption = NdbOperation::DefaultAbortOption,
57
CommitIfFailFree = NdbOperation::AbortOnError,
58
TryCommit = NdbOperation::AbortOnError,
59
AbortOnError= NdbOperation::AbortOnError,
60
CommitAsMuchAsPossible = NdbOperation::AO_IgnoreError,
61
AO_IgnoreError= NdbOperation::AO_IgnoreError
73
* @class NdbTransaction
74
* @brief Represents a transaction.
76
* A transaction (represented by an NdbTransaction object)
77
* belongs to an Ndb object and is created using
78
* Ndb::startTransaction().
79
* A transaction consists of a list of operations
80
* (represented by NdbOperation, NdbScanOperation, NdbIndexOperation,
81
* and NdbIndexScanOperation objects).
82
* Each operation access exactly one table.
84
* After getting the NdbTransaction object,
85
* the first step is to get (allocate) an operation given the table name using
86
* one of the methods getNdbOperation(), getNdbScanOperation(),
87
* getNdbIndexOperation(), or getNdbIndexScanOperation().
88
* Then the operation is defined.
89
* Several operations can be defined on the same
90
* NdbTransaction object, they will in that case be executed in parallell.
91
* When all operations are defined, the execute()
92
* method sends them to the NDB kernel for execution.
94
* The execute() method returns when the NDB kernel has
95
* completed execution of all operations defined before the call to
96
* execute(). All allocated operations should be properly defined
97
* before calling execute().
99
* A call to execute() uses one out of three types of execution:
100
* -# NdbTransaction::NoCommit Executes operations without committing them.
101
* -# NdbTransaction::Commit Executes remaining operation and commits the
102
* complete transaction
103
* -# NdbTransaction::Rollback Rollbacks the entire transaction.
105
* execute() is equipped with an extra error handling parameter.
106
* There are two alternatives:
107
* -# NdbTransaction::AbortOnError (default).
108
* The transaction is aborted if there are any error during the
110
* -# NdbTransaction::AO_IgnoreError
111
* Continue execution of transaction even if operation fails
115
/* FUTURE IMPLEMENTATION:
116
* Later a prepare mode will be added when Ndb supports Prepare-To-Commit
117
* The NdbTransaction can deliver the Transaction Id of the transaction.
118
* After committing a transaction it is also possible to retrieve the
119
* global transaction checkpoint which the transaction was put in.
121
* FUTURE IMPLEMENTATION:
122
* There are three methods for acquiring the NdbOperation.
123
* -# The first method is the normal where a table name is
124
* provided. In this case the primary key must be supplied through
125
* the use of the NdbOperation::equal methods on the NdbOperation object.
126
* -# The second method provides the tuple identity of the tuple to be
127
* read. The tuple identity contains a table identifier and will
128
* thus be possible to use to ensure the attribute names provided
129
* are correct. If an object-oriented layer is put on top of NDB
130
* Cluster it is essential that all tables derived from a base
131
* class has the same attributes with the same type and the same
132
* name. Thus the application can use the tuple identity and need
133
* not known the table of the tuple. As long as the table is
134
* derived from the known base class everything is ok.
135
* It is not possible to provide any primary key since it is
136
* already supplied with the call to NdbTransaction::getNdbOperation.
137
* -# The third method is used when a scanned tuple is to be transferred to
138
* another transaction. In this case it is not possible to define the
139
* primary key since it came along from the scanned tuple.
147
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
149
friend class NdbOperation;
150
friend class NdbScanOperation;
151
friend class NdbIndexOperation;
152
friend class NdbIndexScanOperation;
153
friend class NdbBlob;
154
friend class ha_ndbcluster;
155
friend class NdbQueryImpl;
156
friend class NdbQueryOperationImpl;
160
#ifdef NDBAPI_50_COMPAT
162
DefaultAbortOption = NdbOperation::DefaultAbortOption,
163
CommitIfFailFree = NdbOperation::AbortOnError,
164
TryCommit = NdbOperation::AbortOnError,
165
AbortOnError= NdbOperation::AbortOnError,
166
CommitAsMuchAsPossible = NdbOperation::AO_IgnoreError,
167
AO_IgnoreError= NdbOperation::AO_IgnoreError
173
* Execution type of transaction
176
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
178
::NoExecTypeDef, ///< Erroneous type (Used for debugging only)
179
Prepare= ::Prepare, ///< <i>Missing explanation</i>
181
NoCommit= ///< Execute the transaction as far as it has
182
///< been defined, but do not yet commit it
183
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
186
,Commit= ///< Execute and try to commit the transaction
187
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
190
,Rollback ///< Rollback transaction
191
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
196
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
198
* Convenience method to fetch this transaction's Ndb* object
205
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
207
* Get an NdbOperation for a table.
208
* Note that the operation has to be defined before it is executed.
210
* @note All operations within the same transaction need to
211
* be initialized with this method.
213
* @param aTableName The table name.
214
* @return Pointer to an NdbOperation object if successful, otherwise NULL.
216
NdbOperation* getNdbOperation(const char* aTableName);
220
* Get an NdbOperation for a table.
221
* Note that the operation has to be defined before it is executed.
223
* @note All operations within the same transaction need to
224
* be initialized with this method.
227
* A table object (fetched by NdbDictionary::Dictionary::getTable)
228
* @return Pointer to an NdbOperation object if successful, otherwise NULL.
230
NdbOperation* getNdbOperation(const NdbDictionary::Table * aTable);
232
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
234
* Get an operation from NdbScanOperation idlelist and
235
* get the NdbTransaction object which
236
* was fetched by startTransaction pointing to this operation.
238
* @param aTableName The table name.
239
* @return pointer to an NdbOperation object if successful, otherwise NULL
241
NdbScanOperation* getNdbScanOperation(const char* aTableName);
245
* Get an operation from NdbScanOperation idlelist and
246
* get the NdbTransaction object which
247
* was fetched by startTransaction pointing to this operation.
250
* A table object (fetched by NdbDictionary::Dictionary::getTable)
251
* @return pointer to an NdbOperation object if successful, otherwise NULL
253
NdbScanOperation* getNdbScanOperation(const NdbDictionary::Table * aTable);
255
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
257
* Get an operation from NdbIndexScanOperation idlelist and
258
* get the NdbTransaction object which
259
* was fetched by startTransaction pointing to this operation.
261
* @param anIndexName The name of the index to use for scanning
262
* @param aTableName The name of the table to scan
263
* @return pointer to an NdbOperation object if successful, otherwise NULL
265
NdbIndexScanOperation* getNdbIndexScanOperation(const char* anIndexName,
266
const char* aTableName);
267
NdbIndexScanOperation* getNdbIndexScanOperation
268
(const NdbDictionary::Index *anIndex, const NdbDictionary::Table *aTable);
272
* Get an operation from NdbIndexScanOperation idlelist and
273
* get the NdbTransaction object which
274
* was fetched by startTransaction pointing to this operation.
277
An index object (fetched by NdbDictionary::Dictionary::getIndex).
278
* @return pointer to an NdbOperation object if successful, otherwise NULL
280
NdbIndexScanOperation* getNdbIndexScanOperation
281
(const NdbDictionary::Index *anIndex);
283
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
285
* Get an operation from NdbIndexOperation idlelist and
286
* get the NdbTransaction object that
287
* was fetched by startTransaction pointing to this operation.
289
* @param anIndexName The index name (as created by createIndex).
290
* @param aTableName The table name.
291
* @return Pointer to an NdbIndexOperation object if
292
* successful, otherwise NULL
294
NdbIndexOperation* getNdbIndexOperation(const char* anIndexName,
295
const char* aTableName);
296
NdbIndexOperation* getNdbIndexOperation(const NdbDictionary::Index *anIndex,
297
const NdbDictionary::Table *aTable);
301
* Get an operation from NdbIndexOperation idlelist and
302
* get the NdbTransaction object that
303
* was fetched by startTransaction pointing to this operation.
306
* An index object (fetched by NdbDictionary::Dictionary::getIndex).
307
* @return Pointer to an NdbIndexOperation object if
308
* successful, otherwise NULL
310
NdbIndexOperation* getNdbIndexOperation(const NdbDictionary::Index *anIndex);
313
* @name Execute Transaction
318
* Executes transaction.
320
* @param execType Execution type:<br>
321
* ExecType::NoCommit executes operations without
322
* committing them.<br>
323
* ExecType::Commit executes remaining operations and
324
* commits the complete transaction.<br>
325
* ExecType::Rollback rollbacks the entire transaction.
326
* @param abortOption Handling of error while excuting
327
* AbortOnError - Abort transaction if an operation fail
328
* AO_IgnoreError - Accept failing operations
329
* DefaultAbortOption - Use per-operation abort option
330
* @param force When operations should be sent to NDB Kernel.
331
* (See @ref secAdapt.)
332
* - 0: non-force, adaptive algorithm notices it
334
* - 1: force send, adaptive algorithm notices it;
335
* - 2: non-force, adaptive algorithm do not notice
337
* @return 0 if successful otherwise -1.
339
#ifndef NDBAPI_50_COMPAT
340
int execute(ExecType execType,
341
NdbOperation::AbortOption = NdbOperation::DefaultAbortOption,
343
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
344
int execute(::ExecType execType,
345
::AbortOption abortOption = ::DefaultAbortOption,
347
return execute ((ExecType)execType,
348
(NdbOperation::AbortOption)abortOption,
353
* 50 compability layer
354
* Check 50-docs for sematics
357
int execute(ExecType execType, NdbOperation::AbortOption, int force);
359
int execute(NdbTransaction::ExecType execType,
360
NdbTransaction::AbortOption abortOption = AbortOnError,
363
int ret = execute ((ExecType)execType,
364
(NdbOperation::AbortOption)abortOption,
366
if (ret || (abortOption != AO_IgnoreError && theError.code))
372
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
373
// to be documented later
375
* Prepare an asynchronous transaction.
377
* See @ref secAsync for more information on
378
* how to use this method.
380
* @param execType Execution type:<br>
381
* ExecType::NoCommit executes operations without committing them.<br>
382
* ExecType::Commit executes remaining operations and commits the
383
* complete transaction.<br>
384
* ExecType::Rollback rollbacks the entire transaction.
385
* @param callback A callback method. This method gets
386
* called when the transaction has been
387
* executed. See @ref ndbapi_async1.cpp
388
* for an example on how to specify and use
390
* @param anyObject A void pointer. This pointer is forwarded to the
391
* callback method and can be used to give
392
* the callback method some data to work on.
393
* It is up to the application programmer
394
* to decide on the use of this pointer.
395
* @param abortOption see @ref execute
397
#ifndef NDBAPI_50_COMPAT
398
void executeAsynchPrepare(ExecType execType,
399
NdbAsynchCallback callback,
401
NdbOperation::AbortOption = NdbOperation::DefaultAbortOption);
402
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
403
void executeAsynchPrepare(::ExecType execType,
404
NdbAsynchCallback callback,
406
::AbortOption ao = ::DefaultAbortOption) {
407
executeAsynchPrepare((ExecType)execType, callback, anyObject,
408
(NdbOperation::AbortOption)ao); }
412
* 50 compability layer
413
* Check 50-docs for sematics
415
void executeAsynchPrepare(ExecType execType,
416
NdbAsynchCallback callback,
418
NdbOperation::AbortOption);
420
void executeAsynchPrepare(NdbTransaction::ExecType execType,
421
NdbAsynchCallback callback,
423
NdbTransaction::AbortOption abortOption = NdbTransaction::AbortOnError)
425
executeAsynchPrepare((ExecType)execType, callback, anyObject,
426
(NdbOperation::AbortOption)abortOption);
431
* Prepare and send an asynchronous transaction.
433
* This method perform the same action as
434
* NdbTransaction::executeAsynchPrepare
435
* but also sends the operations to the NDB kernel.
437
* See NdbTransaction::executeAsynchPrepare for information
438
* about the parameters of this method.
440
* See @ref secAsync for more information on
441
* how to use this method.
443
#ifndef NDBAPI_50_COMPAT
444
void executeAsynch(ExecType aTypeOfExec,
445
NdbAsynchCallback aCallback,
447
NdbOperation::AbortOption = NdbOperation::DefaultAbortOption,
449
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
450
void executeAsynch(::ExecType aTypeOfExec,
451
NdbAsynchCallback aCallback,
453
::AbortOption abortOption= ::DefaultAbortOption,
455
{ executeAsynch((ExecType)aTypeOfExec, aCallback, anyObject,
456
(NdbOperation::AbortOption)abortOption, forceSend); }
460
* 50 compability layer
461
* Check 50-docs for sematics
463
void executeAsynch(ExecType aTypeOfExec,
464
NdbAsynchCallback aCallback,
466
NdbOperation::AbortOption = NdbOperation::DefaultAbortOption,
468
void executeAsynch(NdbTransaction::ExecType aTypeOfExec,
469
NdbAsynchCallback aCallback,
471
NdbTransaction::AbortOption abortOption = AbortOnError)
473
executeAsynch((ExecType)aTypeOfExec, aCallback, anyObject,
474
(NdbOperation::AbortOption)abortOption, 0);
481
* Update timeout counter of this transaction
482
* in the database. If you want to keep the transaction
483
* active in the database longer than the
484
* transaction abort timeout.
485
* @note It's not advised to take a lock on a record and keep it
486
* for a extended time since this can impact other transactions.
494
* @note Equivalent to to calling Ndb::closeTransaction()
496
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
498
* @note It is not allowed to call NdbTransaction::close after sending the
499
* transaction asynchronously before the callback method has
501
* (The application should keep track of the number of
502
* outstanding transactions and wait until all of them
503
* has completed before calling NdbTransaction::close).
504
* If the transaction is not committed it will be aborted.
509
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
511
* Restart transaction
513
* Once a transaction has been completed successfully
514
* it can be started again wo/ calling closeTransaction/startTransaction
516
* @note This method also releases completed operations
518
* @note This method does not close open scans,
519
* c.f. NdbScanOperation::close()
521
* @note This method can only be called _directly_ after commit
522
* and only if commit is successful
527
/** @} *********************************************************************/
530
* @name Meta Information
535
* Get global checkpoint identity (GCI) of transaction.
537
* Each committed transaction belong to a GCI.
538
* The log for the committed transaction is saved on
539
* disk when a global checkpoint occurs.
541
* Whether or not the global checkpoint with this GCI has been
542
* saved on disk or not cannot be determined by this method.
544
* By comparing the GCI of a transaction with the value
545
* last GCI restored in a restarted NDB Cluster one can determine
546
* whether the transaction was restored or not.
548
* @note Global Checkpoint Identity is undefined for scan transactions
549
* (This is because no updates are performed in scan transactions.)
551
* @return 0 if GCI is available, and stored in <em>gciptr</em>
552
-1 if GCI is not available.
553
* (Note that there has to be an NdbTransaction::execute call
554
* with Ndb::Commit for the GCI to be available.)
556
int getGCI(Uint64 * gciptr);
559
* Deprecated...in favor of getGCI(Uint64*)
564
* Get transaction identity.
566
* @return Transaction id.
568
Uint64 getTransactionId();
571
* The commit status of the transaction.
573
enum CommitStatusType {
574
NotStarted, ///< Transaction not yet started
575
Started, ///< <i>Missing explanation</i>
576
Committed, ///< Transaction has been committed
577
Aborted, ///< Transaction has been aborted
578
NeedAbort ///< <i>Missing explanation</i>
582
* Get the commit status of the transaction.
584
* @return The commit status of the transaction
586
CommitStatusType commitStatus();
588
/** @} *********************************************************************/
591
* @name Error Handling
596
* Get error object with information about the latest error.
598
* @return An error object with information about the latest error.
600
const NdbError & getNdbError() const;
603
* Get the latest NdbOperation which had an error.
604
* This method is used on the NdbTransaction object to find the
605
* NdbOperation causing an error.
606
* To find more information about the
607
* actual error, use method NdbOperation::getNdbError()
608
* on the returned NdbOperation object.
610
* @return The NdbOperation causing the latest error.
611
* @deprecated Use the const NdbOperation returning variant.
613
NdbOperation* getNdbErrorOperation();
616
* Get the latest NdbOperation which had an error.
617
* This method is used on the NdbTransaction object to find the
618
* NdbOperation causing an error.
619
* To find more information about the
620
* actual error, use method NdbOperation::getNdbError()
621
* on the returned NdbOperation object.
623
* @return The NdbOperation causing the latest error.
625
const NdbOperation* getNdbErrorOperation() const;
628
* Get the method number where the latest error occured.
630
* @return Line number where latest error occured.
632
int getNdbErrorLine();
635
* Get completed (i.e. executed) operations of a transaction
637
* This method should only be used <em>after</em> a transaction
639
* - NdbTransaction::getNextCompletedOperation(NULL) returns the
640
* first NdbOperation object.
641
* - NdbTransaction::getNextCompletedOperation(op) returns the
642
* NdbOperation object defined after the NdbOperation "op".
644
* This method is typically used to fetch all NdbOperation:s of
645
* a transaction to check for errors (use NdbOperation::getNdbError
646
* to fetch the NdbError object of an NdbOperation).
648
* @note This method should only be used after the transaction has been
649
* executed and before the transaction has been closed.
651
* @param op Operation, NULL means get first operation
652
* @return Operation "after" op
654
const NdbOperation * getNextCompletedOperation(const NdbOperation * op)const;
656
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
657
const NdbOperation* getFirstDefinedOperation()const{return theFirstOpInList;}
658
const NdbOperation* getLastDefinedOperation()const{return theLastOpInList;}
660
/** @} *********************************************************************/
663
* Execute the transaction in NoCommit mode if there are any not-yet
664
* executed blob part operations of given types. Otherwise do
665
* nothing. The flags argument is bitwise OR of (1 << optype) where
666
* optype comes from NdbOperation::OperationType. Only the basic PK
667
* ops are used (read, insert, update, delete).
669
int executePendingBlobOps(Uint8 flags = 0xFF);
672
* Get nodeId of TC for this transaction
674
Uint32 getConnectedNodeId(); // Get Connected node id
678
* NdbRecord primary key and unique key operations.
680
* If the key_rec passed in is for a table, the operation will be a primary
681
* key operation. If it is for an index, it will be a unique key operation
684
* The key_row passed in defines the primary or unique key of the affected
685
* tuple, and must remain valid until execute() is called. The key_rec must
686
* include all columns of the key.
688
* The mask, if != NULL, defines a subset of attributes to read, update, or
689
* insert. Only if (mask[attrId >> 3] & (1<<(attrId & 7))) is set is the
690
* column affected. The mask is copied by the methods, so need not remain
691
* valid after the call returns.
693
* For unique index operations, the attr_rec must refer to the underlying
694
* table of the index.
696
* OperationOptions can be used to give finer-grained control of operation
697
* definition. An OperationOptions structure is passed with flags
698
* indicating which operation definition options are present. Not all
699
* operation types support all operation options. See the definition of
700
* the OperationOptions structure for more information on individual options.
702
* Operation type Supported OperationOptions flags
703
* -------------- --------------------------------
704
* readTuple OO_ABORTOPTION, OO_GETVALUE,
705
* OO_PARTITION_ID, OO_INTERPRETED
706
* insertTuple OO_ABORTOPTION, OO_SETVALUE,
707
* OO_PARTITION_ID, OO_ANYVALUE
708
* updateTuple OO_ABORTOPTION, OO_SETVALUE,
709
* OO_PARTITION_ID, OO_INTERPRETED,
711
* writeTuple OO_ABORTOPTION, OO_SETVALUE,
712
* OO_PARTITION_ID, OO_ANYVALUE
713
* deleteTuple OO_ABORTOPTION, OO_GETVALUE,
714
* OO_PARTITION_ID, OO_INTERPRETED,
717
* The sizeOfOptions optional parameter is used to allow this interface
718
* to be backwards compatible with previous definitions of the OperationOptions
719
* structure. If an unusual size is detected by the interface implementation,
720
* it can use this to determine how to interpret the passed OperationOptions
721
* structure. To enable this functionality, the caller should pass
722
* sizeof(NdbOperation::OperationOptions) for this argument.
724
const NdbOperation *readTuple(const NdbRecord *key_rec, const char *key_row,
725
const NdbRecord *result_rec, char *result_row,
726
NdbOperation::LockMode lock_mode= NdbOperation::LM_Read,
727
const unsigned char *result_mask= 0,
728
const NdbOperation::OperationOptions *opts = 0,
729
Uint32 sizeOfOptions = 0);
730
const NdbOperation *insertTuple(const NdbRecord *key_rec, const char *key_row,
731
const NdbRecord *attr_rec, const char *attr_row,
732
const unsigned char *mask= 0,
733
const NdbOperation::OperationOptions *opts = 0,
734
Uint32 sizeOfOptions = 0);
735
const NdbOperation *insertTuple(const NdbRecord *combined_rec, const char *combined_row,
736
const unsigned char *mask = 0,
737
const NdbOperation::OperationOptions *opts = 0,
738
Uint32 sizeOfOptions = 0);
739
const NdbOperation *updateTuple(const NdbRecord *key_rec, const char *key_row,
740
const NdbRecord *attr_rec, const char *attr_row,
741
const unsigned char *mask= 0,
742
const NdbOperation::OperationOptions *opts = 0,
743
Uint32 sizeOfOptions = 0);
744
const NdbOperation *writeTuple(const NdbRecord *key_rec, const char *key_row,
745
const NdbRecord *attr_rec, const char *attr_row,
746
const unsigned char *mask= 0,
747
const NdbOperation::OperationOptions *opts = 0,
748
Uint32 sizeOfOptions = 0);
749
const NdbOperation *deleteTuple(const NdbRecord *key_rec, const char *key_row,
750
const NdbRecord *result_rec, char *result_row = 0,
751
const unsigned char *result_mask = 0,
752
const NdbOperation::OperationOptions *opts = 0,
753
Uint32 sizeOfOptions = 0);
755
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
756
const NdbOperation *refreshTuple(const NdbRecord *key_rec, const char *key_row,
757
const NdbOperation::OperationOptions *opts = 0,
758
Uint32 sizeOfOptions = 0);
762
* Scan a table, using NdbRecord to read out column data.
764
* The NdbRecord pointed to by result_record must remain valid until
765
* the scan operation is closed.
767
* The result_mask pointer is optional, if present only columns for
768
* which the corresponding bit (by attribute id order) in result_mask
769
* is set will be retrieved in the scan. The result_mask is copied
770
* internally, so in contrast to result_record need not be valid at
773
* A ScanOptions structure can be passed, specifying extra options. See
774
* the definition of the NdbScanOperation::ScanOptions structure for
777
* To enable backwards compatability of this interface, a sizeOfOptions
778
* parameter can be passed. This parameter indicates the size of the
779
* ScanOptions structure at the time the client was compiled, and enables
780
* detection of the use of an old ScanOptions structure. If this
781
* functionality is not required, it can be left set to zero.
784
scanTable(const NdbRecord *result_record,
785
NdbOperation::LockMode lock_mode= NdbOperation::LM_Read,
786
const unsigned char *result_mask= 0,
787
const NdbScanOperation::ScanOptions *options = 0,
788
Uint32 sizeOfOptions = 0);
791
* Do an index range scan (optionally ordered) of a table.
793
* The key_record describes the index to be scanned. It must be a key record
794
* for the index, ie. it must specify (at least) all the key columns of the
795
* index. And it must be created from the index to be scanned (not from the
798
* The result_record describes the rows to be returned from the scan. For an
799
* ordered index scan, result_record must be a key record for the index to
800
* be scanned, that is it must include at least all of the columns in the
801
* index (the reason is that the full index key is needed by NDBAPI for merge
802
* sorting the ordered rows returned from each fragment). The result_record
803
* must be created from the underlying table, not from the index to be scanned.
805
* Both the key_record and result_record NdbRecord structures must stay
806
* in-place until the scan operation is closed.
808
* A single IndexBound can either be specified in this call or in a separate
809
* call to NdbIndexScanOperation::setBound(). To perform a multi range read,
810
* the scan_flags in the ScanOptions structure must include SF_MULTIRANGE.
811
* Additional bounds can then be added using multiple calls to
812
* NdbIndexScanOperation::setBound().
814
* To specify an equals bound, use the same row pointer for the low_key and
815
* high_key with the low and high inclusive bits set.
817
* A ScanOptions structure can be passed, specifying extra options. See
818
* the definition of the ScanOptions structure for more information.
820
* To enable backwards compatability of this interface, a sizeOfOptions
821
* parameter can be passed. This parameter indicates the size of the
822
* ScanOptions structure at the time the client was compiled, and enables
823
* detection of the use of an old ScanOptions structure. If this functionality
824
* is not required, it can be left set to zero.
827
NdbIndexScanOperation *
828
scanIndex(const NdbRecord *key_record,
829
const NdbRecord *result_record,
830
NdbOperation::LockMode lock_mode = NdbOperation::LM_Read,
831
const unsigned char *result_mask = 0,
832
const NdbIndexScanOperation::IndexBound *bound = 0,
833
const NdbScanOperation::ScanOptions *options = 0,
834
Uint32 sizeOfOptions = 0);
837
* Add a prepared NdbQueryDef to transaction for execution.
839
* If the NdbQueryDef contains parameters,
840
* (built with NdbQueryBilder::paramValue()) the value of these
841
* parameters are specified in the 'paramValue' array. Parameter values
842
* Should be supplied in the same order as the related paramValue's
846
createQuery(const NdbQueryDef* query,
847
const NdbQueryParamValue paramValue[]= 0,
848
NdbOperation::LockMode lock_mode= NdbOperation::LM_Read);
850
/* LockHandle methods */
852
* Shared or Exclusive locks taken by read operations in a transaction
853
* are normally held until the transaction commits or aborts.
854
* Shared or Exclusive *read* locks can be released before transaction
855
* commit or abort time by requesting a LockHandle when defining the
856
* read operation. Any time after the read operation has been executed,
857
* the LockHandle can be used to create a new Unlock operation. When
858
* the Unlock operation is executed, the row lock placed by the read
859
* operation will be released.
862
* 1) Define the primary key read operation in the normal way
863
* with lockmode LM_Read or LM_Exclusive
865
* 2) Call NdbOperation::getLockHandle() during operation definition
866
* (Or set the OO_LOCKHANDLE operation option when calling
867
* NdbTransaction::readTuple() for NdbRecord)
869
* 3) Call NdbTransaction::execute()
870
* (Row will be locked from here as normal)
872
* 4) Use the read data, make zero or more calls to
873
* NdbTransaction::execute() etc.
875
* 5) Call NdbTransaction::unlock(NdbLockHandle*), passing in the
876
* const LockHandle* from 2) to create an Unlock operation.
878
* 6) Call NdbTransaction::execute()
879
* (Row will be unlocked from here)
882
* - As with other operation types, Unlock operations can be batched.
883
* - Each LockHandle object refers to a lock placed on a row by a single
884
* primary key read operation. A single row in the database may have
885
* concurrent multiple lock holders (of mode LM_Read) and may have
886
* multiple lock holders pending (LM_Exclusive), so releasing the
887
* claim of one lock holder may not result in a change to the
888
* observable lock status of the row.
889
* - LockHandles are supported for Scan lock takeover operations - the
890
* lockhandle must be requested before the locktakeover is executed.
891
* - LockHandles and Unlock operations are not supported for Unique Index
897
* This method creates an Unlock operation on the current transaction.
898
* When executed, the Unlock operation will remove the lock referenced
899
* by the passed LockHandle.
901
* The unlock operation can fail, for example due to the row being
902
* unlocked already. In this scenario, the AbortOption specifies how
903
* this will be handled.
904
* The default is that errors will cause transaction abort.
906
const NdbOperation* unlock(const NdbLockHandle* lockHandle,
907
NdbOperation::AbortOption ao = NdbOperation::DefaultAbortOption);
910
* This method is used to release a LockHandle object once it
911
* is no longer required.
912
* For NdbRecord primary key read operations, this cannot be
913
* called until the associated read operation has executed.
914
* All LockHandles associated with a transaction are released
917
int releaseLockHandle(const NdbLockHandle* lockHandle);
919
/* Get maximum number of pending Blob read/write bytes before
920
* an automatic execute() occurs
922
Uint32 getMaxPendingBlobReadBytes() const;
923
Uint32 getMaxPendingBlobWriteBytes() const;
925
/* Set maximum number of pending Blob read/write bytes before
926
* an automatic execute() occurs
928
void setMaxPendingBlobReadBytes(Uint32 bytes);
929
void setMaxPendingBlobWriteBytes(Uint32 bytes);
933
* Release completed operations
935
void releaseCompletedOperations();
936
void releaseCompletedQueries();
938
typedef Uint64 TimeMillis_t;
939
/**************************************************************************
940
* These methods are service methods to other classes in the NDBAPI. *
941
**************************************************************************/
943
/**************************************************************************
944
* These are the create and delete methods of this class. *
945
**************************************************************************/
946
NdbTransaction(Ndb* aNdb);
949
int init(); // Initialize connection object for new transaction
951
int executeNoBlobs(ExecType execType,
952
NdbOperation::AbortOption = NdbOperation::DefaultAbortOption,
956
* Set Connected node id
959
void setConnectedNodeId( Uint32 nodeId, Uint32 sequence);
961
void setMyBlockReference( int ); // Set my block refrerence
962
void setTC_ConnectPtr( Uint32 ); // Sets TC Connect pointer
963
int getTC_ConnectPtr(); // Gets TC Connect pointer
964
void setBuddyConPtr(Uint32); // Sets Buddy Con Ptr
965
Uint32 getBuddyConPtr(); // Gets Buddy Con Ptr
966
NdbTransaction* next(); // Returns the next pointer
967
void next(NdbTransaction*); // Sets the next pointer
976
ConStatusType Status(); // Read the status information
977
void Status(ConStatusType); // Set the status information
979
Uint32 get_send_size(); // Get size to send
980
void set_send_size(Uint32); // Set size to send;
982
int receiveTCSEIZECONF(const NdbApiSignal* anApiSignal);
983
int receiveTCSEIZEREF(const NdbApiSignal* anApiSignal);
984
int receiveTCRELEASECONF(const NdbApiSignal* anApiSignal);
985
int receiveTCRELEASEREF(const NdbApiSignal* anApiSignal);
986
int receiveTC_COMMITCONF(const class TcCommitConf *, Uint32 len);
987
int receiveTCKEYCONF(const class TcKeyConf *, Uint32 aDataLength);
988
int receiveTCKEY_FAILCONF(const class TcKeyFailConf *);
989
int receiveTCKEY_FAILREF(const NdbApiSignal* anApiSignal);
990
int receiveTC_COMMITREF(const NdbApiSignal* anApiSignal);
991
int receiveTCROLLBACKCONF(const NdbApiSignal* anApiSignal);
992
int receiveTCROLLBACKREF(const NdbApiSignal* anApiSignal);
993
int receiveTCROLLBACKREP(const NdbApiSignal* anApiSignal);
994
int receiveTCINDXREF(const NdbApiSignal*);
995
int receiveSCAN_TABREF(const NdbApiSignal*);
996
int receiveSCAN_TABCONF(const NdbApiSignal*, const Uint32*, Uint32 len);
998
int doSend(); // Send all operations
999
int sendROLLBACK(); // Send of an ROLLBACK
1000
int sendTC_HBREP(); // Send a TCHBREP signal;
1001
int sendCOMMIT(); // Send a TC_COMMITREQ signal;
1002
void setGCI(int GCI); // Set the global checkpoint identity
1004
int OpCompleteFailure();
1005
int OpCompleteSuccess();
1007
void OpSent(); // Operation Sent with success
1009
// Free connection related resources and close transaction
1012
// Release all operations in connection
1013
void releaseOperations();
1015
// Release all cursor operations in connection
1016
void releaseOps(NdbOperation*);
1017
void releaseQueries(NdbQueryImpl*);
1018
void releaseScanOperations(NdbIndexScanOperation*);
1019
bool releaseScanOperation(NdbIndexScanOperation** listhead,
1020
NdbIndexScanOperation** listtail,
1021
NdbIndexScanOperation* op);
1022
void releaseLockHandles();
1024
// Set the transaction identity of the transaction
1025
void setTransactionId(Uint64 aTransactionId);
1027
// Indicate something went wrong in the definition phase
1028
void setErrorCode(int anErrorCode);
1030
// Indicate something went wrong in the definition phase
1031
void setOperationErrorCode(int anErrorCode);
1033
// Indicate something went wrong in the definition phase
1034
void setOperationErrorCodeAbort(int anErrorCode, int abortOption = -1);
1036
int checkMagicNumber(); // Verify correct object
1037
NdbOperation* getNdbOperation(const class NdbTableImpl* aTable,
1038
NdbOperation* aNextOp = 0,
1039
bool useRec= false);
1041
NdbIndexScanOperation* getNdbScanOperation(const class NdbTableImpl* aTable);
1042
NdbIndexOperation* getNdbIndexOperation(const class NdbIndexImpl* anIndex,
1043
const class NdbTableImpl* aTable,
1044
NdbOperation* aNextOp = 0,
1045
bool useRec= false);
1046
NdbIndexScanOperation* getNdbIndexScanOperation(const NdbIndexImpl* index,
1047
const NdbTableImpl* table);
1049
NdbOperation *setupRecordOp(NdbOperation::OperationType type,
1050
NdbOperation::LockMode lock_mode,
1051
NdbOperation::AbortOption default_ao,
1052
const NdbRecord *key_record,
1053
const char *key_row,
1054
const NdbRecord *attribute_record,
1055
const char *attribute_row,
1056
const unsigned char *mask,
1057
const NdbOperation::OperationOptions *opts,
1058
Uint32 sizeOfOptions,
1059
const NdbLockHandle* lh = 0);
1061
void handleExecuteCompletion();
1063
/****************************************************************************
1064
* These are the private variables of this class.
1065
****************************************************************************/
1070
// Keeps track of what the send method should do.
1071
enum SendStatusType {
1083
SendStatusType theSendStatus;
1084
NdbAsynchCallback theCallbackFunction; // Pointer to the callback function
1085
void* theCallbackObject; // The callback object pointer
1086
Uint32 theTransArrayIndex; // Current index in a transaction
1087
// array for this object
1088
TimeMillis_t theStartTransTime; // Start time of the transaction
1090
NdbError theError; // Errorcode on transaction
1091
int theErrorLine; // Method number of last error in NdbOperation
1092
NdbOperation* theErrorOperation; // The NdbOperation where the error occurred
1094
Ndb* theNdb; // Pointer to Ndb object
1095
NdbTransaction* theNext; // Next pointer. Used in idle list.
1097
NdbOperation* theFirstOpInList; // First operation in defining list.
1098
NdbOperation* theLastOpInList; // Last operation in defining list.
1100
NdbOperation* theFirstExecOpInList; // First executing operation in list
1101
NdbOperation* theLastExecOpInList; // Last executing operation in list.
1104
NdbOperation* theCompletedFirstOp; // First & last operation in completed
1105
NdbOperation* theCompletedLastOp; // operation list.
1107
Uint32 theNoOfOpSent; // How many operations have been sent
1108
Uint32 theNoOfOpCompleted; // How many operations have completed
1109
Uint32 theMyRef; // Our block reference
1110
Uint32 theTCConPtr; // Transaction Co-ordinator connection pointer.
1111
Uint64 theTransactionId; // theTransactionId of the transaction
1112
Uint64 theGlobalCheckpointId; // The gloabl checkpoint identity of the transaction
1113
Uint64 *p_latest_trans_gci; // Reference to latest gci for connection
1114
ConStatusType theStatus; // The status of the connection
1115
enum CompletionStatus {
1120
} theCompletionStatus; // The Completion status of the transaction
1121
CommitStatusType theCommitStatus; // The commit status of the transaction
1122
Uint32 theMagicNumber; // Magic Number to verify correct object
1123
// Current meanings :
1124
// 0x00FE11DC : NdbTransaction not in use
1125
// 0x37412619 : NdbTransaction in use
1126
// 0x00FE11DF : NdbTransaction for scan operation
1127
// scan definition not yet complete
1128
Uint32 thePriority; // Transaction Priority
1130
enum ReturnType { ReturnSuccess, ReturnFailure };
1131
ReturnType theReturnStatus; // Did we have any read/update/delete failing
1132
// to find the tuple.
1133
bool theTransactionIsStarted;
1135
bool theSimpleState;
1144
Uint32 theDBnode; // The database node we are connected to
1145
Uint32 theNodeSequence; // The sequence no of the db node
1146
bool theReleaseOnClose;
1149
* handle transaction spanning
1150
* multiple TC/db nodes
1152
* 1) Bitmask with used nodes
1153
* 2) Bitmask with nodes failed during op
1155
Uint32 m_db_nodes[2];
1156
Uint32 m_failed_db_nodes[2];
1158
int report_node_failure(Uint32 id);
1161
bool m_waitForReply;
1162
NdbIndexScanOperation* m_theFirstScanOperation;
1163
NdbIndexScanOperation* m_theLastScanOperation;
1165
NdbIndexScanOperation* m_firstExecutedScanOp;
1167
// Scan operations or queries:
1168
// The operation or query actually performing the scan.
1169
// (Only one of theScanningOp/m_scanningQuery be non-NULL,
1170
// which indirectly indicates the type)
1171
NdbScanOperation* theScanningOp;
1173
Uint32 theBuddyConPtr;
1176
Uint8 thePendingBlobOps;
1177
Uint32 maxPendingBlobReadBytes;
1178
Uint32 maxPendingBlobWriteBytes;
1179
Uint32 pendingBlobReadBytes;
1180
Uint32 pendingBlobWriteBytes;
1181
inline bool hasBlobOperation() { return theBlobFlag; }
1183
static void sendTC_COMMIT_ACK(class NdbImpl *, NdbApiSignal *,
1184
Uint32 transId1, Uint32 transId2,
1187
void completedFail(const char * s);
1191
bool checkState_TransId(const Uint32 * transId) const;
1193
void remove_list(NdbOperation*& head, NdbOperation*);
1194
void define_scan_op(NdbIndexScanOperation*);
1196
NdbLockHandle* m_theFirstLockHandle;
1197
NdbLockHandle* m_theLastLockHandle;
1199
NdbLockHandle* getLockHandle();
1201
friend class HugoOperations;
1202
friend struct Ndb_free_list_t<NdbTransaction>;
1204
NdbTransaction(const NdbTransaction&); // Not impl.
1205
NdbTransaction&operator=(const NdbTransaction&);
1207
// Query operation (aka multicursor)
1208
NdbQueryImpl* m_firstQuery; // First query in defining list.
1209
NdbQueryImpl* m_firstExecQuery; // First query to send for execution
1210
NdbQueryImpl* m_firstActiveQuery; // First query actively executing, or completed
1212
// Scan operations or queries:
1213
// The operation or query actually performing the scan.
1214
// (Only one of theScanningOp/m_scanningQuery be non-NULL,
1215
// which indirectly indicates the type)
1216
NdbQueryImpl* m_scanningQuery;
1221
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1225
NdbTransaction::get_send_size()
1232
NdbTransaction::set_send_size(Uint32 send_size)
1234
(void)send_size; //unused
1238
#ifdef NDB_NO_DROPPED_SIGNAL
1244
NdbTransaction::checkMagicNumber()
1246
if (theMagicNumber == 0x37412619)
1249
#ifdef NDB_NO_DROPPED_SIGNAL
1258
NdbTransaction::checkState_TransId(const Uint32 * transId) const {
1259
const Uint32 tTmp1 = transId[0];
1260
const Uint32 tTmp2 = transId[1];
1261
Uint64 tRecTransId = (Uint64)tTmp1 + ((Uint64)tTmp2 << 32);
1262
bool b = theStatus == Connected && theTransactionId == tRecTransId;
1266
/************************************************************************************************
1267
void setTransactionId(Uint64 aTransactionId);
1269
Remark: Set the transaction identity.
1270
************************************************************************************************/
1273
NdbTransaction::setTransactionId(Uint64 aTransactionId)
1275
theTransactionId = aTransactionId;
1280
NdbTransaction::setConnectedNodeId(Uint32 aNode, Uint32 aSequenceNo)
1283
theNodeSequence = aSequenceNo;
1285
/******************************************************************************
1286
int getConnectedNodeId();
1288
Return Value: Return theDBnode.
1289
Remark: Get Connected node id.
1290
******************************************************************************/
1293
NdbTransaction::getConnectedNodeId()
1297
/******************************************************************************
1298
void setMyBlockReference(int aBlockRef);
1300
Parameters: aBlockRef: The block refrerence.
1301
Remark: Set my block refrerence.
1302
******************************************************************************/
1305
NdbTransaction::setMyBlockReference(int aBlockRef)
1307
theMyRef = aBlockRef;
1309
/******************************************************************************
1310
void setTC_ConnectPtr(Uint32 aTCConPtr);
1312
Parameters: aTCConPtr: The connection pointer.
1313
Remark: Sets TC Connect pointer.
1314
******************************************************************************/
1317
NdbTransaction::setTC_ConnectPtr(Uint32 aTCConPtr)
1319
theTCConPtr = aTCConPtr;
1322
/******************************************************************************
1323
int getTC_ConnectPtr();
1325
Return Value: Return theTCConPtr.
1326
Remark: Gets TC Connect pointer.
1327
******************************************************************************/
1330
NdbTransaction::getTC_ConnectPtr()
1337
NdbTransaction::setBuddyConPtr(Uint32 aBuddyConPtr)
1339
theBuddyConPtr = aBuddyConPtr;
1343
Uint32 NdbTransaction::getBuddyConPtr()
1345
return theBuddyConPtr;
1348
/******************************************************************************
1349
NdbTransaction* next();
1353
NdbTransaction::setBuddyConPtr(Uint32 aBuddyConPtr)
1355
theBuddyConPtr = aBuddyConPtr;
1359
Uint32 NdbTransaction::getBuddyConPtr()
1361
return theBuddyConPtr;
1364
Return Value: Return next pointer to NdbTransaction object.
1365
Remark: Get the next pointer.
1366
******************************************************************************/
1369
NdbTransaction::next()
1374
/******************************************************************************
1375
void next(NdbTransaction aTransaction);
1377
Parameters: aTransaction: The connection object.
1378
Remark: Sets the next pointer.
1379
******************************************************************************/
1382
NdbTransaction::next(NdbTransaction* aTransaction)
1384
theNext = aTransaction;
1387
/******************************************************************************
1388
ConStatusType Status();
1390
Return Value Return the ConStatusType.
1391
Parameters: aStatus: The status.
1392
Remark: Sets Connect status.
1393
******************************************************************************/
1395
NdbTransaction::ConStatusType
1396
NdbTransaction::Status()
1401
/******************************************************************************
1402
void Status(ConStatusType aStatus);
1404
Parameters: aStatus: The status.
1405
Remark: Sets Connect status.
1406
******************************************************************************/
1409
NdbTransaction::Status( ConStatusType aStatus )
1411
theStatus = aStatus;
1415
/******************************************************************************
1418
Remark: An operation was sent with success that expects a response.
1419
******************************************************************************/
1422
NdbTransaction::OpSent()
1427
/******************************************************************************
1428
void executePendingBlobOps();
1429
******************************************************************************/
1432
NdbTransaction::executePendingBlobOps(Uint8 flags)
1434
if (thePendingBlobOps & flags) {
1435
// not executeNoBlobs because there can be new ops with blobs
1436
return execute(NoCommit);
1443
NdbTransaction::ptr2int(){
1447
typedef NdbTransaction NdbConnection;
1449
#endif // ifndef DOXYGEN_SHOULD_SKIP_INTERNAL