📄 ndb.hpp
字号:
class NdbTransaction;class NdbApiSignal;class NdbRecAttr;class NdbLabel;class NdbBranch;class NdbSubroutine;class NdbCall;class Table;class BaseString;class NdbBlob;class NdbReceiver;class Ndb_local_table_info;template <class T> struct Ndb_free_list_t;#if defined NDB_OSE/** * Default time to wait for response after request has been sent to * NDB Cluster (Set to 10 seconds usually, but to 100 s in * the OSE operating system) */#define WAITFOR_RESPONSE_TIMEOUT 100000 // Milliseconds#else#define WAITFOR_RESPONSE_TIMEOUT 120000 // Milliseconds#endif/** * @class Ndb * @brief Represents the NDB kernel and is the main class of the NDB API. * * Always start your application program by creating an Ndb object. * By using several Ndb objects it is possible to design * a multi-threaded application, but note that Ndb objects * cannot be shared by several threads. * Different threads should use different Ndb objects. * A thread might however use multiple Ndb objects. * Currently there is a limit of maximum 128 Ndb objects * per application process. * * @note It is not allowed to call methods in the NDB API * on the same Ndb object in different threads * simultaneously (without special handling of the * Ndb object). * * @note The Ndb object is multi-thread safe in the following manner. * Each Ndb object can ONLY be handled in one thread. * If an Ndb object is handed over to another thread then the * application must ensure that a memory barrier is used to * ensure that the new thread see all updates performed by * the previous thread. * Semaphores, mutexes and so forth are easy ways of issuing memory * barriers without having to bother about the memory barrier concept. * */#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL// to be documented later/* * If one Ndb object is used to handle parallel transactions through the * asynchronous programming interface, please read the notes regarding * asynchronous transactions (Section @ref secAsync). * The asynchronous interface provides much higher performance * in some situations, but is more complicated for the application designer. * * @note Each Ndb object should either use the methods for * asynchronous transaction or the methods for * synchronous transactions but not both. */#endifclass Ndb{#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL friend class NdbReceiver; friend class NdbOperation; friend class NdbTransaction; friend class Table; friend class NdbApiSignal; friend class NdbIndexOperation; friend class NdbScanOperation; friend class NdbIndexScanOperation; friend class NdbDictionaryImpl; friend class NdbDictInterface; friend class NdbBlob; friend class NdbImpl; friend class NdbScanFilterImpl;#endifpublic: /** * @name General * @{ */ /** * The Ndb object represents a connection to a database. * * @note The init() method must be called before the Ndb object may actually be used. * * @param ndb_cluster_connection is a connection to the cluster containing * the database to be used * @param aCatalogName is the name of the catalog to be used. * @note The catalog name provides a namespace for the tables and * indexes created in any connection from the Ndb object. * @param aSchemaName is the name of the schema you * want to use. * @note The schema name provides an additional namespace * for the tables and indexes created in a given catalog. */ Ndb(Ndb_cluster_connection *ndb_cluster_connection, const char* aCatalogName = "", const char* aSchemaName = "def"); ~Ndb();#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL /** * The current catalog name can be fetched by getCatalogName. * * @return the current catalog name */ const char * getCatalogName() const; /** * The current catalog name can be set by setCatalogName. * * @param aCatalogName is the new name of the current catalog */ int setCatalogName(const char * aCatalogName); /** * The current schema name can be fetched by getSchemaName. * * @return the current schema name */ const char * getSchemaName() const; /** * The current schema name can be set by setSchemaName. * * @param aSchemaName is the new name of the current schema */ int setSchemaName(const char * aSchemaName);#endif /** * The current database name can be fetched by getDatabaseName. * * @return the current database name */ const char * getDatabaseName() const; /** * The current database name can be set by setDatabaseName. * * @param aDatabaseName is the new name of the current database */ int setDatabaseName(const char * aDatabaseName); /** * The current database schema name can be fetched by getDatabaseSchemaName. * * @return the current database schema name */ const char * getDatabaseSchemaName() const; /** * The current database schema name can be set by setDatabaseSchemaName. * * @param aDatabaseSchemaName is the new name of the current database schema */ int setDatabaseSchemaName(const char * aDatabaseSchemaName); /** * Initializes the Ndb object * * @param maxNoOfTransactions * Maximum number of parallel * NdbTransaction objects that can be handled by the Ndb object. * Maximum value is 1024. * * @note each scan or index scan operation uses one extra * NdbTransaction object * * @return 0 if successful, -1 otherwise. */ int init(int maxNoOfTransactions = 4);#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED /** * Wait for Ndb object to successfully set-up connections to * the NDB kernel. * Starting to use the Ndb object without using this method * gives unspecified behavior. * * @param timeout The maximum time we will wait for * the initiation process to finish. * Timeout is expressed in seconds. * @return 0: Ndb is ready and timeout has not occurred.<br> * -1: Timeout has expired */ int waitUntilReady(int timeout = 60);#endif /** @} *********************************************************************/ /** * @name Meta Information * @{ */ /** * Get an object for retrieving or manipulating database schema information * * @note this object operates outside any transaction * * @return Object containing meta information about all tables * in NDB Cluster. */ class NdbDictionary::Dictionary* getDictionary() const; /** @} *********************************************************************/ /** * @name Starting and Closing Transactions * @{ */ /** * Start a transaction * * @note When the transaction is completed it must be closed using * Ndb::closeTransaction or NdbTransaction::close. * The transaction must be closed independent of its outcome, i.e. * even if there is an error. * * @param table Pointer to table object used for deciding * which node to run the Transaction Coordinator on * @param keyData Pointer to partition key corresponding to * <var>table</var> * @param keyLen Length of partition key expressed in bytes * * @return NdbTransaction object, or NULL on failure. */ NdbTransaction* startTransaction(const NdbDictionary::Table *table= 0, const char *keyData = 0, Uint32 keyLen = 0); /** * Close a transaction. * * @note should be called after the transaction has completed, irrespective * of success or failure */#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL /** * @note It is not allowed to call Ndb::closeTransaction after sending the * transaction asynchronously with either * Ndb::sendPreparedTransactions or * Ndb::sendPollNdb before the callback method has been called. * (The application should keep track of the number of * outstanding transactions and wait until all of them * has completed before calling Ndb::closeTransaction). * If the transaction is not committed it will be aborted. */#endif void closeTransaction(NdbTransaction*); /** @} *********************************************************************/#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL // to be documented later /** * @name Asynchronous Transactions * @{ */ /** * Wait for prepared transactions. * Will return as soon as at least 'minNoOfEventsToWakeUp' * of them have completed, or the maximum time given as timeout has passed. * * @param aMillisecondNumber * Maximum time to wait for transactions to complete. Polling * without wait is achieved by setting the timer to zero. * Time is expressed in milliseconds. * @param minNoOfEventsToWakeup Minimum number of transactions * which has to wake up before the poll-call will return. * If minNoOfEventsToWakeup is * set to a value larger than 1 then this is the minimum * number of transactions that need to complete before the * poll will return. * Setting it to zero means that one should wait for all * outstanding transactions to return before waking up. * @return Number of transactions polled. */ int pollNdb(int aMillisecondNumber = WAITFOR_RESPONSE_TIMEOUT, int minNoOfEventsToWakeup = 1); /** * This send method will send all prepared database operations. * The default method is to do it non-force and instead * use the adaptive algorithm. (See Section @ref secAdapt.) * The second option is to force the sending and * finally there is the third alternative which is * also non-force but also making sure that the * adaptive algorithm do not notice the send. * In this case the sending will be performed on a * cyclical 10 millisecond event. * * @param forceSend When operations should be sent to NDB Kernel. * (See @ref secAdapt.) * - 0: non-force, adaptive algorithm notices it (default); * - 1: force send, adaptive algorithm notices it; * - 2: non-force, adaptive algorithm do not notice the send. */ void sendPreparedTransactions(int forceSend = 0); /** * This is a send-poll variant that first calls * Ndb::sendPreparedTransactions and then Ndb::pollNdb. * It is however somewhat faster than calling the methods * separately, since some mutex-operations are avoided. * See documentation of Ndb::pollNdb and Ndb::sendPreparedTransactions
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -