2.3.15 The Ndb Class

2.3.15.1 Ndb Methods

Abstract

This class represents the NDB kernel; it is the primary class of the NDB API.

Parent class.  None

Child classes.  None

Description.  Any nontrivial NDB API program makes use of at least one instance of Ndb. By using several Ndb objects, it is possible to implement a multi-threaded application. You should remember that one Ndb object cannot be shared between threads; however, it is possible for a single thread to use multiple Ndb objects. A single application process can support a maximum of 4711 Ndb objects.

Resource consumption by Ndb objects.  An Ndb object consumes memory in proportion to the size of the largest operation performed over the lifetime of the object. This is particularly noticeable in cases of large transactions; use of one or both of BLOB or TEXT columns; or both. This memory is held for the lifetime of the object, and once used in this way by the Ndb object, the only way to free this memory is to destroy the object (and then to create a new instance if desired).

Note

The Ndb object is multi-thread safe in that each Ndb object can be handled by one thread at a time. 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 sees all updates performed by the previous thread.

Semaphores and mutexes are examples of easy ways to provide memory barriers without having to bother about the memory barrier concept.

It is also possible to use multiple Ndb objects to perform operations on different clusters in a single application. See Application-level partitioning, for conditions and restrictions applying to such usage.

Methods.  The following table lists the public methods of this class and the purpose or use of each method:

MethodPurpose / Use
Ndb()Class constructor; represents a connection to a MySQL Cluster.
~Ndb()Class destructor; terminates a Cluster connection when it is no longer to be used
closeTransaction()Closes a transaction.
computeHash()Computes a distribution hash value.
createEventOperation()Creates a subscription to a database event. (See Section 2.3.20, “The NdbEventOperation Class”.)
dropEventOperation()Drops a subscription to a database event.
getDictionary()Gets a dictionary, which is used for working with database schema information.
getDatabaseName()Gets the name of the current database.
getDatabaseSchemaName()Gets the name of the current database schema.
getGCIEventOperations()Gets the next event operation from a GCI.
getNdbError()Retrieves an error. (See Section 2.3.19, “The NdbError Structure”.)
getNdbErrorDetail()Retrieves extra error details. Added in MySQL Cluster NDB 6.2.19, MySQL Cluster NDB 6.3.29, and MySQL Cluster NDB 7.0.10.
getNdbObjectName()Retrieves the Ndb object name if one was set. Added in MySQL Cluster NDB 7.1.32, MySQL Cluster NDB 7.2.17, and MySQL Cluster NDB 7.3.6.
getReference()Retrieves a reference or identifier for the Ndb object instance.
init()Initializes an Ndb object and makes it ready for use.
nextEvent()Returns the next event operation.
pollEvents()Waits for an event to occur.
setDatabaseName()Sets the name of the current database.
setDatabaseSchemaName()Sets the name of the current database schema.
setNdbObjectName()Set an arbitrary name for the Ndb object name for debugging purposes. Added in MySQL Cluster NDB 7.1.32, MySQL Cluster NDB 7.2.17, and MySQL Cluster NDB 7.3.6.
startTransaction()Begins a transaction. (See Section 2.3.29, “The NdbTransaction Class”.)

For detailed descriptions, signatures, and examples of use for each of these methods, see Section 2.3.15.1, “Ndb Methods”.

Class diagram.  This diagram shows all the available members of the Ndb class:

Public members of the Ndb class.