diff options
Diffstat (limited to 'ndb/include/ndbapi')
-rw-r--r-- | ndb/include/ndbapi/AttrType.hpp | 329 | ||||
-rw-r--r-- | ndb/include/ndbapi/Ndb.hpp | 72 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbApi.hpp | 5 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbBlob.hpp | 293 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbConnection.hpp | 101 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbDictionary.hpp | 36 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbIndexOperation.hpp | 2 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbOperation.hpp | 110 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbRecAttr.hpp | 43 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbReceiver.hpp | 4 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbScanOperation.hpp | 6 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbSchemaCon.hpp | 132 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbSchemaOp.hpp | 456 | ||||
-rw-r--r-- | ndb/include/ndbapi/ndbapi_limits.h | 20 |
14 files changed, 549 insertions, 1060 deletions
diff --git a/ndb/include/ndbapi/AttrType.hpp b/ndb/include/ndbapi/AttrType.hpp deleted file mode 100644 index e6e00c77130..00000000000 --- a/ndb/include/ndbapi/AttrType.hpp +++ /dev/null @@ -1,329 +0,0 @@ -/* Copyright (C) 2003 MySQL AB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -/** - * @file AttrType.hpp - */ - -#ifndef AttrType_H -#define AttrType_H - -/** - * Max number of Ndb objects in different threads. - * (Ndb objects should not be shared by different threads.) - */ -const unsigned MAX_NO_THREADS = 4711; - -/** - * Max number of attributes in a table. - */ -const unsigned MAXNROFATTRIBUTES = 128; - -/** - * Max number of tuple keys for a table in NDB Cluster. - * - * A <em>tuple key</em> of a table is an attribute - * which is either part of the - * <em>primary key</em> or the <em>tuple id</em> of a table. - */ -const unsigned MAXNROFTUPLEKEY = 16; - -/** - * Max number of words in a tuple key attribute. - * - * Tuple keys can not have values larger than - * 4092 bytes (i.e. 1023 words). - */ -const unsigned MAXTUPLEKEYLENOFATTERIBUTEINWORD = 1023; - -/** - * Max number of ErrorCode in NDB Cluster range 0 - 1999. - */ -const unsigned MAXNDBCLUSTERERROR = 1999; - -/** - * Max number of theErrorCode NDB API range 4000 - 4999. - */ -const unsigned MAXNROFERRORCODE = 5000; - -/** - * <i>Missing explanation</i> - */ -enum ReturnType { - ReturnSuccess, ///< <i>Missing explanation</i> - ReturnFailure ///< <i>Missing explanation</i> -}; - -/** - * - */ -enum SendStatusType { - NotInit, ///< <i>Missing explanation</i> - InitState, ///< <i>Missing explanation</i> - sendOperations, ///< <i>Missing explanation</i> - sendCompleted, ///< <i>Missing explanation</i> - sendCOMMITstate, ///< <i>Missing explanation</i> - sendABORT, ///< <i>Missing explanation</i> - sendABORTfail, ///< <i>Missing explanation</i> - sendTC_ROLLBACK, ///< <i>Missing explanation</i> - sendTC_COMMIT, ///< <i>Missing explanation</i> - sendTC_OP ///< <i>Missing explanation</i> -}; - -/** - * <i>Missing explanation</i> - */ -enum ListState { - NotInList, ///< <i>Missing explanation</i> - InPreparedList, ///< <i>Missing explanation</i> - InSendList, ///< <i>Missing explanation</i> - InCompletedList ///< <i>Missing explanation</i> -}; - -/** - * Commit status of the transaction - */ -enum CommitStatusType { - NotStarted, ///< Transaction not yet started - Started, ///< <i>Missing explanation</i> - Committed, ///< Transaction has been committed - Aborted, ///< Transaction has been aborted - NeedAbort ///< <i>Missing explanation</i> -}; - -/** - * Commit type of transaction - */ -enum AbortOption { -#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL - CommitIfFailFree = 0, - CommitAsMuchAsPossible = 2, ///< Commit transaction with as many - TryCommit = 0, ///< <i>Missing explanation</i> -#endif - AbortOnError = 0, ///< Abort transaction on failed operation - IgnoreError = 2 ///< Transaction continues on failed operation -}; - -typedef AbortOption CommitType; - -/** - * <i>Missing explanation</i> - */ -enum InitType { - NotConstructed, ///< <i>Missing explanation</i> - NotInitialised, ///< <i>Missing explanation</i> - StartingInit, ///< <i>Missing explanation</i> - Initialised, ///< <i>Missing explanation</i> - InitConfigError ///< <i>Missing explanation</i> -}; - -/** - * Type of attribute - */ -enum AttrType { - Signed, ///< Attributes of this type can be read with: - ///< NdbRecAttr::int64_value, - ///< NdbRecAttr::int32_value, - ///< NdbRecAttr::short_value, - ///< NdbRecAttr::char_value - UnSigned, ///< Attributes of this type can be read with: - ///< NdbRecAttr::u_64_value, - ///< NdbRecAttr::u_32_value, - ///< NdbRecAttr::u_short_value, - ///< NdbRecAttr::u_char_value - Float, ///< Attributes of this type can be read with: - ///< NdbRecAttr::float_value and - ///< NdbRecAttr::double_value - String, ///< Attributes of this type can be read with: - ///< NdbRecAttr::aRef, - ///< NdbRecAttr::getAttributeObject - NoAttrTypeDef ///< Used for debugging only -}; - -/** - * Execution type of transaction - */ -enum ExecType { - NoExecTypeDef = -1, ///< Erroneous type (Used for debugging only) - Prepare, ///< <i>Missing explanation</i> - NoCommit, ///< Execute the transaction as far as it has - ///< been defined, but do not yet commit it - Commit, ///< Execute and try to commit the transaction - Rollback ///< Rollback transaction -}; - -/** - * Indicates whether the attribute is part of a primary key or not - */ -enum KeyType { - Undefined = -1, ///< Used for debugging only - NoKey, ///< Attribute is not part of primary key - ///< or tuple identity - TupleKey, ///< Attribute is part of primary key - TupleId ///< Attribute is part of tuple identity - ///< (This type of attribute is created - ///< internally, and should not be - ///< manually created.) -}; - -/** - * Indicate whether the attribute should be stored on disk or not - */ -enum StorageMode { - MMBased = 0, ///< Main memory - DiskBased = 1, ///< Disk (Not yet supported.) - NoStorageTypeDef ///< Used for debugging only -}; - -/** - * Where attribute is stored. - * - * This is used to indicate whether a primary key - * should only be stored in the index storage and not in the data storage - * or if it should be stored in both places. - * The first alternative makes the attribute take less space, - * but makes it impossible to scan using attribute. - * - * @note Use NormalStorageAttribute for most cases. - * (IndexStorageAttribute should only be used on primary key - * attributes and only if you do not want to scan using the attribute.) - */ -enum StorageAttributeType { - NoStorageAttributeTypeDefined = -1, ///< <i>Missing explanation</i> - IndexStorageAttribute, ///< Attribute is only stored in - ///< index storage (ACC) - NormalStorageAttribute ///< Attribute values are stored - ///< both in the index (ACC) and - ///< in the data storage (TUP) -}; - -/** - * <i>Missing explanation</i> - */ -enum OperationStatus{ - Init, ///< <i>Missing explanation</i> - OperationDefined, ///< <i>Missing explanation</i> - TupleKeyDefined, ///< <i>Missing explanation</i> - GetValue, ///< <i>Missing explanation</i> - SetValue, ///< <i>Missing explanation</i> - ExecInterpretedValue, ///< <i>Missing explanation</i> - SetValueInterpreted, ///< <i>Missing explanation</i> - FinalGetValue, ///< <i>Missing explanation</i> - SubroutineExec, ///< <i>Missing explanation</i> - SubroutineEnd, ///< <i>Missing explanation</i> - SetBound, ///< Setting bounds in range scan - WaitResponse, ///< <i>Missing explanation</i> - WaitCommitResponse, ///< <i>Missing explanation</i> - Finished, ///< <i>Missing explanation</i> - ReceiveFinished ///< <i>Missing explanation</i> -}; - -/** - * Type of operation - */ -enum OperationType { - ReadRequest = 0, ///< Read operation - UpdateRequest = 1, ///< Update Operation - InsertRequest = 2, ///< Insert Operation - DeleteRequest = 3, ///< Delete Operation - WriteRequest = 4, ///< Write Operation - ReadExclusive = 5, ///< Read exclusive - OpenScanRequest, ///< Scan Operation - OpenRangeScanRequest, ///< Range scan operation - NotDefined2, ///< <i>Missing explanation</i> - NotDefined ///< <i>Missing explanation</i> -}; - -/** - * <i>Missing explanation</i> - */ -enum ConStatusType { - NotConnected, ///< <i>Missing explanation</i> - Connecting, ///< <i>Missing explanation</i> - Connected, ///< <i>Missing explanation</i> - DisConnecting, ///< <i>Missing explanation</i> - ConnectFailure ///< <i>Missing explanation</i> -}; - -/** - * <i>Missing explanation</i> - */ -enum CompletionStatus { - NotCompleted, ///< <i>Missing explanation</i> - CompletedSuccess, ///< <i>Missing explanation</i> - CompletedFailure, ///< <i>Missing explanation</i> - DefinitionFailure ///< <i>Missing explanation</i> -}; - -/** - * Type of fragmentation used for a table - */ -enum FragmentType { - Default = 0, ///< (All is default!) - Single = 1, ///< Only one fragment - All = 2, ///< Default value. One fragment per node group - DistributionGroup = 3, ///< Distribution Group used for fragmentation. - ///< One fragment per node group - DistributionKey = 4, ///< Distribution Key used for fragmentation. - ///< One fragment per node group. - AllLarge = 5, ///< Sixten fragments per node group. - DGroupLarge = 6, ///< Distribution Group used for fragmentation. - ///< Sixten fragments per node group - DKeyLarge = 7 ///< Distribution Key used for fragmentation. - ///< Sixten fragments per node group -}; - -/** - * Type of table or index. - */ -enum TableType { - UndefTableType = 0, - SystemTable = 1, ///< Internal. Table cannot be updated by user - UserTable = 2, ///< Normal application table - UniqueHashIndex = 3, ///< Unique un-ordered hash index - HashIndex = 4, ///< Non-unique un-ordered hash index - UniqueOrderedIndex = 5, ///< Unique ordered index - OrderedIndex = 6 ///< Non-unique ordered index -}; - -#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL -/** - * Different types of tampering with the NDB Cluster. - * <b>Only for debugging purposes only.</b> - */ -enum TamperType { - LockGlbChp = 1, ///< Lock GCP - UnlockGlbChp, ///< Unlock GCP - CrashNode, ///< Crash an NDB node - ReadRestartGCI, ///< Request the restart GCI id from NDB Cluster - InsertError ///< Execute an error in NDB Cluster - ///< (may crash system) -}; -#endif - -#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED -/** - * @deprecated - */ -enum NullAttributeType { - NoNullTypeDefined = -1, - NotNullAttribute, - NullAttribute, - AttributeDefined -}; -#endif - -#endif diff --git a/ndb/include/ndbapi/Ndb.hpp b/ndb/include/ndbapi/Ndb.hpp index fd6e827ceb4..27da5c3fa39 100644 --- a/ndb/include/ndbapi/Ndb.hpp +++ b/ndb/include/ndbapi/Ndb.hpp @@ -860,7 +860,6 @@ #include <ndb_types.h> #include <ndbapi_limits.h> -#include <AttrType.hpp> #include <NdbError.hpp> #include <NdbDictionary.hpp> @@ -870,8 +869,6 @@ class NdbEventOperationImpl; class NdbScanOperation; class NdbIndexOperation; class NdbConnection; -class NdbSchemaOp; -class NdbSchemaCon; class NdbApiSignal; class NdbRecAttr; class NdbLabel; @@ -882,6 +879,7 @@ class NdbScanReceiver; class Table; class BaseString; class NdbEventOperation; +class NdbBlob; typedef void (* NdbEventCallback)(NdbEventOperation*, Ndb*, void*); @@ -961,14 +959,13 @@ class Ndb friend class NdbOperation; friend class NdbEventOperationImpl; friend class NdbConnection; - friend class NdbSchemaOp; - friend class NdbSchemaCon; friend class Table; friend class NdbApiSignal; friend class NdbScanReceiver; friend class NdbIndexOperation; friend class NdbDictionaryImpl; friend class NdbDictInterface; + friend class NdbBlob; public: /** @@ -1064,8 +1061,6 @@ public: * A value larger than 1024 will be downgraded to 1024. * This means that one Ndb object can handle at most 1024 parallel * transactions. - * There is a maximum of 128 simultaneous - * Ndb object within one application process. * @return 0 if successful, -1 otherwise. * * @note The internal implementation multiplies this value @@ -1245,22 +1240,6 @@ public: */ void closeTransaction(NdbConnection* aConnection); -#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED - /** - * To create a table it is necessary to obtain a schema transaction - * object. - * All schema transactions need to closed when they are - * completed. - * - * @return NdbSchemaCon - */ - NdbSchemaCon* startSchemaTransaction(); - - /** - * Close schema transaction when finished. - */ - void closeSchemaTransaction(NdbSchemaCon* aSchemaCon); -#endif /** @} *********************************************************************/ @@ -1384,13 +1363,27 @@ public: * index names as DATABASENAME/SCHEMANAME/TABLENAME/INDEXNAME * @param turnNamingOn bool true - turn naming on, false - turn naming off */ - static void useFullyQualifiedNames(bool turnNamingOn = true); + void useFullyQualifiedNames(bool turnNamingOn = true); - static bool usingFullyQualifiedNames(); + bool usingFullyQualifiedNames(); /** @} *********************************************************************/ #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL + + /** + * Different types of tampering with the NDB Cluster. + * <b>Only for debugging purposes only.</b> + */ + enum TamperType { + LockGlbChp = 1, ///< Lock GCP + UnlockGlbChp, ///< Unlock GCP + CrashNode, ///< Crash an NDB node + ReadRestartGCI, ///< Request the restart GCI id from NDB Cluster + InsertError ///< Execute an error in NDB Cluster + ///< (may crash system) + }; + /** * For testing purposes it is possible to tamper with the NDB Cluster * (i.e. send a special signal to DBDIH, the NDB distribution handler). @@ -1398,14 +1391,7 @@ public: * In a release versions of NDB Cluster, * this call always return -1 and does nothing. * - * @param aAction Action to be taken - * - 1: Lock global checkpointing - * (Can only be sent to master DIH, - * Parameter aNode ignored). - * - 2: UnLock global checkpointing - * (Can only be sent to master DIH, - * Parameter aNode ignored). - * - 3: Crash node. + * @param aAction Action to be taken according to TamperType above * * @param aNode Which node the action will be taken * -1: Master DIH. @@ -1468,6 +1454,7 @@ private: NdbIndexOperation* getIndexOperation();// Get an index operation from idle class NdbGlobalEventBufferHandle* getGlobalEventBufferHandle(); + NdbBlob* getNdbBlob();// Get a blob handle etc void releaseSignal(NdbApiSignal* anApiSignal); void releaseSignalsInList(NdbApiSignal** pList); @@ -1479,6 +1466,7 @@ private: void releaseRecAttr (NdbRecAttr* aRecAttr); void releaseOperation(NdbOperation* anOperation); void releaseScanOperation(NdbScanOperation* aScanOperation); + void releaseNdbBlob(NdbBlob* aBlob); void check_send_timeout(); void remove_sent_list(Uint32); @@ -1521,6 +1509,7 @@ private: void freeNdbSubroutine();// Free the first idle NdbSubroutine obj void freeNdbCall(); // Free the first idle NdbCall obj void freeNdbScanRec(); // Free the first idle NdbScanRec obj + void freeNdbBlob(); // Free the first etc NdbConnection* getNdbCon(); // Get a connection from idle list @@ -1558,10 +1547,12 @@ private: void abortTransactionsAfterNodeFailure(Uint16 aNodeId); static + const char * externalizeTableName(const char * internalTableName, bool fullyQualifiedNames); const char * externalizeTableName(const char * internalTableName); const char * internalizeTableName(const char * externalTableName); static + const char * externalizeIndexName(const char * internalIndexName, bool fullyQualifiedNames); const char * externalizeIndexName(const char * internalIndexName); const char * internalizeIndexName(const NdbTableImpl * table, const char * externalIndexName); @@ -1598,6 +1589,8 @@ private: NdbWaiter theWaiter; + bool fullyQualifiedNames; + // Ndb database name. char theDataBase[NDB_MAX_DATABASE_NAME_SIZE]; // Ndb database schema name. @@ -1616,9 +1609,6 @@ private: NdbScanOperation* theScanOpIdleList; // First scan operation in the idle list. NdbIndexOperation* theIndexOpIdleList; // First index operation in the idle list. - NdbSchemaCon* theSchemaConIdleList; // First schemaCon in idle list. - - NdbSchemaCon* theSchemaConToNdbList; // Connected schemaCon object. NdbConnection* theTransactionList; NdbConnection** theConnectionArray; NdbRecAttr* theRecAttrIdleList; @@ -1628,6 +1618,7 @@ private: NdbSubroutine* theSubroutineList; // First subroutine descriptor in NdbCall* theCallList; // First call descriptor in list NdbScanReceiver* theScanList; + NdbBlob* theNdbBlobIdleList; Uint32 theMyRef; // My block reference Uint32 theNode; // The node number of our node @@ -1649,7 +1640,14 @@ private: NdbError theError; Int32 theNdbBlockNumber; - InitType theInitState; + + enum InitType { + NotConstructed, + NotInitialised, + StartingInit, + Initialised, + InitConfigError + } theInitState; // Ensure good distribution of connects Uint32 theCurrentConnectIndex; diff --git a/ndb/include/ndbapi/NdbApi.hpp b/ndb/include/ndbapi/NdbApi.hpp index e5efc9756ce..515f39433e4 100644 --- a/ndb/include/ndbapi/NdbApi.hpp +++ b/ndb/include/ndbapi/NdbApi.hpp @@ -17,17 +17,16 @@ #ifndef NdbApi_H #define NdbApi_H +#include "ndbapi_limits.h" #include "Ndb.hpp" -#include "AttrType.hpp" #include "NdbConnection.hpp" #include "NdbOperation.hpp" #include "NdbScanOperation.hpp" #include "NdbIndexOperation.hpp" -#include "NdbSchemaCon.hpp" -#include "NdbSchemaOp.hpp" #include "NdbRecAttr.hpp" #include "NdbResultSet.hpp" #include "NdbDictionary.hpp" #include "NdbEventOperation.hpp" #include "NdbPool.hpp" +#include "NdbBlob.hpp" #endif diff --git a/ndb/include/ndbapi/NdbBlob.hpp b/ndb/include/ndbapi/NdbBlob.hpp new file mode 100644 index 00000000000..9398f77c474 --- /dev/null +++ b/ndb/include/ndbapi/NdbBlob.hpp @@ -0,0 +1,293 @@ +/* Copyright (C) 2003 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#ifndef NdbBlob_H +#define NdbBlob_H + +#include <ndb_types.h> +#include <NdbDictionary.hpp> +#include <NdbConnection.hpp> +#include <NdbError.hpp> + +class Ndb; +class NdbConnection; +class NdbOperation; +class NdbRecAttr; +class NdbTableImpl; +class NdbColumnImpl; + +/** + * @class NdbBlob + * @brief Blob handle + * + * Blob data is stored in 2 places: + * + * - "header" and "inline bytes" stored in the blob attribute + * - "blob parts" stored in a separate table NDB$BLOB_<t>_<v>_<c> + * + * Inline and part sizes can be set via NdbDictionary::Column methods + * when the table is created. + * + * NdbBlob is a blob handle. To access blob data, the handle must be + * created using NdbOperation::getBlobHandle in operation prepare phase. + * The handle has following states: + * + * - prepared: before the operation is executed + * - active: after execute or next result but before transaction commit + * - closed: after transaction commit + * - invalid: after rollback or transaction close + * + * NdbBlob supports 2 styles of data access: + * + * - in prepare phase, NdbBlob methods getValue and setValue are used to + * prepare a read or write of a single blob value of known size + * + * - in active phase, NdbBlob methods readData and writeData are used to + * read or write blob data of undetermined size + * + * NdbBlob methods return -1 on error and 0 on success, and use output + * parameters when necessary. + * + * Notes: + * - table and its blob part tables are not created atomically + * - blob data operations take effect at next transaction execute + * - NdbBlob may need to do implicit executes on the transaction + * - read and write of complete parts is much more efficient + * - scan must use the "new" interface NdbScanOperation + * - scan with blobs applies hold-read-lock (at minimum) + * - to update a blob in a read op requires exclusive tuple lock + * - update op in scan must do its own getBlobHandle + * - delete creates implicit, not-accessible blob handles + * - NdbOperation::writeTuple does not support blobs + * - there is no support for an asynchronous interface + * + * Bugs / limitations: + * - scan must use exclusive locking for now + * + * Todo: + * - add scan method hold-read-lock-until-next + return-keyinfo + * - better check of keyinfo length when setting keys + * - better check of allowed blob op vs locking mode + */ +class NdbBlob { +public: + enum State { + Idle = 0, + Prepared = 1, + Active = 2, + Closed = 3, + Invalid = 9 + }; + State getState(); + /** + * Prepare to read blob value. The value is available after execute. + * Use isNull to check for NULL and getLength to get the real length + * and to check for truncation. Sets current read/write position to + * after the data read. + */ + int getValue(void* data, Uint32 bytes); + /** + * Prepare to insert or update blob value. An existing longer blob + * value will be truncated. The data buffer must remain valid until + * execute. Sets current read/write position to after the data. Set + * data to null pointer (0) to create a NULL value. + */ + int setValue(const void* data, Uint32 bytes); + /** + * Check if blob is null. + */ + int getNull(bool& isNull); + /** + * Set blob to NULL. + */ + int setNull(); + /** + * Get current length in bytes. Use isNull to distinguish between + * length 0 blob and NULL blob. + */ + int getLength(Uint64& length); + /** + * Truncate blob to given length. Has no effect if the length is + * larger than current length. + */ + int truncate(Uint64 length = 0); + /** + * Get current read/write position. + */ + int getPos(Uint64& pos); + /** + * Set read/write position. Must be between 0 and current length. + * "Sparse blobs" are not supported. + */ + int setPos(Uint64 pos); + /** + * Read at current position and set new position to first byte after + * the data read. A read past blob end returns actual number of bytes + * read in the in/out bytes parameter. + */ + int readData(void* data, Uint32& bytes); + /** + * Read at given position. Does not use or update current position. + */ + int readData(Uint64 pos, void* data, Uint32& bytes); + /** + * Write at current position and set new position to first byte after + * the data written. A write past blob end extends the blob value. + */ + int writeData(const void* data, Uint32 bytes); + /** + * Write at given position. Does not use or update current position. + */ + int writeData(Uint64 pos, const void* data, Uint32 bytes); + /** + * Return the blob column. + */ + const NdbDictionary::Column* getColumn(); + /** + * Get blob parts table name. Useful only to test programs. + */ + static const unsigned BlobTableNameSize = 40; + static int getBlobTableName(char* btname, Ndb* anNdb, const char* tableName, const char* columnName); + /** + * Return error object. The error may be blob specific (below) or may + * be copied from a failed implicit operation. + */ + const NdbError& getNdbError() const; + // "Invalid blob attributes or invalid blob parts table" + static const int ErrTable = 4263; + // "Invalid usage of blob attribute" + static const int ErrUsage = 4264; + // "Method is not valid in current blob state" + static const int ErrState = 4265; + // "Invalid blob seek position" + static const int ErrSeek = 4266; + // "Corrupted blob value" + static const int ErrCorrupt = 4267; + // "Error in blob head update forced rollback of transaction" + static const int ErrAbort = 4268; + // "Unknown blob error" + static const int ErrUnknown = 4269; + +private: + friend class Ndb; + friend class NdbConnection; + friend class NdbOperation; + friend class NdbScanOperation; + friend class NdbDictionaryImpl; + // state + State theState; + void setState(State newState); + // define blob table + static void getBlobTableName(char* btname, const NdbTableImpl* t, const NdbColumnImpl* c); + static void getBlobTable(NdbTableImpl& bt, const NdbTableImpl* t, const NdbColumnImpl* c); + // table name + char theBlobTableName[BlobTableNameSize]; + // ndb api stuff + Ndb* theNdb; + NdbConnection* theNdbCon; + NdbOperation* theNdbOp; + NdbTableImpl* theTable; + NdbTableImpl* theAccessTable; + const NdbColumnImpl* theColumn; + char theFillChar; + // sizes + Uint32 theInlineSize; + Uint32 thePartSize; + Uint32 theStripeSize; + // getValue/setValue + bool theGetFlag; + char* theGetBuf; + bool theSetFlag; + const char* theSetBuf; + Uint32 theGetSetBytes; + // head + struct Head { + Uint64 length; + }; + // buffers + struct Buf { + char* data; + unsigned size; + unsigned maxsize; + Buf(); + ~Buf(); + void alloc(unsigned n); + }; + Buf theKeyBuf; + Buf theAccessKeyBuf; + Buf theHeadInlineBuf; + Buf thePartBuf; + Head* theHead; + char* theInlineData; + NdbRecAttr* theHeadInlineRecAttr; + bool theHeadInlineUpdateFlag; + bool theNewPartFlag; + // length and read/write position + int theNullFlag; + Uint64 theLength; + Uint64 thePos; + // errors + NdbError theError; + // for keeping in lists + NdbBlob* theNext; + // initialization + NdbBlob(); + void init(); + void release(); + // classify operations + bool isTableOp(); + bool isIndexOp(); + bool isKeyOp(); + bool isReadOp(); + bool isInsertOp(); + bool isUpdateOp(); + bool isDeleteOp(); + bool isScanOp(); + // computations + Uint32 getPartNumber(Uint64 pos); + Uint32 getPartCount(); + Uint32 getDistKey(Uint32 part); + // getters and setters + int getTableKeyValue(NdbOperation* anOp); + int setTableKeyValue(NdbOperation* anOp); + int setAccessKeyValue(NdbOperation* anOp); + int setPartKeyValue(NdbOperation* anOp, Uint32 part); + int getHeadInlineValue(NdbOperation* anOp); + void getHeadFromRecAttr(); + int setHeadInlineValue(NdbOperation* anOp); + // data operations + int readDataPrivate(Uint64 pos, char* buf, Uint32& bytes); + int writeDataPrivate(Uint64 pos, const char* buf, Uint32 bytes); + int readParts(char* buf, Uint32 part, Uint32 count); + int insertParts(const char* buf, Uint32 part, Uint32 count); + int updateParts(const char* buf, Uint32 part, Uint32 count); + int deleteParts(Uint32 part, Uint32 count); + // blob handle maintenance + int atPrepare(NdbConnection* aCon, NdbOperation* anOp, const NdbColumnImpl* aColumn); + int preExecute(ExecType anExecType, bool& batch); + int postExecute(ExecType anExecType); + int preCommit(); + int atNextResult(); + // errors + void setErrorCode(int anErrorCode, bool invalidFlag = true); + void setErrorCode(NdbOperation* anOp, bool invalidFlag = true); + void setErrorCode(NdbConnection* aCon, bool invalidFlag = true); +#ifdef VM_TRACE + friend class NdbOut& operator<<(NdbOut&, const NdbBlob&); +#endif +}; + +#endif diff --git a/ndb/include/ndbapi/NdbConnection.hpp b/ndb/include/ndbapi/NdbConnection.hpp index c775dd5e33d..c620578cabd 100644 --- a/ndb/include/ndbapi/NdbConnection.hpp +++ b/ndb/include/ndbapi/NdbConnection.hpp @@ -18,7 +18,6 @@ #define NdbConnection_H #include <ndb_types.h> -#include <AttrType.hpp> #include <NdbError.hpp> class NdbConnection; @@ -29,6 +28,7 @@ class NdbIndexOperation; class NdbApiSignal; class Ndb; class NdbScanReceiver; +class NdbBlob; /** @@ -41,6 +41,35 @@ class NdbScanReceiver; typedef void (* NdbAsynchCallback)(int, NdbConnection*, void*); /** + * Commit type of transaction + */ +enum AbortOption { +#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL + CommitIfFailFree = 0, + CommitAsMuchAsPossible = 2, ///< Commit transaction with as many + TryCommit = 0, ///< <i>Missing explanation</i> +#endif + AbortOnError = 0, ///< Abort transaction on failed operation + IgnoreError = 2 ///< Transaction continues on failed operation +}; + +typedef AbortOption CommitType; + + +/** + * Execution type of transaction + */ +enum ExecType { + NoExecTypeDef = -1, ///< Erroneous type (Used for debugging only) + Prepare, ///< <i>Missing explanation</i> + NoCommit, ///< Execute the transaction as far as it has + ///< been defined, but do not yet commit it + Commit, ///< Execute and try to commit the transaction + Rollback ///< Rollback transaction +}; + + +/** * @class NdbConnection * @brief Represents a transaction. * @@ -132,6 +161,7 @@ class NdbConnection friend class NdbScanOperation; friend class NdbIndexOperation; friend class NdbScanReceiver; + friend class NdbBlob; public: @@ -419,6 +449,14 @@ public: * @return The commit status of the transaction, i.e. one of * { NotStarted, Started, TimeOut, Committed, Aborted, NeedAbort } */ + enum CommitStatusType { + NotStarted, ///< Transaction not yet started + Started, ///< <i>Missing explanation</i> + Committed, ///< Transaction has been committed + Aborted, ///< Transaction has been aborted + NeedAbort ///< <i>Missing explanation</i> + }; + CommitStatusType commitStatus(); /** @} *********************************************************************/ @@ -500,6 +538,10 @@ private: ~NdbConnection(); void init(); // Initialize connection object for new transaction + + int executeNoBlobs(ExecType execType, + AbortOption abortOption = AbortOnError, + int force = 0 ); /** * Set Connected node id @@ -515,8 +557,17 @@ private: Uint32 getBuddyConPtr(); // Gets Buddy Con Ptr NdbConnection* next(); // Returns the next pointer void next(NdbConnection*); // Sets the next pointer - ConStatusType Status(); // Read the status information - void Status(ConStatusType); // Set the status information + + enum ConStatusType { + NotConnected, + Connecting, + Connected, + DisConnecting, + ConnectFailure + }; + ConStatusType Status(); // Read the status information + void Status(ConStatusType); // Set the status information + Uint32 get_send_size(); // Get size to send void set_send_size(Uint32); // Set size to send; @@ -580,10 +631,12 @@ private: void setOperationErrorCodeAbort(int anErrorCode); int checkMagicNumber(); // Verify correct object - NdbOperation* getNdbOperation(class NdbTableImpl* aTable); + NdbOperation* getNdbOperation(class NdbTableImpl* aTable, + NdbOperation* aNextOp = 0); NdbScanOperation* getNdbScanOperation(class NdbTableImpl* aTable); NdbIndexOperation* getNdbIndexOperation(class NdbIndexImpl* anIndex, - class NdbTableImpl* aTable); + class NdbTableImpl* aTable, + NdbOperation* aNextOp = 0); void handleExecuteCompletion(); @@ -595,6 +648,18 @@ private: Uint32 theId; // Keeps track of what the send method should do. + enum SendStatusType { + NotInit, + InitState, + sendOperations, + sendCompleted, + sendCOMMITstate, + sendABORT, + sendABORTfail, + sendTC_ROLLBACK, + sendTC_COMMIT, + sendTC_OP + }; SendStatusType theSendStatus; NdbAsynchCallback theCallbackFunction; // Pointer to the callback function void* theCallbackObject; // The callback object pointer @@ -628,12 +693,18 @@ private: Uint64 theTransactionId; // theTransactionId of the transaction Uint32 theGlobalCheckpointId; // The gloabl checkpoint identity of the transaction ConStatusType theStatus; // The status of the connection - - CompletionStatus theCompletionStatus; // The Completion status of the transaction + enum CompletionStatus { + NotCompleted, + CompletedSuccess, + CompletedFailure, + DefinitionFailure + } theCompletionStatus; // The Completion status of the transaction CommitStatusType theCommitStatus; // The commit status of the transaction Uint32 theMagicNumber; // Magic Number to verify correct object Uint32 thePriority; // Transaction Priority + + enum ReturnType { ReturnSuccess, ReturnFailure }; ReturnType theReturnStatus; // Did we have any read/update/delete failing // to find the tuple. bool theTransactionIsStarted; @@ -641,7 +712,12 @@ private: bool theSimpleState; Uint8 m_abortOption; // Type of commit - ListState theListState; + enum ListState { + NotInList, + InPreparedList, + InSendList, + InCompletedList + } theListState; Uint32 theDBnode; // The database node we are connected to Uint32 theNodeSequence; // The sequence no of the db node @@ -662,6 +738,8 @@ private: // nextScanResult. NdbOperation* theScanningOp; // The operation actually performing the scan Uint32 theBuddyConPtr; + // optim: any blobs + bool theBlobFlag; static void sendTC_COMMIT_ACK(NdbApiSignal *, Uint32 transId1, Uint32 transId2, @@ -687,6 +765,10 @@ NdbConnection::set_send_size(Uint32 send_size) return; } +#ifdef NDB_NO_DROPPED_SIGNAL +#include <stdlib.h> +#endif + inline int NdbConnection::checkMagicNumber() @@ -830,7 +912,7 @@ Parameters: aStatus: The status. Remark: Sets Connect status. ******************************************************************************/ inline -ConStatusType +NdbConnection::ConStatusType NdbConnection::Status() { return theStatus; @@ -849,6 +931,7 @@ NdbConnection::Status( ConStatusType aStatus ) theStatus = aStatus; } + /****************************************************************************** void setGCI(); diff --git a/ndb/include/ndbapi/NdbDictionary.hpp b/ndb/include/ndbapi/NdbDictionary.hpp index a8a3bc86786..3b38e33ec91 100644 --- a/ndb/include/ndbapi/NdbDictionary.hpp +++ b/ndb/include/ndbapi/NdbDictionary.hpp @@ -182,7 +182,8 @@ public: Varbinary, ///< Max len Datetime, ///< Precision down to 1 sec (sizeof(Datetime) == 8 bytes ) Timespec, ///< Precision down to 1 nsec(sizeof(Datetime) == 12 bytes ) - Blob ///< Binary large object (see NdbBlob) + Blob, ///< Binary large object (see NdbBlob) + Clob ///< Text blob }; /** @@ -297,7 +298,34 @@ public: * Array length for column or max length for variable length arrays. */ int getLength() const; - + + /** + * For blob, set or get "inline size" i.e. number of initial bytes + * to store in table's blob attribute. This part is normally in + * main memory and can be indexed and interpreted. + */ + void setInlineSize(int size) { setPrecision(size); } + int getInlineSize() const { return getPrecision(); } + + /** + * For blob, set or get "part size" i.e. number of bytes to store in + * each tuple of the "blob table". Must be less than 64k. + */ + void setPartSize(int size) { setScale(size); } + int getPartSize() const { return getScale(); } + + /** + * For blob, set or get "stripe size" i.e. number of consecutive + * <em>parts</em> to store in each node group. + */ + void setStripeSize(int size) { setLength(size); } + int getStripeSize() const { return getLength(); } + + /** + * Get size of element + */ + int Column::getSize() const; + /** * Set distribution key * @@ -349,6 +377,7 @@ public: #endif private: + friend class NdbRecAttr; friend class NdbColumnImpl; class NdbColumnImpl & m_impl; Column(NdbColumnImpl&); @@ -1023,6 +1052,7 @@ public: private: friend class NdbDictionaryImpl; friend class UtilTransactions; + friend class NdbBlob; class NdbDictionaryImpl & m_impl; Dictionary(NdbDictionaryImpl&); const Table * getIndexTable(const char * indexName, @@ -1030,4 +1060,6 @@ public: }; }; +class NdbOut& operator <<(class NdbOut& ndbout, const NdbDictionary::Column::Type type); + #endif diff --git a/ndb/include/ndbapi/NdbIndexOperation.hpp b/ndb/include/ndbapi/NdbIndexOperation.hpp index 3b8e5f7a888..baf31dca0ee 100644 --- a/ndb/include/ndbapi/NdbIndexOperation.hpp +++ b/ndb/include/ndbapi/NdbIndexOperation.hpp @@ -184,7 +184,7 @@ private: // Private attributes NdbIndexImpl* m_theIndex; - Uint32 m_theIndexDefined[MAXNROFTUPLEKEY][3]; + Uint32 m_theIndexDefined[NDB_MAX_ATTRIBUTES_IN_INDEX][3]; Uint32 m_theIndexLen; // Length of the index in words Uint32 m_theNoOfIndexDefined; // The number of index attributes }; diff --git a/ndb/include/ndbapi/NdbOperation.hpp b/ndb/include/ndbapi/NdbOperation.hpp index 3c515fe84ef..cfa656cb2d5 100644 --- a/ndb/include/ndbapi/NdbOperation.hpp +++ b/ndb/include/ndbapi/NdbOperation.hpp @@ -18,10 +18,9 @@ #define NdbOperation_H #include <ndb_types.h> - -#include <AttrType.hpp> -#include <NdbError.hpp> -#include <NdbReceiver.hpp> +#include "ndbapi_limits.h" +#include "NdbError.hpp" +#include "NdbReceiver.hpp" class Ndb; class NdbApiSignal; @@ -29,6 +28,7 @@ class NdbRecAttr; class NdbOperation; class NdbConnection; class NdbColumnImpl; +class NdbBlob; /** * @class NdbOperation @@ -42,7 +42,8 @@ class NdbOperation friend class NdbScanReceiver; friend class NdbScanFilter; friend class NdbScanFilterImpl; - + friend class NdbBlob; + public: /** * @name Define Standard Operation Type @@ -526,6 +527,17 @@ public: virtual int setValue(Uint32 anAttrId, Int64 aValue); virtual int setValue(Uint32 anAttrId, float aValue); virtual int setValue(Uint32 anAttrId, double aValue); + + /** + * This method replaces getValue/setValue for blobs. It creates + * a blob handle NdbBlob. A second call with same argument returns + * the previously created handle. The handle is linked to the + * operation and is maintained automatically. + * + * See NdbBlob for details. + */ + virtual NdbBlob* getBlobHandle(const char* anAttrName); + virtual NdbBlob* getBlobHandle(Uint32 anAttrId); /** @} *********************************************************************/ /** @@ -833,8 +845,29 @@ public: */ int getNdbErrorLine(); + /** + * Get table name of this operation. + */ + const char* getTableName() const; + /** @} *********************************************************************/ + /** + * Type of operation + */ + enum OperationType { + ReadRequest = 0, ///< Read operation + UpdateRequest = 1, ///< Update Operation + InsertRequest = 2, ///< Insert Operation + DeleteRequest = 3, ///< Delete Operation + WriteRequest = 4, ///< Write Operation + ReadExclusive = 5, ///< Read exclusive + OpenScanRequest, ///< Scan Operation + OpenRangeScanRequest, ///< Range scan operation + NotDefined2, ///< Internal for debugging + NotDefined ///< Internal for debugging + }; + protected: /****************************************************************************** * These are the methods used to create and delete the NdbOperation objects. @@ -865,11 +898,27 @@ protected: NdbOperation* next(); // Get next pointer + enum OperationStatus{ + Init, + OperationDefined, + TupleKeyDefined, + GetValue, + SetValue, + ExecInterpretedValue, + SetValueInterpreted, + FinalGetValue, + SubroutineExec, + SubroutineEnd, + SetBound, + WaitResponse, + WaitCommitResponse, + Finished, + ReceiveFinished + }; + OperationStatus Status(); // Read the status information void Status(OperationStatus); // Set the status information - - OperationType RequestType(); void NdbCon(NdbConnection*); // Set reference to connection // object. @@ -879,8 +928,6 @@ protected: // the operations object. void setStartIndicator(); - void setCommitIndicator(CommitType aCommitType); - /****************************************************************************** * The methods below is the execution part of the NdbOperation * class. This is where the NDB signals are sent and received. The @@ -924,6 +971,7 @@ protected: Uint32 len); NdbRecAttr* getValue(const NdbColumnImpl* anAttrObject, char* aValue = 0); int setValue(const NdbColumnImpl* anAttrObject, const char* aValue, Uint32 len); + NdbBlob* getBlobHandle(NdbConnection* aCon, const NdbColumnImpl* anAttrObject); int incValue(const NdbColumnImpl* anAttrObject, Uint32 aValue); int incValue(const NdbColumnImpl* anAttrObject, Uint64 aValue); int subValue(const NdbColumnImpl* anAttrObject, Uint32 aValue); @@ -968,6 +1016,10 @@ protected: NdbOperation* takeOverScanOp(OperationType opType, NdbConnection* updateTrans); + // get table or index key from prepared signals + int getKeyFromTCREQ(Uint32* data, unsigned size); + int getKeyFromKEYINFO20(Uint32* data, unsigned size); + /****************************************************************************** * These are the private variables that are defined in the operation objects. *****************************************************************************/ @@ -1013,18 +1065,13 @@ protected: Uint32 theCurrRecAI_Len; // The currently received length Uint32 theAI_ElementLen; // How many words long is this element Uint32* theCurrElemPtr; // The current pointer to the element - //Uint32 theTableId; // Table id. - //Uint32 theAccessTableId; // The id of table for initial access, - // changed by NdbIndexOperation - //Uint32 theSchemaVersion; // The schema version on the table. class NdbTableImpl* m_currentTable; // The current table class NdbTableImpl* m_accessTable; // Set to TRUE when a tuple key attribute has been defined. - // A tuple key is allowed to consist of 64 attributes. - Uint32 theTupleKeyDefined[MAXNROFTUPLEKEY][3]; + Uint32 theTupleKeyDefined[NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY][3]; - Uint32 theTotalNrOfKeyWordInSignal; // The total number of + Uint32 theTotalNrOfKeyWordInSignal; // The total number of // keyword in signal. Uint32 theTupKeyLen; // Length of the tuple key in words @@ -1071,9 +1118,16 @@ protected: // saveBoundATTRINFO() moves ATTRINFO here when setBound() is ready NdbApiSignal* theBoundATTRINFO; Uint32 theTotalBoundAI_Len; + // Blobs in this operation + NdbBlob* theBlobList; }; +#ifdef NDB_NO_DROPPED_SIGNAL +#include <stdlib.h> +#endif + + inline int NdbOperation::checkMagicNumber() @@ -1094,16 +1148,6 @@ NdbOperation::setStartIndicator() theStartIndicator = 1; } -#if 0 -inline -void -NdbOperation::setCommitIndicator(CommitType aTypeOfCommit) -{ - theCommitIndicator = 1; - theCommitType = (Uint8)aTypeOfCommit; -} -#endif - inline int NdbOperation::getNdbErrorLine() @@ -1145,7 +1189,7 @@ Parameters: aStatus: The status. Remark: Sets Operation status. ******************************************************************************/ inline -OperationStatus +NdbOperation::OperationStatus NdbOperation::Status() { return theStatus; @@ -1178,18 +1222,6 @@ NdbOperation::NdbCon(NdbConnection* aNdbCon) theNdbCon = aNdbCon; } -/****************************************************************************** -OperationType RequestType(); - -Remark: Return the request typ of the operation.. -******************************************************************************/ -inline -OperationType -NdbOperation::RequestType() -{ - return theOperationType; -} - inline int NdbOperation::equal(const char* anAttrName, Int32 aPar) diff --git a/ndb/include/ndbapi/NdbRecAttr.hpp b/ndb/include/ndbapi/NdbRecAttr.hpp index 7eeff88671d..36b54035d96 100644 --- a/ndb/include/ndbapi/NdbRecAttr.hpp +++ b/ndb/include/ndbapi/NdbRecAttr.hpp @@ -18,10 +18,8 @@ #define NdbRecAttr_H #include <NdbDictionary.hpp> -#include "AttrType.hpp" class NdbOperation; -class AttrInfo; /** * @class NdbRecAttr @@ -78,20 +76,19 @@ class NdbRecAttr friend class NdbEventOperationImpl; friend class NdbScanReceiver; friend class Ndb; - + friend class NdbOut& operator<<(class NdbOut&, const class AttributeS&); + public: /** * @name Getting meta information * @{ */ const NdbDictionary::Column * getColumn() const; - + /** - * Get attribute type. - * - * @return Type of attribute: { Signed, UnSigned, Float, String } + * Get type of column + * @return Data type of the column */ - AttrType attrType() const ; NdbDictionary::Column::Type getType() const; /** @@ -257,6 +254,7 @@ private: void next(NdbRecAttr* aRecAttr); NdbRecAttr* next() const; + int setup(const class NdbDictionary::Column* col, char* aValue); int setup(const class NdbColumnImpl* anAttrInfo, char* aValue); /* Set up attributes and buffers */ bool copyoutRequired() const; /* Need to copy data to application */ @@ -317,33 +315,6 @@ NdbRecAttr::attrSize() const { } inline -AttrType -NdbRecAttr::attrType() const { - switch(getType()){ - case NdbDictionary::Column::Bigint: - case NdbDictionary::Column::Int: - return Signed; - case NdbDictionary::Column::Bigunsigned: - case NdbDictionary::Column::Unsigned: - return UnSigned; - case NdbDictionary::Column::Float: - case NdbDictionary::Column::Decimal: - case NdbDictionary::Column::Double: - return Float; - case NdbDictionary::Column::Char: - case NdbDictionary::Column::Varchar: - case NdbDictionary::Column::Binary: - case NdbDictionary::Column::Varbinary: - return String; - case NdbDictionary::Column::Datetime: - case NdbDictionary::Column::Timespec: - case NdbDictionary::Column::Undefined: - default: - return NoAttrTypeDef; - } -} - -inline Uint32 NdbRecAttr::arraySize() const { @@ -505,5 +476,7 @@ NdbRecAttr::isNULL() const return theNULLind; } +class NdbOut& operator <<(class NdbOut&, const NdbRecAttr &); + #endif diff --git a/ndb/include/ndbapi/NdbReceiver.hpp b/ndb/include/ndbapi/NdbReceiver.hpp index bc11207a112..a1a08a9735a 100644 --- a/ndb/include/ndbapi/NdbReceiver.hpp +++ b/ndb/include/ndbapi/NdbReceiver.hpp @@ -56,6 +56,10 @@ private: void* m_owner; }; +#ifdef NDB_NO_DROPPED_SIGNAL +#include <stdlib.h> +#endif + inline bool NdbReceiver::checkMagicNumber() const { diff --git a/ndb/include/ndbapi/NdbScanOperation.hpp b/ndb/include/ndbapi/NdbScanOperation.hpp index f83669fb616..151dc5bb99f 100644 --- a/ndb/include/ndbapi/NdbScanOperation.hpp +++ b/ndb/include/ndbapi/NdbScanOperation.hpp @@ -33,6 +33,8 @@ #include <NdbOperation.hpp> #include <NdbCursorOperation.hpp> +class NdbBlob; + /** * @class NdbScanOperation * @brief Class of scan operations for use in transactions. @@ -82,6 +84,10 @@ public: int setValue(Uint32 anAttrId, float aValue); int setValue(Uint32 anAttrId, double aValue); #endif + + NdbBlob* getBlobHandle(const char* anAttrName); + NdbBlob* getBlobHandle(Uint32 anAttrId); + private: NdbScanOperation(Ndb* aNdb); diff --git a/ndb/include/ndbapi/NdbSchemaCon.hpp b/ndb/include/ndbapi/NdbSchemaCon.hpp deleted file mode 100644 index 9d6b49df8f9..00000000000 --- a/ndb/include/ndbapi/NdbSchemaCon.hpp +++ /dev/null @@ -1,132 +0,0 @@ -/* Copyright (C) 2003 MySQL AB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -#ifndef NdbSchemaCon_H -#define NdbSchemaCon_H -#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED - -#include <ndb_types.h> -#include "AttrType.hpp" -#include "NdbError.hpp" - -class NdbSchemaOp; -class NdbApiSignal; -class Ndb; - -/** - * @class NdbSchemaCon - * @brief Represents a schema transaction. - * - * When creating a new table, - * the first step is to get a NdbSchemaCon object to represent - * the schema transaction. - * This is done by calling Ndb::startSchemaTransaction. - * - * The next step is to get a NdbSchemaOp object by calling - * NdbSchemaCon::getNdbSchemaOp. - * The NdbSchemaOp object then has methods to define the table and - * its attributes. - * - * Finally, the NdbSchemaCon::execute method inserts the table - * into the database. - * - * @note Currently only one table can be added per transaction. - */ -class NdbSchemaCon -{ -friend class Ndb; -friend class NdbSchemaOp; - -public: - /** - * Execute a schema transaction. - * - * @return 0 if successful otherwise -1. - */ - int execute(); - - /** - * Get a schemaoperation. - * - * @note Currently, only one operation per transaction is allowed. - * - * @return Pointer to a NdbSchemaOp or NULL if unsuccessful. - */ - NdbSchemaOp* getNdbSchemaOp(); - - /** - * Get the latest error - * - * @return Error object. - */ - const NdbError & getNdbError() const; - -private: -/****************************************************************************** - * These are the create and delete methods of this class. - *****************************************************************************/ - - NdbSchemaCon(Ndb* aNdb); - ~NdbSchemaCon(); - -/****************************************************************************** - * These are the private methods of this class. - *****************************************************************************/ - void init(); // Initialise connection object for new - // transaction. - - void release(); // Release all schemaop in schemaCon - - /*************************************************************************** - * These methods are service methods to other classes in the NDBAPI. - ***************************************************************************/ - - int checkMagicNumber(); // Verify correct object - int receiveDICTTABCONF(NdbApiSignal* aSignal); - int receiveDICTTABREF(NdbApiSignal* aSignal); - - - int receiveCREATE_INDX_CONF(NdbApiSignal*); - int receiveCREATE_INDX_REF(NdbApiSignal*); - int receiveDROP_INDX_CONF(NdbApiSignal*); - int receiveDROP_INDX_REF(NdbApiSignal*); - - - -/***************************************************************************** - * These are the private variables of this class. - *****************************************************************************/ - - - NdbError theError; // Errorcode - Ndb* theNdb; // Pointer to Ndb object - - NdbSchemaOp* theFirstSchemaOpInList; // First operation in operation list. - int theMagicNumber; // Magic number -}; - -inline -int -NdbSchemaCon::checkMagicNumber() -{ - if (theMagicNumber != 0x75318642) - return -1; - return 0; -}//NdbSchemaCon::checkMagicNumber() -#endif -#endif - - diff --git a/ndb/include/ndbapi/NdbSchemaOp.hpp b/ndb/include/ndbapi/NdbSchemaOp.hpp deleted file mode 100644 index c3a3827a6b4..00000000000 --- a/ndb/include/ndbapi/NdbSchemaOp.hpp +++ /dev/null @@ -1,456 +0,0 @@ -/* Copyright (C) 2003 MySQL AB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -#ifndef NdbSchemaOp_H -#define NdbSchemaOp_H -#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED - -#include "NdbDictionary.hpp" -#include "AttrType.hpp" -#include "NdbSchemaCon.hpp" - -class NdbApiSignal; -class Ndb; - -/** - * @class NdbSchemaOp - * @brief Represents various operations for use in schema transactions - * - * This class is used for schema operations, e.g. creating tables and - * attributes. - * - * The NdbSchemaOp object is created using NdbSchemaCon::getNdbSchemaOp. - * - * @note This class is depricated and is now replaced with the class - * NdbDictionary. - */ -class NdbSchemaOp -{ - friend class Ndb; - friend class NdbSchemaCon; - -public: - /** - * Create a new table in the database. - * - * @note The NdbSchemaCon should be closed with - * Ndb::closeSchemaTransaction, even if this method fails. - * - * @param aTableName Table name. Should not be NULL. - * @param aTableSize (Performance parameter.) - * Initial size of the data part of the table - * expressed in kByte. - * The database handles - * bad parameter setting but at a certain - * loss in performance. - * The size given here is - * the initial size allocated for the table - * storage (the data part). - * When calculating the data storage one should - * add the size of all attributes (each attribute - * consumes at least 4 bytes) and also an overhead - * of 12 byte. - * Variable size attributes (not supported yet) - * will have a size of 12 bytes plus the actual - * data storage parts where there is an - * additional overhead based on the size of the - * variable part. - * <br> - * An example table with 5 attributes: - * one 64 bit attribute, one 32 bit attribute, - * two 16 bit attributes and one array of 64 8 bits. - * This table will consume - * 12 (overhead) + 8 + 4 + 2*4 (4 is minimum) + 64 = - * 96 bytes per record. - * Additionally an overhead of about 2 % as page - * headers and waste should be allocated. - * Thus, 1 million records should consume 96 MBytes - * plus the overhead 2 MByte and rounded up to - * 100 000 kBytes. - * <br><em> - * This parameter is currently not used. - * </em> - * @param aTupleKey Indicates if the table has a primary key or not. - * <br> - * <b>TupleKey</b> means that a <em>primary key</em> - * consisting of one to four attributes - * (at most one of variable size) - * uniquely identifies each record in the created - * table. - * <br> - * <b>TupleId</b> means that a <em>tuple identity</em> - * is used. The tuple identity is - * a unique key indentifying each record of the - * created table. - * The tuple identity is a (non-stored) - * 64 bit attribute named <b>NDB$TID</b>. - * <br> - * When inserting a record (tuple), the method - * NdbOperation::setTupleId - * will generate a unique tuple identity - * and return it to the user. - * <br> - * When reading, updating or deleting a record - * in a table with <b>TupleId</b>, - * NdbOperation::equal("NDB$TID", value_Uint64) - * can be used to identify the record. - * <br> - * Legal values: TupleKey or TupleId. - * @param aNrOfPages (Performance parameter.) - * Specifies the initial size of the index storage. - * When calculating the index storage, - * each key has approximately 14 byte of - * overhead plus the size of the key. - * Each key attribute takes up at least 4 bytes - * of storage. - * Thus a mixed key consisting of a - * 64 bit attribute, a 32 bit attribute - * and a 16 bit attribute will - * consume approx. 30 bytes per key. - * Thus, the if initial size is to be 1 million rows, - * then aNrOfPages should be set to - * 30 M / 8k = 2670 pages. - * <br><em> - * This parameter is currently not used. - * </em> - * @param aFragmentType Type of fragmentation.<br> - * <b>All</b> (default) means that the - * table fragments are automatically - * distributed on all nodes in the system.<br> - * <b>DistributionGroup</b> and - * <b>DistributionKey</b> are - * also supported. For further details about - * these types see the documentation of - * Ndb::startTransaction. - * @param aKValue (Hash parameter.) - * Only allowed value is 6. - * Later implementations might add flexibility - * in this parameter. - * @param aMinLoadFactor (Hash parameter.) - * This value specifies the load factor when - * starting to shrink the hash table. - * It must be smaller than aMaxLoadFactor. - * Both these factors are given in percentage. - * @param aMaxLoadFactor (Hash parameter.) - * This value specifies the load factor when - * starting to split the containers in the local - * hash tables. 100 is the maximum which will - * optimize memory usage (this is the figure - * used for the above calculations). - * A lower figure will store less information in - * each container and thus - * find the key faster but consume more memory. - * @param aMemoryType Currently only 1 is allowed which specifies - * storage of table in main memory. - * Later 2 will be added where the table is stored - * completely on disk - * and 3 where the index is in main memory but - * data is on disk. - * If 1 is chosen an individual attribute can - * still be specified as a disk attribute. - * @param aStoredTable If set to false it indicates that the table is - * a temporary table and should not be logged - * to disk. - * In case of a system restart the table will still - * be defined and exist but will be empty. - * Thus no checkpointing and - * no logging is performed on the table. - * The default value is true and indicates a - * normal table with full checkpointing and - * logging activated. - * @return Returns 0 when successful and returns -1 otherwise. - */ - int createTable( const char* aTableName, - Uint32 aTableSize = 8, - KeyType aTupleKey = TupleKey, - int aNrOfPages = 2, - FragmentType aFragmentType = All, - int aKValue = 6, - int aMinLoadFactor = 78, - int aMaxLoadFactor = 80, - int aMemoryType = 1, - bool aStoredTable = true); - -#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED - /** - * This is the old function declaration, don't use. - * - * @deprecated do not use! - */ - inline int createTable( const char* aTableName, - Uint32 aTableSize, - KeyType aTupleKey, - int aNrOfPages, - FragmentType aFragmentType, - int aKValue, - int aMinLoadFactor, - int aMaxLoadFactor, - int aMemoryType, - int aStoredTable){ - return createTable(aTableName, - aTableSize, - aTupleKey, - aNrOfPages, - aFragmentType, - aKValue, - aMinLoadFactor, - aMaxLoadFactor, - aMemoryType, - (aStoredTable == 1 ? true : false)); - } -#endif - - /** - * Add a new attribute to a database table. - * - * Attributes can only be added to a table in the same transaction - * as the transaction creating the table. - * - * @note The NdbSchemaCon transaction should be closed with - * Ndb::closeSchemaTransaction, even if this method fails. - * - * Example creating an unsigned int attribute belonging to the primary key - * of the table it is created in: - * @code - * MySchemaOp->createAttribute("Attr1", // Attribute name - * TupleKey, // Belongs to primary key - * 32, // 32 bits - * 1, // Not an array attribute - * UnSigned, // Unsigned type - * ); - * @endcode - * - * Example creating a string attribute belonging to the primary key - * of the table it is created in: - * @code - * MySchemaOp->createAttribute("Attr1", // Attribute name - * TupleKey, // Belongs to primary key - * 8, // Each character is 8 bits - * 12, // Max 12 chars in string - * String, // Attribute if of type string - * ); - * @endcode - * - * A <em>distribution key</em> is a set of attributes which are used - * to distribute the tuples onto the NDB nodes. - * A <em>distribution group</em> is a part (currently 16 bits) - * of an attribute used to distribute the tuples onto the NDB nodes. - * The distribution key uses the NDB Cluster hashing function, - * while the distribution group uses a simpler function. - * - * @param aAttrName Attribute name. Should not be NULL. - * @param aTupleKey This parameter specifies whether the - * attribute is part of the primary key or not. - * Floats are not allowed in the primary key. - * <br> - * Legal values: NoKey, TupleKey - * @param aAttrSize Specifies the size of the elements of the - * attribute. (An attribute can consist - * of an array of elements.) - * <br> - * Legal values: 8, 16, 32, 64 and 128 bits. - * @param aArraySize Size of array. - * <br> - * Legal values: - * 0 = variable-sized array, - * 1 = no array, and - * 2- = fixed size array. - * <br> - * <em> - * Variable-sized array attributes are - * not yet supported. - * </em> - * <br> - * There is no upper limit of the array size - * for a single attribute. - * @param aAttrType The attribute type. - * This is only of interest if calculations are - * made within NDB. - * <br> - * Legal values: UnSigned, Signed, Float, String - * @param aStorageMode Main memory based or disk based attribute.<br> - * Legal values: MMBased, DiskBased - * <br> - * <em> - * Disk-based attributes are not yet supported. - * </em> - * @param nullable Set to true if NULL is a correct value for - * the attribute. - * <br> - * Legal values: true, false - * @param aStType Stored in both index and data storage or - * only store in index data storage. - * <br> - * This parameter is only of interest for tuple - * key attributes. - * All tuple key attributes values are always stored - * in the index storage part. - * If this parameter is set to - * IndexStorageAttribute, then the attribute values - * will <em>only</em> be stored in the index - * storage part and <em>not</em> in the data - * storage part. - * <br> - * If there will be no scans using the primary - * key attribute and if the size of the attribute - * is large, then this might be of interest. - * A typical example is a table where - * http-addresses are used as primary key. - * <br> - * Legal values: NormalStorageAttribute, - * IndexStorageAttribute - * @param aDistributionKey Sometimes it is preferable to use a subset - * of the primary key as the distribution key. - * An example is TPC-C where it might be - * good to use the warehouse id and district id - * as the distribution key. - * <br> - * Locally in the fragments the full primary key - * will still be used with the hashing algorithm. - * Set to 1 if this attribute is part of the - * distribution key. - * All distribution key attributes must be - * defined before - * any other attributes are defined. - * @param aDistributionGroup In other applications it is desirable to use - * only a part of an attribute to create the - * distribution key. - * This is applicable for some telecom - * applications. - * <br> - * In these situations one must provide how many - * bits of the attribute that is to - * be used as the distribution hash value. - * <br> - * This provides some control to the - * application of the distribution. - * It still needs to be part of a primary key - * the attribute and must be defined as the - * first attribute. - * @param aDistributionGroupNoOfBits - * Number of bits to use of the - * distribution group attribute in the - * distribution hash value. - * <br> - * Currently, only 16 bits is supported. It will - * always be the last 16 bits in the attribute - * which is used for the distribution group. - * @param aAutoIncrement Set to autoincrement attribute. - * @param aDefaultValue Set a default value of attribute. - * - * @return Returns 0 when successful and returns -1 otherwise. - ****************************************************************************/ - int createAttribute(const char* aAttrName, - KeyType aTupleKey = NoKey, - int aAttrSize = 32, - int aArraySize = 1, - AttrType aAttrType = UnSigned, - StorageMode aStorageMode = MMBased, - bool nullable = false, - StorageAttributeType aStType= NormalStorageAttribute, - int aDistributionKey = 0, - int aDistributionGroup = 0, - int aDistributionGroupNoOfBits = 16, - bool aAutoIncrement = false, - const char* aDefaultValue = 0); - -#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED - /** - * @deprecated do not use! - */ - int createAttribute(const char* aAttrName, - KeyType aTupleKey, - int aAttrSize, - int aArraySize, - AttrType aAttrType, - StorageMode aStorageMode, - NullAttributeType aNullAttr, - StorageAttributeType aStType = NormalStorageAttribute, - int aDistributionKey = 0, - int aDistributionGroup = 0, - int aDistributionGroupNoOfBits = 16){ - return createAttribute(aAttrName, - aTupleKey, - aAttrSize, - aArraySize, - aAttrType, - aStorageMode, - aNullAttr == NullAttribute, - aStType, - aDistributionKey, - aDistributionGroup, - aDistributionGroupNoOfBits); - } -#endif - - /** - * Get the last error which occurred during the transaction. - * - * If an error occured (NdbSchemaCon::execute returned -1 or - * NdbSchemaCon::getNdbSchemaOp returned NULL), then this method - * retrieves the error object containing information about - * the error. - * - * @return Error object containing information about last error. - */ - const NdbError & getNdbError() const; - -protected: - -/***************************************************************************** - * These are the methods used to create and delete the NdbOperation objects. - ****************************************************************************/ - NdbSchemaOp(Ndb* aNdb); - - ~NdbSchemaOp(); - -/****************************************************************************** - * These methods are service routines used by the other NDBAPI classes. - *****************************************************************************/ - - void release(); // Release all memory connected - // to the operations object. - -/**************************************************************************** - * The methods below is the execution part of the NdbSchemaOp class. - *****************************************************************************/ - - int sendRec(); - int sendSignals(Uint32 aNodeId, bool HaveMutex); - - int init(NdbSchemaCon* aSchemaCon); - - /************************************************************************** - * These are the private variables that are defined in the operation - * objects. - **************************************************************************/ - Ndb* theNdb; // Point back to the Ndb object. - NdbSchemaCon* theSchemaCon; // Point back to the connection object. - - class NdbDictionary::Table * m_currentTable; -}; - -inline -const NdbError & -NdbSchemaOp::getNdbError() const -{ - return theSchemaCon->getNdbError(); -} - -#endif -#endif - - diff --git a/ndb/include/ndbapi/ndbapi_limits.h b/ndb/include/ndbapi/ndbapi_limits.h index bcfba7d3f9d..1cf2d9b342d 100644 --- a/ndb/include/ndbapi/ndbapi_limits.h +++ b/ndb/include/ndbapi/ndbapi_limits.h @@ -18,30 +18,16 @@ #define NDBAPI_LIMITS_H #define NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY 32 -#define NDB_MAX_TABLES 1600 +#define NDB_MAX_ATTRIBUTES_IN_INDEX NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY #define NDB_MAX_DATABASE_NAME_SIZE 128 #define NDB_MAX_SCHEMA_NAME_SIZE 128 #define NDB_MAX_TAB_NAME_SIZE 128 -#define NDB_MAX_ATTR_NAME_SIZE 32 -#define NDB_MAX_ATTR_DEFAULT_VALUE_SIZE 128 #define NDB_MAX_ATTRIBUTES_IN_TABLE 91 -#define NDB_MAX_ATTRIBUTES_IN_INDEX NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY + #define NDB_MAX_TUPLE_SIZE_IN_WORDS 1023 -#define NDB_MAX_FIXED_KEY_LENGTH_IN_WORDS 8 #define NDB_MAX_KEYSIZE_IN_WORDS 1023 #define NDB_MAX_KEY_SIZE NDB_MAX_KEYSIZE_IN_WORDS*sizeof(Uint32) -#define NDB_MAX_TUPLE_SIZE 8191 -#define NDB_MAX_CONNECTIONS 127 -#define NDB_MAX_TRANSACTIONS 1024 -#define NDB_MAX_PARALLEL_SCANS 12 +#define NDB_MAX_TUPLE_SIZE NDB_MAX_TUPLE_SIZE_IN_WORDS*sizeof(uint32) #define NDB_MAX_ACTIVE_EVENTS 100 -#ifndef MIN -#define MIN(x,y) (((x)<(y))?(x):(y)) -#endif - -#ifndef MAX -#define MAX(x,y) (((x)>(y))?(x):(y)) -#endif - #endif |