1 /* 2 Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License, version 2.0, 6 as published by the Free Software Foundation. 7 8 This program is also distributed with certain software (including 9 but not limited to OpenSSL) that is licensed under separate terms, 10 as designated in a particular file or component or in included license 11 documentation. The authors of MySQL hereby grant you an additional 12 permission to link the program and your derivative works with the 13 separately licensed software that they have included with MySQL. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License, version 2.0, for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 25 #ifndef NdbDictionary_H 26 #define NdbDictionary_H 27 28 #include <ndb_types.h> 29 30 class Ndb; 31 struct charset_info_st; 32 typedef struct charset_info_st CHARSET_INFO; 33 34 /* Forward declaration only. */ 35 class NdbRecord; 36 37 /** 38 * @class NdbDictionary 39 * @brief Data dictionary class 40 * 41 * The preferred and supported way to create and drop tables and indexes 42 * in ndb is through the 43 * MySQL Server (see MySQL reference Manual, section MySQL Cluster). 44 * 45 * Tables and indexes that are created directly through the 46 * NdbDictionary class 47 * can not be viewed from the MySQL Server. 48 * Dropping indexes directly via the NdbApi will cause inconsistencies 49 * if they were originally created from a MySQL Cluster. 50 * 51 * This class supports schema data enquiries such as: 52 * -# Enquiries about tables 53 * (Dictionary::getTable, Table::getNoOfColumns, 54 * Table::getPrimaryKey, and Table::getNoOfPrimaryKeys) 55 * -# Enquiries about indexes 56 * (Dictionary::getIndex, Index::getNoOfColumns, 57 * and Index::getColumn) 58 * 59 * This class supports schema data definition such as: 60 * -# Creating tables (Dictionary::createTable) and table columns 61 * -# Dropping tables (Dictionary::dropTable) 62 * -# Creating secondary indexes (Dictionary::createIndex) 63 * -# Dropping secondary indexes (Dictionary::dropIndex) 64 * 65 * NdbDictionary has several help (inner) classes to support this: 66 * -# NdbDictionary::Dictionary the dictionary handling dictionary objects 67 * -# NdbDictionary::Table for creating tables 68 * -# NdbDictionary::Column for creating table columns 69 * -# NdbDictionary::Index for creating secondary indexes 70 * 71 * See @ref ndbapi_simple_index.cpp for details of usage. 72 */ 73 class NdbDictionary { 74 public: NdbDictionary()75 NdbDictionary() {} /* Remove gcc warning */ 76 /** 77 * @class Object 78 * @brief Meta information about a database object (a table, index, etc) 79 */ 80 class Object { 81 public: Object()82 Object() {} /* Remove gcc warning */ ~Object()83 virtual ~Object() {} /* Remove gcc warning */ 84 /** 85 * Status of object 86 */ 87 enum Status { 88 New, ///< The object only exist in memory and 89 ///< has not been created in the NDB Kernel 90 Changed, ///< The object has been modified in memory 91 ///< and has to be commited in NDB Kernel for 92 ///< changes to take effect 93 Retrieved, ///< The object exist and has been read 94 ///< into main memory from NDB Kernel 95 Invalid, ///< The object has been invalidated 96 ///< and should not be used 97 Altered ///< Table has been altered in NDB kernel 98 ///< but is still valid for usage 99 }; 100 101 /** 102 * Get status of object 103 */ 104 virtual Status getObjectStatus() const = 0; 105 106 /** 107 * Get version of object 108 */ 109 virtual int getObjectVersion() const = 0; 110 111 virtual int getObjectId() const = 0; 112 113 /** 114 * Object type 115 */ 116 enum Type { 117 TypeUndefined = 0, ///< Undefined 118 SystemTable = 1, ///< System table 119 UserTable = 2, ///< User table (may be temporary) 120 UniqueHashIndex = 3, ///< Unique un-ordered hash index 121 OrderedIndex = 6, ///< Non-unique ordered index 122 HashIndexTrigger = 7, ///< Index maintenance, internal 123 IndexTrigger = 8, ///< Index maintenance, internal 124 SubscriptionTrigger = 9,///< Backup or replication, internal 125 ReadOnlyConstraint = 10,///< Trigger, internal 126 TableEvent = 11, ///< Table event 127 Tablespace = 20, ///< Tablespace 128 LogfileGroup = 21, ///< Logfile group 129 Datafile = 22, ///< Datafile 130 Undofile = 23, ///< Undofile 131 ReorgTrigger = 19, 132 HashMap = 24 133 }; 134 135 /** 136 * Object state 137 */ 138 enum State { 139 StateUndefined = 0, ///< Undefined 140 StateOffline = 1, ///< Offline, not usable 141 StateBuilding = 2, ///< Building, not yet usable 142 StateDropping = 3, ///< Offlining or dropping, not usable 143 StateOnline = 4, ///< Online, usable 144 StateBackup = 5, ///< Online, being backuped, usable 145 StateBroken = 9 ///< Broken, should be dropped and re-created 146 }; 147 148 /** 149 * Object store 150 */ 151 enum Store { 152 StoreUndefined = 0, ///< Undefined 153 StoreNotLogged = 1, ///< Object or data deleted on system restart 154 StorePermanent = 2 ///< Permanent. logged to disk 155 }; 156 157 /** 158 * Type of fragmentation. 159 * 160 * This parameter specifies how data in the table or index will 161 * be distributed among the db nodes in the cluster.<br> 162 * The bigger the table the more number of fragments should be used. 163 * Note that all replicas count as same "fragment".<br> 164 * For a table, default is FragAllMedium. For a unique hash index, 165 * default is taken from underlying table and cannot currently 166 * be changed. 167 */ 168 enum FragmentType { 169 FragUndefined = 0, ///< Fragmentation type undefined or default 170 FragSingle = 1, ///< Only one fragment 171 FragAllSmall = 2, ///< One fragment per node, default 172 FragAllMedium = 3, ///< two fragments per node 173 FragAllLarge = 4, ///< Four fragments per node. 174 DistrKeyHash = 5, 175 DistrKeyLin = 6, 176 UserDefined = 7, 177 HashMapPartition = 9 178 }; 179 private: 180 Object&operator=(const Object&); 181 }; 182 183 class Dictionary; // Forward declaration 184 185 class ObjectId : public Object 186 { 187 public: 188 ObjectId(); 189 virtual ~ObjectId(); 190 191 /** 192 * Get status of object 193 */ 194 virtual Status getObjectStatus() const; 195 196 /** 197 * Get version of object 198 */ 199 virtual int getObjectVersion() const; 200 201 virtual int getObjectId() const; 202 203 private: 204 friend class NdbDictObjectImpl; 205 class NdbDictObjectImpl & m_impl; 206 207 ObjectId(const ObjectId&); // Not impl. 208 ObjectId&operator=(const ObjectId&); 209 }; 210 211 class Table; // forward declaration 212 class Tablespace; // forward declaration 213 class HashMap; // Forward 214 // class NdbEventOperation; // forward declaration 215 216 /** 217 * @class Column 218 * @brief Represents a column in an NDB Cluster table 219 * 220 * Each column has a type. The type of a column is determined by a number 221 * of type specifiers. 222 * The type specifiers are: 223 * - Builtin type 224 * - Array length or max length 225 * - Precision and scale (not used yet) 226 * - Character set for string types 227 * - Inline and part sizes for blobs 228 * 229 * Types in general correspond to MySQL types and their variants. 230 * Data formats are same as in MySQL. NDB API provides no support for 231 * constructing such formats. NDB kernel checks them however. 232 */ 233 class Column { 234 public: 235 /** 236 * The builtin column types 237 */ 238 enum Type { 239 Undefined = NDB_TYPE_UNDEFINED, ///< Undefined 240 Tinyint = NDB_TYPE_TINYINT, ///< 8 bit. 1 byte signed integer, can be used in array 241 Tinyunsigned = NDB_TYPE_TINYUNSIGNED, ///< 8 bit. 1 byte unsigned integer, can be used in array 242 Smallint = NDB_TYPE_SMALLINT, ///< 16 bit. 2 byte signed integer, can be used in array 243 Smallunsigned = NDB_TYPE_SMALLUNSIGNED, ///< 16 bit. 2 byte unsigned integer, can be used in array 244 Mediumint = NDB_TYPE_MEDIUMINT, ///< 24 bit. 3 byte signed integer, can be used in array 245 Mediumunsigned = NDB_TYPE_MEDIUMUNSIGNED,///< 24 bit. 3 byte unsigned integer, can be used in array 246 Int = NDB_TYPE_INT, ///< 32 bit. 4 byte signed integer, can be used in array 247 Unsigned = NDB_TYPE_UNSIGNED, ///< 32 bit. 4 byte unsigned integer, can be used in array 248 Bigint = NDB_TYPE_BIGINT, ///< 64 bit. 8 byte signed integer, can be used in array 249 Bigunsigned = NDB_TYPE_BIGUNSIGNED, ///< 64 Bit. 8 byte signed integer, can be used in array 250 Float = NDB_TYPE_FLOAT, ///< 32-bit float. 4 bytes float, can be used in array 251 Double = NDB_TYPE_DOUBLE, ///< 64-bit float. 8 byte float, can be used in array 252 Olddecimal = NDB_TYPE_OLDDECIMAL, ///< MySQL < 5.0 signed decimal, Precision, Scale 253 Olddecimalunsigned = NDB_TYPE_OLDDECIMALUNSIGNED, 254 Decimal = NDB_TYPE_DECIMAL, ///< MySQL >= 5.0 signed decimal, Precision, Scale 255 Decimalunsigned = NDB_TYPE_DECIMALUNSIGNED, 256 Char = NDB_TYPE_CHAR, ///< Len. A fixed array of 1-byte chars 257 Varchar = NDB_TYPE_VARCHAR, ///< Length bytes: 1, Max: 255 258 Binary = NDB_TYPE_BINARY, ///< Len 259 Varbinary = NDB_TYPE_VARBINARY, ///< Length bytes: 1, Max: 255 260 Datetime = NDB_TYPE_DATETIME, ///< Precision down to 1 sec (sizeof(Datetime) == 8 bytes ) 261 Date = NDB_TYPE_DATE, ///< Precision down to 1 day(sizeof(Date) == 4 bytes ) 262 Blob = NDB_TYPE_BLOB, ///< Binary large object (see NdbBlob) 263 Text = NDB_TYPE_TEXT, ///< Text blob 264 Bit = NDB_TYPE_BIT, ///< Bit, length specifies no of bits 265 Longvarchar = NDB_TYPE_LONGVARCHAR, ///< Length bytes: 2, little-endian 266 Longvarbinary = NDB_TYPE_LONGVARBINARY, ///< Length bytes: 2, little-endian 267 Time = NDB_TYPE_TIME, ///< Time without date 268 Year = NDB_TYPE_YEAR, ///< Year 1901-2155 (1 byte) 269 Timestamp = NDB_TYPE_TIMESTAMP ///< Unix time 270 }; 271 272 /* 273 * Array type specifies internal attribute format. 274 * 275 * - ArrayTypeFixed is stored as fixed number of bytes. This type 276 * is fastest to access but can waste space. 277 * 278 * - ArrayTypeVar is stored as variable number of bytes with a fixed 279 * overhead of 2 bytes. 280 * 281 * Default is ArrayTypeVar for Var* types and ArrayTypeFixed for 282 * others. The default is normally ok. 283 */ 284 enum ArrayType { 285 ArrayTypeFixed = NDB_ARRAYTYPE_FIXED, // 0 length bytes 286 ArrayTypeShortVar = NDB_ARRAYTYPE_SHORT_VAR, // 1 length bytes 287 ArrayTypeMediumVar = NDB_ARRAYTYPE_MEDIUM_VAR // 2 length bytes 288 }; 289 290 /* 291 * Storage type specifies whether attribute is stored in memory or 292 * on disk. Default is memory. Disk attributes are potentially 293 * much slower to access and cannot be indexed in version 5.1. 294 */ 295 enum StorageType { 296 StorageTypeMemory = NDB_STORAGETYPE_MEMORY, 297 StorageTypeDisk = NDB_STORAGETYPE_DISK, 298 StorageTypeDefault = NDB_STORAGETYPE_DEFAULT 299 }; 300 301 /** 302 * @name General 303 * @{ 304 */ 305 306 /** 307 * Get name of column 308 * @return Name of the column 309 */ 310 const char* getName() const; 311 312 /** 313 * Get if the column is nullable or not 314 */ 315 bool getNullable() const; 316 317 /** 318 * Check if column is part of primary key 319 */ 320 bool getPrimaryKey() const; 321 322 /** 323 * Get number of column (horizontal position within table) 324 */ 325 int getColumnNo() const; 326 327 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 328 int getAttrId() const; 329 #endif 330 331 /** 332 * Check if column is equal to some other column 333 * @param column Column to compare with 334 * @return true if column is equal to some other column otherwise false. 335 */ 336 bool equal(const Column& column) const; 337 338 339 /** @} *******************************************************************/ 340 /** 341 * @name Get Type Specifiers 342 * @{ 343 */ 344 345 /** 346 * Get type of column 347 */ 348 Type getType() const; 349 350 /** 351 * Get precision of column. 352 * @note Only applicable for decimal types 353 */ 354 int getPrecision() const; 355 356 /** 357 * Get scale of column. 358 * @note Only applicable for decimal types 359 */ 360 int getScale() const; 361 362 /** 363 * Get length for column 364 * Array length for column or max length for variable length arrays. 365 */ 366 int getLength() const; 367 368 /** 369 * For Char or Varchar or Text, get MySQL CHARSET_INFO. This 370 * specifies both character set and collation. See get_charset() 371 * etc in MySQL. (The cs is not "const" in MySQL). 372 */ 373 CHARSET_INFO* getCharset() const; 374 375 /** 376 * Returns mysql's internal number for the column's character set. 377 */ 378 int getCharsetNumber() const; 379 380 /** 381 * For blob, get "inline size" i.e. number of initial bytes 382 * to store in table's blob attribute. 383 */ 384 int getInlineSize() const; 385 386 /** 387 * For blob, get "part size" i.e. number of bytes to store in 388 * each tuple of the "blob table". Can be set to zero to omit parts 389 * and to allow only inline bytes ("tinyblob"). 390 */ 391 int getPartSize() const; 392 393 /** 394 * For blob, set or get "stripe size" i.e. number of consecutive 395 * <em>parts</em> to store in each node group. 396 */ 397 int getStripeSize() const; 398 399 /** 400 * Get size of element 401 */ 402 int getSize() const; 403 404 /** 405 * Check if column is part of partition key 406 * 407 * A <em>partition key</em> is a set of attributes which are used 408 * to distribute the tuples onto the NDB nodes. 409 * The partition key uses the NDB Cluster hashing function. 410 * 411 * An example where this is useful is TPC-C where it might be 412 * good to use the warehouse id and district id as the partition key. 413 * This would place all data for a specific district and warehouse 414 * in the same database node. 415 * 416 * Locally in the fragments the full primary key 417 * will still be used with the hashing algorithm. 418 * 419 * @return true then the column is part of 420 * the partition key. 421 */ 422 bool getPartitionKey() const; 423 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED getDistributionKey() const424 inline bool getDistributionKey() const { return getPartitionKey(); }; 425 #endif 426 427 ArrayType getArrayType() const; 428 StorageType getStorageType() const; 429 430 /** 431 * Get if the column is dynamic (NULL values not stored) 432 */ 433 bool getDynamic() const; 434 435 /** 436 * Determine if the column is defined relative to an Index 437 * This affects the meaning of the attrId, column no and primary key, 438 */ 439 bool getIndexSourced() const; 440 441 /** @} *******************************************************************/ 442 443 444 /** 445 * @name Column creation 446 * @{ 447 * 448 * These operations should normally not be performed in an NbdApi program 449 * as results will not be visable in the MySQL Server 450 * 451 */ 452 453 /** 454 * Constructor 455 * @param name Name of column 456 */ 457 Column(const char * name = ""); 458 /** 459 * Copy constructor 460 * @param column Column to be copied 461 */ 462 Column(const Column& column); 463 ~Column(); 464 465 /** 466 * Set name of column 467 * @param name Name of the column 468 */ 469 int setName(const char * name); 470 471 /** 472 * Set whether column is nullable or not 473 */ 474 void setNullable(bool); 475 476 /** 477 * Set that column is part of primary key 478 */ 479 void setPrimaryKey(bool); 480 481 /** 482 * Set type of column 483 * @param type Type of column 484 * 485 * @note setType resets <em>all</em> column attributes 486 * to (type dependent) defaults and should be the first 487 * method to call. Default type is Unsigned. 488 */ 489 void setType(Type type); 490 491 /** 492 * Set precision of column. 493 * @note Only applicable for decimal types 494 */ 495 void setPrecision(int); 496 497 /** 498 * Set scale of column. 499 * @note Only applicable for decimal types 500 */ 501 void setScale(int); 502 503 /** 504 * Set length for column 505 * Array length for column or max length for variable length arrays. 506 */ 507 void setLength(int length); 508 509 /** 510 * For Char or Varchar or Text, get MySQL CHARSET_INFO. This 511 * specifies both character set and collation. See get_charset() 512 * etc in MySQL. (The cs is not "const" in MySQL). 513 */ 514 void setCharset(CHARSET_INFO* cs); 515 516 /** 517 * For blob, set "inline size" i.e. number of initial bytes 518 * to store in table's blob attribute. This part is normally in 519 * main memory. It can not currently be indexed. 520 */ 521 void setInlineSize(int size); 522 523 /** 524 * For blob, set "part size" i.e. number of bytes to store in 525 * each tuple of the "blob table". Can be set to zero to omit parts 526 * and to allow only inline bytes ("tinyblob"). 527 */ 528 void setPartSize(int size); 529 530 /** 531 * For blob, set "stripe size" i.e. number of consecutive 532 * <em>parts</em> to store in a fragment, before moving to 533 * another (random) fragment. 534 * 535 * Striping may improve performance for large blobs 536 * since blob part operations are done in parallel. 537 * Optimal stripe size depends on the transport e.g. tcp/ip. 538 * 539 * Example: Given part size 2048 bytes, set stripe size 8. 540 * This assigns i/o in 16k chunks to each fragment. 541 * 542 * Blobs V1 required non-zero stripe size. Blobs V2 543 * (created in version >= 5.1.x) have following behaviour: 544 * 545 * Default stripe size is zero, which means no striping and 546 * also that blob part data is stored in the same node group 547 * as the primary table row. This is done by giving blob parts 548 * table same partition key as the primary table. 549 */ 550 void setStripeSize(int size); 551 552 /** 553 * Set partition key 554 * @see getPartitionKey 555 * 556 * @param enable If set to true, then the column will be part of 557 * the partition key. 558 */ 559 void setPartitionKey(bool enable); 560 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED setDistributionKey(bool enable)561 inline void setDistributionKey(bool enable) 562 { setPartitionKey(enable); }; 563 #endif 564 565 void setArrayType(ArrayType type); 566 void setStorageType(StorageType type); 567 568 /** 569 * Set whether column is dynamic. 570 */ 571 void setDynamic(bool); 572 573 /** @} *******************************************************************/ 574 575 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED 576 int setDefaultValue(const char*); 577 #endif 578 /* setDefaultValue 579 * Set buf to NULL for no default value, or null default value for 580 * NULLABLE column, otherwise set buf to pointer to default value. 581 * The len parameter is the number of significant bytes of default 582 * value supplied, which is the type size for fixed size types. 583 * For variable length types, the leading 1 or 2 bytes pointed to 584 * by buf also contain length information as normal for the type. 585 */ 586 int setDefaultValue(const void* buf, unsigned int len); 587 588 /* getDefaultValue 589 * Get the default value data for this column. 590 * Optional int len* will be updated with the significant length 591 * of the default value, or set to 0 for NULL or no default. 592 */ 593 const void* getDefaultValue(unsigned int* len = 0) const; 594 595 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 596 const Table * getBlobTable() const; 597 598 void setAutoIncrement(bool); 599 bool getAutoIncrement() const; 600 void setAutoIncrementInitialValue(Uint64 val); 601 602 static const Column * FRAGMENT; 603 static const Column * FRAGMENT_FIXED_MEMORY; 604 static const Column * FRAGMENT_VARSIZED_MEMORY; 605 static const Column * ROW_COUNT; 606 static const Column * COMMIT_COUNT; 607 static const Column * ROW_SIZE; 608 static const Column * RANGE_NO; 609 static const Column * DISK_REF; 610 static const Column * RECORDS_IN_RANGE; 611 static const Column * ROWID; 612 static const Column * ROW_GCI; 613 static const Column * ROW_GCI64; 614 static const Column * ROW_AUTHOR; 615 static const Column * ANY_VALUE; 616 static const Column * COPY_ROWID; 617 static const Column * LOCK_REF; 618 static const Column * OP_ID; 619 static const Column * OPTIMIZE; 620 static const Column * FRAGMENT_EXTENT_SPACE; 621 static const Column * FRAGMENT_FREE_EXTENT_SPACE; 622 623 int getSizeInBytes() const; 624 625 int getBlobVersion() const; // NDB_BLOB_V1 or NDB_BLOB_V2 626 void setBlobVersion(int blobVersion); // default NDB_BLOB_V2 627 628 /** 629 * 0 = yes 630 * -1 = no 631 */ 632 int isBindable(const Column&) const; 633 #endif 634 635 private: 636 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 637 friend class NdbRecAttr; 638 friend class NdbColumnImpl; 639 #endif 640 class NdbColumnImpl & m_impl; 641 Column(NdbColumnImpl&); 642 Column& operator=(const Column&); 643 }; 644 645 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 646 /** 647 * ??? 648 */ 649 typedef Column Attribute; 650 #endif 651 652 /** 653 * @brief Represents a table in NDB Cluster 654 * 655 * <em>TableSize</em><br> 656 * When calculating the data storage one should add the size of all 657 * attributes (each attributeconsumes at least 4 bytes) and also an overhead 658 * of 12 byte. Variable size attributes (not supported yet) will have a 659 * size of 12 bytes plus the actual data storage parts where there is an 660 * additional overhead based on the size of the variable part.<br> 661 * An example table with 5 attributes: 662 * one 64 bit attribute, one 32 bit attribute, 663 * two 16 bit attributes and one array of 64 8 bits. 664 * This table will consume 665 * 12 (overhead) + 8 + 4 + 2*4 (4 is minimum) + 64 = 96 bytes per record. 666 * Additionally an overhead of about 2 % as page headers and waste should 667 * be allocated. Thus, 1 million records should consume 96 MBytes 668 * plus the overhead 2 MByte and rounded up to 100 000 kBytes.<br> 669 * 670 */ 671 class Table : public Object { 672 public: 673 /* 674 * Single user mode specifies access rights to table during single user mode 675 */ 676 enum SingleUserMode { 677 SingleUserModeLocked = NDB_SUM_LOCKED, 678 SingleUserModeReadOnly = NDB_SUM_READONLY, 679 SingleUserModeReadWrite = NDB_SUM_READ_WRITE 680 }; 681 682 /** 683 * @name General 684 * @{ 685 */ 686 687 /** 688 * Get table name 689 */ 690 const char * getName() const; 691 692 /** 693 * Get table id 694 */ 695 int getTableId() const; 696 697 /** 698 * Get column definition via name. 699 * @return null if none existing name 700 */ 701 const Column* getColumn(const char * name) const; 702 703 /** 704 * Get column definition via index in table. 705 * @return null if none existing name 706 */ 707 Column* getColumn(const int attributeId); 708 709 /** 710 * Get column definition via name. 711 * @return null if none existing name 712 */ 713 Column* getColumn(const char * name); 714 715 /** 716 * Get column definition via index in table. 717 * @return null if none existing name 718 */ 719 const Column* getColumn(const int attributeId) const; 720 721 /** @} *******************************************************************/ 722 /** 723 * @name Storage 724 * @{ 725 */ 726 727 /** 728 * If set to false, then the table is a temporary 729 * table and is not logged to disk. 730 * 731 * In case of a system restart the table will still 732 * be defined and exist but will be empty. 733 * Thus no checkpointing and no logging is performed on the table. 734 * 735 * The default value is true and indicates a normal table 736 * with full checkpointing and logging activated. 737 */ 738 bool getLogging() const; 739 740 /** 741 * Get fragmentation type 742 */ 743 FragmentType getFragmentType() const; 744 745 /** 746 * Get KValue (Hash parameter.) 747 * Only allowed value is 6. 748 * Later implementations might add flexibility in this parameter. 749 */ 750 int getKValue() const; 751 752 /** 753 * Get MinLoadFactor (Hash parameter.) 754 * This value specifies the load factor when starting to shrink 755 * the hash table. 756 * It must be smaller than MaxLoadFactor. 757 * Both these factors are given in percentage. 758 */ 759 int getMinLoadFactor() const; 760 761 /** 762 * Get MaxLoadFactor (Hash parameter.) 763 * This value specifies the load factor when starting to split 764 * the containers in the local hash tables. 765 * 100 is the maximum which will optimize memory usage. 766 * A lower figure will store less information in each container and thus 767 * find the key faster but consume more memory. 768 */ 769 int getMaxLoadFactor() const; 770 771 /** @} *******************************************************************/ 772 /** 773 * @name Other 774 * @{ 775 */ 776 777 /** 778 * Get number of columns in the table 779 */ 780 int getNoOfColumns() const; 781 782 /** 783 * Get number of auto_increment columns in the table 784 */ 785 int getNoOfAutoIncrementColumns() const; 786 787 /** 788 * Get number of primary keys in the table 789 */ 790 int getNoOfPrimaryKeys() const; 791 792 /** 793 * Get name of primary key 794 */ 795 const char* getPrimaryKey(int no) const; 796 797 /** 798 * Check if table is equal to some other table 799 */ 800 bool equal(const Table&) const; 801 802 /** 803 * Get frm file stored with this table 804 */ 805 const void* getFrmData() const; 806 Uint32 getFrmLength() const; 807 808 /** 809 * Get default NdbRecord object for this table 810 * This NdbRecord object becomes invalid at the same time as 811 * the table object - when the ndb_cluster_connection is closed. 812 */ 813 const NdbRecord* getDefaultRecord() const; 814 815 /** @} *******************************************************************/ 816 817 /** 818 * @name Table creation 819 * @{ 820 * 821 * These methods should normally not be used in an application as 822 * the result is not accessible from the MySQL Server 823 * 824 */ 825 826 /** 827 * Constructor 828 * @param name Name of table 829 */ 830 Table(const char * name = ""); 831 832 /** 833 * Copy constructor 834 * @param table Table to be copied 835 */ 836 Table(const Table& table); 837 virtual ~Table(); 838 839 /** 840 * Assignment operator, deep copy 841 * @param table Table to be copied 842 */ 843 Table& operator=(const Table& table); 844 845 /** 846 * Name of table 847 * @param name Name of table 848 */ 849 int setName(const char * name); 850 851 /** 852 * Add a column definition to a table 853 * @note creates a copy 854 */ 855 int addColumn(const Column &); 856 857 /** 858 * @see NdbDictionary::Table::getLogging. 859 */ 860 void setLogging(bool); 861 862 /** 863 * Set/Get Linear Hash Flag 864 */ 865 void setLinearFlag(Uint32 flag); 866 bool getLinearFlag() const; 867 868 /** 869 * Set fragment count 870 */ 871 void setFragmentCount(Uint32); 872 873 /** 874 * Get fragment count 875 */ 876 Uint32 getFragmentCount() const; 877 878 /** 879 * Set fragmentation type 880 */ 881 void setFragmentType(FragmentType); 882 883 /** 884 * Set KValue (Hash parameter.) 885 * Only allowed value is 6. 886 * Later implementations might add flexibility in this parameter. 887 */ 888 void setKValue(int kValue); 889 890 /** 891 * Set MinLoadFactor (Hash parameter.) 892 * This value specifies the load factor when starting to shrink 893 * the hash table. 894 * It must be smaller than MaxLoadFactor. 895 * Both these factors are given in percentage. 896 */ 897 void setMinLoadFactor(int); 898 899 /** 900 * Set MaxLoadFactor (Hash parameter.) 901 * This value specifies the load factor when starting to split 902 * the containers in the local hash tables. 903 * 100 is the maximum which will optimize memory usage. 904 * A lower figure will store less information in each container and thus 905 * find the key faster but consume more memory. 906 */ 907 void setMaxLoadFactor(int); 908 909 int setTablespaceName(const char * name); 910 const char * getTablespaceName() const; 911 int setTablespace(const class Tablespace &); 912 bool getTablespace(Uint32 *id= 0, Uint32 *version= 0) const; 913 914 bool getHashMap(Uint32* id = 0, Uint32* version = 0) const; 915 int setHashMap(const class HashMap &); 916 917 /** 918 * Get table object type 919 */ 920 Object::Type getObjectType() const; 921 922 /** 923 * Get object status 924 */ 925 virtual Object::Status getObjectStatus() const; 926 void setStatusInvalid() const; 927 928 /** 929 * Get object version 930 */ 931 virtual int getObjectVersion() const; 932 933 /** 934 * Set/Get indicator if default number of partitions is used in table. 935 */ 936 void setDefaultNoPartitionsFlag(Uint32 indicator); 937 Uint32 getDefaultNoPartitionsFlag() const; 938 939 /** 940 * Get object id 941 */ 942 virtual int getObjectId() const; 943 944 /** 945 * Set frm file to store with this table 946 */ 947 int setFrm(const void* data, Uint32 len); 948 949 /** 950 * Set fragmentation 951 * One Uint32 per fragment, containing nodegroup of fragment 952 * nodegroups[0] - correspondce to fragment 0 953 * 954 * Note: This calls also modifies <em>setFragmentCount</em> 955 * 956 */ 957 int setFragmentData(const Uint32 * nodegroups, Uint32 cnt); 958 959 /** 960 * Get Fragment Data (array of node groups) 961 */ 962 const Uint32 *getFragmentData() const; 963 Uint32 getFragmentDataLen() const; 964 965 /** 966 * Set array of information mapping range values and list values 967 * to fragments. 968 * 969 * For range, this is a sorted list of range values 970 * For list, this is a list of pairs { value, partition } 971 */ 972 int setRangeListData(const Int32* data, Uint32 cnt); 973 974 /** 975 * Get Range or List Array (value, partition) 976 */ 977 const Int32 *getRangeListData() const; 978 Uint32 getRangeListDataLen() const; 979 980 /** 981 * Get list of nodes storing given fragment, primary 982 * is normally entry 0 983 * Returns : 0 for error, > 0 for fragment count 984 * If fragment count is > arraySize param, only arraySize 985 * entries are written. 986 */ 987 Uint32 getFragmentNodes(Uint32 fragmentId, 988 Uint32* nodeIdArrayPtr, 989 Uint32 arraySize) const; 990 991 /** 992 * Set table object type 993 */ 994 void setObjectType(Object::Type type); 995 996 /** 997 * Set/Get Maximum number of rows in table (only used to calculate 998 * number of partitions). 999 */ 1000 void setMaxRows(Uint64 maxRows); 1001 Uint64 getMaxRows() const; 1002 1003 /** 1004 * Set/Get Minimum number of rows in table (only used to calculate 1005 * number of partitions). 1006 */ 1007 void setMinRows(Uint64 minRows); 1008 Uint64 getMinRows() const; 1009 1010 /** 1011 * Set/Get SingleUserMode 1012 */ 1013 void setSingleUserMode(enum SingleUserMode); 1014 enum SingleUserMode getSingleUserMode() const; 1015 1016 1017 /** @} *******************************************************************/ 1018 1019 /** 1020 * 1021 */ 1022 void setRowGCIIndicator(bool value); 1023 bool getRowGCIIndicator() const; 1024 1025 void setRowChecksumIndicator(bool value); 1026 bool getRowChecksumIndicator() const; 1027 1028 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1029 const char *getMysqlName() const; 1030 setStoredTable(bool x)1031 void setStoredTable(bool x) { setLogging(x); } getStoredTable() const1032 bool getStoredTable() const { return getLogging(); } 1033 1034 int getRowSizeInBytes() const ; 1035 int createTableInDb(Ndb*, bool existingEqualIsOk = true) const ; 1036 1037 int getReplicaCount() const ; 1038 1039 bool getTemporary() const; 1040 void setTemporary(bool); 1041 1042 /** 1043 * Only table with varpart do support online add column 1044 * Add property so that table wo/ varsize column(s) still 1045 * allocates varpart-ref, so that later online add column is possible 1046 */ 1047 bool getForceVarPart() const; 1048 void setForceVarPart(bool); 1049 1050 /** 1051 * Check if any of column in bitmaps are disk columns 1052 * returns bitmap of different columns 1053 * bit 0 = atleast 1 pk column is set 1054 * bit 1 = atleast 1 disk column set 1055 * bit 2 = atleast 1 non disk column set 1056 * passing NULL pointer will equal to bitmap with all columns set 1057 */ 1058 int checkColumns(const Uint32* bitmap, unsigned len_in_bytes) const; 1059 1060 /** 1061 * Set tableId,tableVersion on a table... 1062 * this is a "work-around" since createIndex can't (currently) 1063 * accept an ObjectId instead of table-object in createIndex 1064 * this as way way too much stuff is pushed into NdbDictInterface 1065 */ 1066 void assignObjId(const ObjectId &); 1067 1068 /** 1069 * set/get table-storage-method 1070 */ 1071 void setStorageType(Column::StorageType); 1072 Column::StorageType getStorageType() const; 1073 1074 /** 1075 * Get/set extra GCI bits (max 31) 1076 */ 1077 void setExtraRowGciBits(Uint32); 1078 Uint32 getExtraRowGciBits() const; 1079 1080 /** 1081 * Get/set extra row author bits (max 31) 1082 */ 1083 void setExtraRowAuthorBits(Uint32); 1084 Uint32 getExtraRowAuthorBits() const; 1085 #endif 1086 1087 // these 2 are not de-doxygenated 1088 1089 /** 1090 * This method is not needed in normal usage. 1091 * 1092 * Compute aggregate data on table being defined. Required for 1093 * aggregate methods such as getNoOfPrimaryKeys() to work before 1094 * table has been created and retrieved via getTable(). 1095 * 1096 * May adjust some column flags. If no PK is so far marked as 1097 * distribution key then all PK's will be marked. 1098 * 1099 * Returns 0 on success. Returns -1 and sets error if an 1100 * inconsistency is detected. 1101 */ 1102 int aggregate(struct NdbError& error); 1103 1104 /** 1105 * This method is not needed in normal usage. 1106 * 1107 * Validate new table definition before create. Does aggregate() 1108 * and additional checks. There may still be errors which are 1109 * detected only by NDB kernel at create table. 1110 * 1111 * Create table and retrieve table do validate() automatically. 1112 * 1113 * Returns 0 on success. Returns -1 and sets error if an 1114 * inconsistency is detected. 1115 */ 1116 int validate(struct NdbError& error); 1117 1118 /** 1119 * Return partitionId given a hashvalue 1120 * Note, if table is not retreived (e.i using getTable) result 1121 * will most likely be wrong 1122 */ 1123 Uint32 getPartitionId(Uint32 hashvalue) const ; 1124 1125 /* 1126 * Return TRUE if any of the columns in the table have a 1127 * non NULL default value defined 1128 */ 1129 bool hasDefaultValues() const; 1130 1131 private: 1132 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1133 friend class Ndb; 1134 friend class NdbDictionaryImpl; 1135 friend class NdbTableImpl; 1136 friend class NdbEventOperationImpl; 1137 #endif 1138 class NdbTableImpl & m_impl; 1139 Table(NdbTableImpl&); 1140 }; 1141 1142 /** 1143 * @class Index 1144 * @brief Represents an index in an NDB Cluster 1145 */ 1146 class Index : public Object { 1147 public: 1148 1149 /** 1150 * @name Getting Index properties 1151 * @{ 1152 */ 1153 1154 /** 1155 * Get the name of an index 1156 */ 1157 const char * getName() const; 1158 1159 /** 1160 * Get the name of the underlying table being indexed 1161 */ 1162 const char * getTable() const; 1163 1164 /** 1165 * Get the number of columns in the index 1166 */ 1167 unsigned getNoOfColumns() const; 1168 1169 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED 1170 /** 1171 * Get the number of columns in the index 1172 * Deprecated, use getNoOfColumns instead. 1173 */ 1174 int getNoOfIndexColumns() const; 1175 #endif 1176 1177 /** 1178 * Get a specific column in the index 1179 */ 1180 const Column * getColumn(unsigned no) const ; 1181 1182 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED 1183 /** 1184 * Get a specific column name in the index 1185 * Deprecated, use getColumn instead. 1186 */ 1187 const char * getIndexColumn(int no) const ; 1188 #endif 1189 1190 /** 1191 * Represents type of index 1192 */ 1193 enum Type { 1194 Undefined = 0, ///< Undefined object type (initial value) 1195 UniqueHashIndex = 3, ///< Unique un-ordered hash index 1196 ///< (only one currently supported) 1197 OrderedIndex = 6 ///< Non-unique ordered index 1198 }; 1199 1200 /** 1201 * Get index type of the index 1202 */ 1203 Type getType() const; 1204 1205 /** 1206 * Check if index is set to be stored on disk 1207 * 1208 * @return if true then logging is enabled 1209 * 1210 * @note Non-logged indexes are rebuilt at system restart. 1211 * @note Ordered index does not currently support logging. 1212 */ 1213 bool getLogging() const; 1214 1215 /** 1216 * Get object status 1217 */ 1218 virtual Object::Status getObjectStatus() const; 1219 1220 /** 1221 * Get object version 1222 */ 1223 virtual int getObjectVersion() const; 1224 1225 /** 1226 * Get object id 1227 */ 1228 virtual int getObjectId() const; 1229 1230 /** 1231 * Get default NdbRecord object for this index 1232 * This NdbRecord object becomes invalid at the same time as 1233 * the index object does - when the ndb_cluster_connection 1234 * is closed. 1235 */ 1236 const NdbRecord* getDefaultRecord() const; 1237 1238 /** @} *******************************************************************/ 1239 1240 /** 1241 * @name Index creation 1242 * @{ 1243 * 1244 * These methods should normally not be used in an application as 1245 * the result will not be visible from the MySQL Server 1246 * 1247 */ 1248 1249 /** 1250 * Constructor 1251 * @param name Name of index 1252 */ 1253 Index(const char * name = ""); 1254 virtual ~Index(); 1255 1256 /** 1257 * Set the name of an index 1258 */ 1259 int setName(const char * name); 1260 1261 /** 1262 * Define the name of the table to be indexed 1263 */ 1264 int setTable(const char * name); 1265 1266 /** 1267 * Add a column to the index definition 1268 * Note that the order of columns will be in 1269 * the order they are added (only matters for ordered indexes). 1270 */ 1271 int addColumn(const Column & c); 1272 1273 /** 1274 * Add a column name to the index definition 1275 * Note that the order of indexes will be in 1276 * the order they are added (only matters for ordered indexes). 1277 */ 1278 int addColumnName(const char * name); 1279 1280 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED 1281 /** 1282 * Add a column name to the index definition 1283 * Note that the order of indexes will be in 1284 * the order they are added (only matters for ordered indexes). 1285 * Deprecated, use addColumnName instead. 1286 */ 1287 int addIndexColumn(const char * name); 1288 #endif 1289 1290 /** 1291 * Add several column names to the index definition 1292 * Note that the order of indexes will be in 1293 * the order they are added (only matters for ordered indexes). 1294 */ 1295 int addColumnNames(unsigned noOfNames, const char ** names); 1296 1297 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED 1298 /** 1299 * Add several column names to the index definition 1300 * Note that the order of indexes will be in 1301 * the order they are added (only matters for ordered indexes). 1302 * Deprecated, use addColumnNames instead. 1303 */ 1304 int addIndexColumns(int noOfNames, const char ** names); 1305 #endif 1306 1307 /** 1308 * Set index type of the index 1309 */ 1310 void setType(Type type); 1311 1312 /** 1313 * Enable/Disable index storage on disk 1314 * 1315 * @param enable If enable is set to true, then logging becomes enabled 1316 * 1317 * @see NdbDictionary::Index::getLogging 1318 */ 1319 void setLogging(bool enable); 1320 1321 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED setStoredIndex(bool x)1322 void setStoredIndex(bool x) { setLogging(x); } getStoredIndex() const1323 bool getStoredIndex() const { return getLogging(); } 1324 1325 bool getTemporary() const; 1326 void setTemporary(bool); 1327 #endif 1328 1329 /** @} *******************************************************************/ 1330 1331 private: 1332 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1333 friend class NdbIndexImpl; 1334 friend class NdbIndexStat; 1335 #endif 1336 class NdbIndexImpl & m_impl; 1337 Index(NdbIndexImpl&); 1338 }; 1339 1340 /** 1341 * @brief Represents a Table Optimization Handle 1342 * Passed as argument to optimizeTable 1343 */ 1344 class OptimizeTableHandle { 1345 public: 1346 /** 1347 * Supported operations for OptimizeTableHandle 1348 */ 1349 OptimizeTableHandle(); 1350 ~OptimizeTableHandle(); 1351 /** 1352 * Optimize one more batch of records 1353 * @return 1 for more records left to optimize, 1354 * 0 when completed 1355 * -1 encountered some error 1356 */ 1357 int next(); 1358 /** 1359 * Close the handle object 1360 * @return 0 when completed 1361 * -1 encountered some error 1362 */ 1363 int close(); 1364 private: 1365 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1366 friend class NdbOptimizeTableHandleImpl; 1367 friend class NdbOptimizeIndexHandleImpl; 1368 friend class NdbDicitionaryImpl; 1369 #endif 1370 class NdbOptimizeTableHandleImpl & m_impl; 1371 OptimizeTableHandle(NdbOptimizeTableHandleImpl &); 1372 }; 1373 1374 /** 1375 * @brief Represents a Index Optimization Handle 1376 * passed as argument to optimizeIndex 1377 */ 1378 class OptimizeIndexHandle { 1379 public: 1380 /** 1381 * Supported operations for OptimizeIndexHandle 1382 */ 1383 OptimizeIndexHandle(); 1384 ~OptimizeIndexHandle(); 1385 /** 1386 * Optimize one more batch of records 1387 * @return 1 for more records left to optimize, 1388 * 0 when completed 1389 * -1 encountered some error 1390 */ 1391 int next(); 1392 /** 1393 * Close the handle object 1394 * @return 0 when completed 1395 * -1 encountered some error 1396 */ 1397 int close(); 1398 private: 1399 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1400 friend class NdbOptimizeIndexHandleImpl; 1401 friend class NdbDicitionaryImpl; 1402 #endif 1403 class NdbOptimizeIndexHandleImpl & m_impl; 1404 OptimizeIndexHandle(NdbOptimizeIndexHandleImpl &); 1405 }; 1406 1407 /** 1408 * @brief Represents an Event in NDB Cluster 1409 * 1410 */ 1411 class Event : public Object { 1412 public: 1413 /** 1414 * Specifies the type of database operations an Event listens to 1415 */ 1416 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1417 /** TableEvent must match 1 << TriggerEvent */ 1418 #endif 1419 enum TableEvent { 1420 TE_INSERT =1<<0, ///< Insert event on table 1421 TE_DELETE =1<<1, ///< Delete event on table 1422 TE_UPDATE =1<<2, ///< Update event on table 1423 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1424 TE_SCAN =1<<3, ///< Scan event on table 1425 TE_FIRST_NON_DATA_EVENT =1<<4, 1426 #endif 1427 TE_DROP =1<<4, ///< Drop of table 1428 TE_ALTER =1<<5, ///< Alter of table 1429 TE_CREATE =1<<6, ///< Create of table 1430 TE_GCP_COMPLETE=1<<7, ///< GCP is complete 1431 TE_CLUSTER_FAILURE=1<<8, ///< Cluster is unavailable 1432 TE_STOP =1<<9, ///< Stop of event operation 1433 TE_NODE_FAILURE=1<<10, ///< Node failed 1434 TE_SUBSCRIBE =1<<11, ///< Node subscribes 1435 TE_UNSUBSCRIBE =1<<12, ///< Node unsubscribes 1436 TE_ALL=0xFFFF ///< Any/all event on table (not relevant when 1437 ///< events are received) 1438 }; 1439 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1440 enum _TableEvent { 1441 _TE_INSERT=0, 1442 _TE_DELETE=1, 1443 _TE_UPDATE=2, 1444 _TE_SCAN=3, 1445 _TE_FIRST_NON_DATA_EVENT=4, 1446 _TE_DROP=4, 1447 _TE_ALTER=5, 1448 _TE_CREATE=6, 1449 _TE_GCP_COMPLETE=7, 1450 _TE_CLUSTER_FAILURE=8, 1451 _TE_STOP=9, 1452 _TE_NODE_FAILURE=10, 1453 _TE_SUBSCRIBE=11, 1454 _TE_UNSUBSCRIBE=12, 1455 _TE_NUL=13, // internal (e.g. INS o DEL within same GCI) 1456 _TE_ACTIVE=14 // internal (node becomes active) 1457 }; 1458 #endif 1459 /** 1460 * Specifies the durability of an event 1461 * (future version may supply other types) 1462 */ 1463 enum EventDurability { 1464 ED_UNDEFINED 1465 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1466 = 0 1467 #endif 1468 #if 0 // not supported 1469 ,ED_SESSION = 1, 1470 // Only this API can use it 1471 // and it's deleted after api has disconnected or ndb has restarted 1472 1473 ED_TEMPORARY = 2 1474 // All API's can use it, 1475 // But's its removed when ndb is restarted 1476 #endif 1477 ,ED_PERMANENT ///< All API's can use it. 1478 ///< It's still defined after a cluster system restart 1479 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1480 = 3 1481 #endif 1482 }; 1483 1484 /** 1485 * Specifies reporting options for table events 1486 */ 1487 enum EventReport { 1488 ER_UPDATED = 0, 1489 ER_ALL = 1, // except not-updated blob inlines 1490 ER_SUBSCRIBE = 2, 1491 ER_DDL = 4 1492 }; 1493 1494 /** 1495 * Constructor 1496 * @param name Name of event 1497 */ 1498 Event(const char *name); 1499 /** 1500 * Constructor 1501 * @param name Name of event 1502 * @param table Reference retrieved from NdbDictionary 1503 */ 1504 Event(const char *name, const NdbDictionary::Table& table); 1505 virtual ~Event(); 1506 /** 1507 * Set unique identifier for the event 1508 */ 1509 int setName(const char *name); 1510 /** 1511 * Get unique identifier for the event 1512 */ 1513 const char *getName() const; 1514 /** 1515 * Get table that the event is defined on 1516 * 1517 * @return pointer to table or NULL if no table has been defined 1518 */ 1519 const NdbDictionary::Table * getTable() const; 1520 /** 1521 * Define table on which events should be detected 1522 * 1523 * @note calling this method will default to detection 1524 * of events on all columns. Calling subsequent 1525 * addEventColumn calls will override this. 1526 * 1527 * @param table reference retrieved from NdbDictionary 1528 */ 1529 void setTable(const NdbDictionary::Table& table); 1530 /** 1531 * Set table for which events should be detected 1532 * 1533 * @note preferred way is using setTable(const NdbDictionary::Table&) 1534 * or constructor with table object parameter 1535 */ 1536 int setTable(const char *tableName); 1537 /** 1538 * Get table name for events 1539 * 1540 * @return table name 1541 */ 1542 const char* getTableName() const; 1543 /** 1544 * Add type of event that should be detected 1545 */ 1546 void addTableEvent(const TableEvent te); 1547 /** 1548 * Check if a specific table event will be detected 1549 */ 1550 bool getTableEvent(const TableEvent te) const; 1551 /** 1552 * Set durability of the event 1553 */ 1554 void setDurability(EventDurability); 1555 /** 1556 * Get durability of the event 1557 */ 1558 EventDurability getDurability() const; 1559 /** 1560 * Set report option of the event 1561 */ 1562 void setReport(EventReport); 1563 /** 1564 * Get report option of the event 1565 */ 1566 EventReport getReport() const; 1567 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1568 void addColumn(const Column &c); 1569 #endif 1570 /** 1571 * Add a column on which events should be detected 1572 * 1573 * @param attrId Column id 1574 * 1575 * @note errors will mot be detected until createEvent() is called 1576 */ 1577 void addEventColumn(unsigned attrId); 1578 /** 1579 * Add a column on which events should be detected 1580 * 1581 * @param columnName Column name 1582 * 1583 * @note errors will not be detected until createEvent() is called 1584 */ 1585 void addEventColumn(const char * columnName); 1586 /** 1587 * Add several columns on which events should be detected 1588 * 1589 * @param n Number of columns 1590 * @param columnNames Column names 1591 * 1592 * @note errors will mot be detected until 1593 * NdbDictionary::Dictionary::createEvent() is called 1594 */ 1595 void addEventColumns(int n, const char ** columnNames); 1596 1597 /** 1598 * Get no of columns defined in an Event 1599 * 1600 * @return Number of columns, -1 on error 1601 */ 1602 int getNoOfEventColumns() const; 1603 1604 /** 1605 * Get a specific column in the event 1606 */ 1607 const Column * getEventColumn(unsigned no) const; 1608 1609 /** 1610 * The merge events flag is false by default. Setting it true 1611 * implies that events are merged in following ways: 1612 * 1613 * - for given NdbEventOperation associated with this event, 1614 * events on same PK within same GCI are merged into single event 1615 * 1616 * - a blob table event is created for each blob attribute 1617 * and blob events are handled as part of main table events 1618 * 1619 * - blob post/pre data from the blob part events can be read 1620 * via NdbBlob methods as a single value 1621 * 1622 * NOTE: Currently this flag is not inherited by NdbEventOperation 1623 * and must be set on NdbEventOperation explicitly. 1624 */ 1625 void mergeEvents(bool flag); 1626 1627 /** 1628 * Get object status 1629 */ 1630 virtual Object::Status getObjectStatus() const; 1631 1632 /** 1633 * Get object version 1634 */ 1635 virtual int getObjectVersion() const; 1636 1637 /** 1638 * Get object id 1639 */ 1640 virtual int getObjectId() const; 1641 1642 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1643 void print(); 1644 #endif 1645 1646 private: 1647 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 1648 friend class NdbEventImpl; 1649 friend class NdbEventOperationImpl; 1650 #endif 1651 class NdbEventImpl & m_impl; 1652 Event(NdbEventImpl&); 1653 }; 1654 1655 /* Flags for createRecord(). */ 1656 enum NdbRecordFlags { 1657 /* 1658 Use special mysqld varchar format in index keys, used only from 1659 inside mysqld. 1660 */ 1661 RecMysqldShrinkVarchar= 0x1, 1662 /* Use the mysqld record format for bitfields, only used inside mysqld. */ 1663 RecMysqldBitfield= 0x2 1664 }; 1665 struct RecordSpecification { 1666 /* 1667 Column described by this entry (the column maximum size defines field 1668 size in row). 1669 Note that even when creating an NdbRecord for an index, the column 1670 pointers must be to columns obtained from the underlying table, not 1671 from the index itself. 1672 Note that pseudo columns cannot be used as part of a RecordSpecification. 1673 To read pesudo column values, use the extra get value and set value 1674 APIs. 1675 */ 1676 const Column *column; 1677 /* 1678 Offset of data from start of a row. 1679 1680 For reading blobs, the blob handle (NdbBlob *) will be written into the 1681 result row when the operation is created, not the actual blob data. 1682 So at least sizeof(NdbBlob *) must be available in the row. Other 1683 operations do not write the blob handle into the row. 1684 In any case, a blob handle can always be obtained with a call to 1685 NdbOperation/NdbScanOperation::getBlobHandle(). 1686 */ 1687 Uint32 offset; 1688 /* 1689 Offset from start of row of byte containing NULL bit. 1690 Not used for columns that are not NULLable. 1691 */ 1692 Uint32 nullbit_byte_offset; 1693 /* NULL bit, 0-7. Not used for columns that are not NULLable. */ 1694 Uint32 nullbit_bit_in_byte; 1695 }; 1696 1697 /* Types of NdbRecord object */ 1698 enum RecordType { 1699 TableAccess, 1700 IndexAccess 1701 }; 1702 1703 /* 1704 Return the type of the passed NdbRecord object 1705 */ 1706 static RecordType getRecordType(const NdbRecord* record); 1707 1708 /* 1709 Return the name of the table object that the NdbRecord 1710 refers to. 1711 This method returns Null if the NdbRecord object is not a 1712 TableAccess NdbRecord. 1713 */ 1714 static const char* getRecordTableName(const NdbRecord* record); 1715 1716 /* 1717 Return the name of the index object that the NdbRecord 1718 refers to. 1719 This method returns Null if the NdbRecord object is not an 1720 IndexAccess NdbRecord 1721 */ 1722 static const char* getRecordIndexName(const NdbRecord* record); 1723 1724 /* 1725 Get the first Attribute Id specified in the NdbRecord object. 1726 Returns false if no Attribute Ids are specified. 1727 */ 1728 static bool getFirstAttrId(const NdbRecord* record, Uint32& firstAttrId); 1729 1730 /* Get the next Attribute Id specified in the NdbRecord object 1731 after the attribute Id passed in. 1732 Returns false if there are no more attribute Ids 1733 */ 1734 static bool getNextAttrId(const NdbRecord* record, Uint32& attrId); 1735 1736 /* Get offset of the given attribute id's storage from the start 1737 of the NdbRecord row. 1738 Returns false if the attribute id is not present 1739 */ 1740 static bool getOffset(const NdbRecord* record, Uint32 attrId, Uint32& offset); 1741 1742 /* Get offset of the given attribute id's null bit from the start 1743 of the NdbRecord row. 1744 Returns false if the attribute is not present or if the 1745 attribute is not nullable 1746 */ 1747 static bool getNullBitOffset(const NdbRecord* record, 1748 Uint32 attrId, 1749 Uint32& nullbit_byte_offset, 1750 Uint32& nullbit_bit_in_byte); 1751 1752 /* 1753 Return pointer to beginning of storage of data specified by 1754 attrId. 1755 This method looks up the offset of the column which is stored in 1756 the NdbRecord object, and returns the value of row + offset. 1757 There are row-const and non-row-const versions. 1758 1759 @param record : Pointer to NdbRecord object describing the row format 1760 @param row : Pointer to the start of row data 1761 @param attrId : Attribute id of column 1762 @return : Pointer to start of the attribute in the row. Null if the 1763 attribute is not part of the NdbRecord definition 1764 */ 1765 static const char* getValuePtr(const NdbRecord* record, 1766 const char* row, 1767 Uint32 attrId); 1768 1769 static char* getValuePtr(const NdbRecord* record, 1770 char* row, 1771 Uint32 attrId); 1772 1773 /* 1774 Return a bool indicating whether the null bit for the given 1775 column is set to true or false. 1776 The location of the null bit in relation to the row pointer is 1777 obtained from the passed NdbRecord object. 1778 If the column is not nullable, false will be returned. 1779 If the column is not part of the NdbRecord definition, false will 1780 be returned. 1781 1782 @param record : Pointer to NdbRecord object describing the row format 1783 @param row : Pointer to the start of row data 1784 @param attrId : Attibute id of column 1785 @return : true if attrId exists in NdbRecord, is nullable, and null bit 1786 in row is set, false otherwise. 1787 */ 1788 static bool isNull(const NdbRecord* record, 1789 const char* row, 1790 Uint32 attrId); 1791 1792 /* 1793 Set the null bit for the given column to the supplied value. 1794 The offset for the null bit is obtained from the passed 1795 NdbRecord object. 1796 1797 If the attrId is not part of the NdbRecord, or is not nullable 1798 then an error will be returned. 1799 1800 @param record : Pointer to NdbRecord object describing the row format 1801 @param row : Pointer to the start of row data 1802 @param atrId : Attribute id of the column 1803 @param value : Value to set null bit to 1804 @returns : 0 in success, -1 if the attrId is not part of the record, 1805 or is not nullable 1806 */ 1807 static int setNull(const NdbRecord* record, 1808 char* row, 1809 Uint32 attrId, 1810 bool value); 1811 1812 /* 1813 Return the number of bytes needed to store one row of data 1814 laid out as described by the passed NdbRecord structure. 1815 */ 1816 static Uint32 getRecordRowLength(const NdbRecord* record); 1817 1818 /* 1819 Return an empty column presence bitmask. 1820 This bitmask can be used with any NdbRecord to specify that 1821 no NdbRecord columns are to be included in the operation. 1822 */ 1823 static const unsigned char* getEmptyBitmask(); 1824 1825 struct AutoGrowSpecification { 1826 Uint32 min_free; 1827 Uint64 max_size; 1828 Uint64 file_size; 1829 const char * filename_pattern; 1830 }; 1831 1832 /** 1833 * @class LogfileGroup 1834 */ 1835 class LogfileGroup : public Object { 1836 public: 1837 LogfileGroup(); 1838 LogfileGroup(const LogfileGroup&); 1839 virtual ~LogfileGroup(); 1840 1841 void setName(const char * name); 1842 const char* getName() const; 1843 1844 void setUndoBufferSize(Uint32 sz); 1845 Uint32 getUndoBufferSize() const; 1846 1847 void setAutoGrowSpecification(const AutoGrowSpecification&); 1848 const AutoGrowSpecification& getAutoGrowSpecification() const; 1849 1850 Uint64 getUndoFreeWords() const; 1851 1852 /** 1853 * Get object status 1854 */ 1855 virtual Object::Status getObjectStatus() const; 1856 1857 /** 1858 * Get object version 1859 */ 1860 virtual int getObjectVersion() const; 1861 1862 /** 1863 * Get object id 1864 */ 1865 virtual int getObjectId() const; 1866 1867 private: 1868 friend class NdbDictionaryImpl; 1869 friend class NdbLogfileGroupImpl; 1870 class NdbLogfileGroupImpl & m_impl; 1871 LogfileGroup(NdbLogfileGroupImpl&); 1872 }; 1873 1874 /** 1875 * @class Tablespace 1876 */ 1877 class Tablespace : public Object { 1878 public: 1879 Tablespace(); 1880 Tablespace(const Tablespace&); 1881 virtual ~Tablespace(); 1882 1883 void setName(const char * name); 1884 const char* getName() const; 1885 1886 void setExtentSize(Uint32 sz); 1887 Uint32 getExtentSize() const; 1888 1889 void setAutoGrowSpecification(const AutoGrowSpecification&); 1890 const AutoGrowSpecification& getAutoGrowSpecification() const; 1891 1892 void setDefaultLogfileGroup(const char * name); 1893 void setDefaultLogfileGroup(const class LogfileGroup&); 1894 1895 const char * getDefaultLogfileGroup() const; 1896 Uint32 getDefaultLogfileGroupId() const; 1897 1898 /** 1899 * Get object status 1900 */ 1901 virtual Object::Status getObjectStatus() const; 1902 1903 /** 1904 * Get object version 1905 */ 1906 virtual int getObjectVersion() const; 1907 1908 /** 1909 * Get object id 1910 */ 1911 virtual int getObjectId() const; 1912 1913 private: 1914 friend class NdbTablespaceImpl; 1915 class NdbTablespaceImpl & m_impl; 1916 Tablespace(NdbTablespaceImpl&); 1917 }; 1918 1919 class Datafile : public Object { 1920 public: 1921 Datafile(); 1922 Datafile(const Datafile&); 1923 virtual ~Datafile(); 1924 1925 void setPath(const char * name); 1926 const char* getPath() const; 1927 1928 void setSize(Uint64); 1929 Uint64 getSize() const; 1930 Uint64 getFree() const; 1931 1932 int setTablespace(const char * name); 1933 int setTablespace(const class Tablespace &); 1934 const char * getTablespace() const; 1935 void getTablespaceId(ObjectId * dst) const; 1936 1937 void setNode(Uint32 nodeId); 1938 Uint32 getNode() const; 1939 1940 Uint32 getFileNo() const; 1941 1942 /** 1943 * Get object status 1944 */ 1945 virtual Object::Status getObjectStatus() const; 1946 1947 /** 1948 * Get object version 1949 */ 1950 virtual int getObjectVersion() const; 1951 1952 /** 1953 * Get object id 1954 */ 1955 virtual int getObjectId() const; 1956 1957 private: 1958 friend class NdbDatafileImpl; 1959 class NdbDatafileImpl & m_impl; 1960 Datafile(NdbDatafileImpl&); 1961 }; 1962 1963 class Undofile : public Object { 1964 public: 1965 Undofile(); 1966 Undofile(const Undofile&); 1967 virtual ~Undofile(); 1968 1969 void setPath(const char * path); 1970 const char* getPath() const; 1971 1972 void setSize(Uint64); 1973 Uint64 getSize() const; 1974 1975 void setLogfileGroup(const char * name); 1976 void setLogfileGroup(const class LogfileGroup &); 1977 const char * getLogfileGroup() const; 1978 void getLogfileGroupId(ObjectId * dst) const; 1979 1980 void setNode(Uint32 nodeId); 1981 Uint32 getNode() const; 1982 1983 Uint32 getFileNo() const; 1984 1985 /** 1986 * Get object status 1987 */ 1988 virtual Object::Status getObjectStatus() const; 1989 1990 /** 1991 * Get object version 1992 */ 1993 virtual int getObjectVersion() const; 1994 1995 /** 1996 * Get object id 1997 */ 1998 virtual int getObjectId() const; 1999 2000 private: 2001 friend class NdbUndofileImpl; 2002 class NdbUndofileImpl & m_impl; 2003 Undofile(NdbUndofileImpl&); 2004 }; 2005 2006 /** 2007 * @class HashMap 2008 * @brief Represents a HashMap in an NDB Cluster 2009 * 2010 */ 2011 class HashMap : public Object { 2012 public: 2013 HashMap(); 2014 HashMap(const HashMap&); 2015 virtual ~HashMap(); 2016 2017 void setName(const char *); 2018 const char * getName() const; 2019 2020 void setMap(const Uint32* values, Uint32 len); 2021 Uint32 getMapLen() const; 2022 int getMapValues(Uint32* dst, Uint32 len) const; 2023 2024 /** 2025 * equal 2026 * compares *values* only 2027 */ 2028 bool equal(const HashMap&) const; 2029 2030 /** 2031 * Get object status 2032 */ 2033 virtual Object::Status getObjectStatus() const; 2034 2035 /** 2036 * Get object version 2037 */ 2038 virtual int getObjectVersion() const; 2039 2040 /** 2041 * Get object id 2042 */ 2043 virtual int getObjectId() const; 2044 2045 private: 2046 friend class NdbHashMapImpl; 2047 class NdbHashMapImpl & m_impl; 2048 HashMap(NdbHashMapImpl&); 2049 }; 2050 2051 /** 2052 * @class Dictionary 2053 * @brief Dictionary for defining and retreiving meta data 2054 */ 2055 class Dictionary { 2056 public: 2057 /** 2058 * @class List 2059 * @brief Structure for retrieving lists of object names 2060 */ 2061 struct List { 2062 /** 2063 * @struct Element 2064 * @brief Object to be stored in an NdbDictionary::Dictionary::List 2065 */ 2066 struct Element { 2067 unsigned id; ///< Id of object 2068 Object::Type type; ///< Type of object 2069 Object::State state; ///< State of object 2070 Object::Store store; ///< How object is logged 2071 Uint32 temp; ///< Temporary status of object 2072 char * database; ///< In what database the object resides 2073 char * schema; ///< What schema the object is defined in 2074 char * name; ///< Name of object ElementNdbDictionary::Dictionary::List::Element2075 Element() : 2076 id(0), 2077 type(Object::TypeUndefined), 2078 state(Object::StateUndefined), 2079 store(Object::StoreUndefined), 2080 temp(NDB_TEMP_TAB_PERMANENT), 2081 database(0), 2082 schema(0), 2083 name(0) { 2084 } 2085 }; 2086 unsigned count; ///< Number of elements in list 2087 Element * elements; ///< Pointer to array of elements ListNdbDictionary::Dictionary::List2088 List() : count(0), elements(0) {} ~ListNdbDictionary::Dictionary::List2089 ~List() { 2090 if (elements != 0) { 2091 for (unsigned i = 0; i < count; i++) { 2092 delete[] elements[i].database; 2093 delete[] elements[i].schema; 2094 delete[] elements[i].name; 2095 elements[i].name = 0; 2096 } 2097 delete[] elements; 2098 count = 0; 2099 elements = 0; 2100 } 2101 } 2102 }; 2103 2104 /** 2105 * @name General 2106 * @{ 2107 */ 2108 2109 /** 2110 * Fetch list of all objects, optionally restricted to given type. 2111 * 2112 * @param list List of objects returned in the dictionary 2113 * @param type Restrict returned list to only contain objects of 2114 * this type 2115 * 2116 * @return -1 if error. 2117 * 2118 */ 2119 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED 2120 int listObjects(List & list, Object::Type type = Object::TypeUndefined); 2121 #endif 2122 int listObjects(List & list, 2123 Object::Type type = Object::TypeUndefined) const; 2124 int listObjects(List & list, 2125 Object::Type type, 2126 bool fullyQualified) const; 2127 2128 /** 2129 * Get the latest error 2130 * 2131 * @return Error object. 2132 */ 2133 const struct NdbError & getNdbError() const; 2134 2135 /** 2136 * Get warning flags. The value is valid only if the operation did 2137 * not return an error and can return warnings. The flags are 2138 * specific to the operation. 2139 */ 2140 int getWarningFlags() const; 2141 2142 /** @} *******************************************************************/ 2143 2144 /** 2145 * @name Retrieving references to Tables and Indexes 2146 * @{ 2147 */ 2148 2149 /** 2150 * Get table with given name, NULL if undefined 2151 * @param name Name of table to get 2152 * @return table if successful otherwise NULL. 2153 */ 2154 const Table * getTable(const char * name) const; 2155 2156 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 2157 /** 2158 * Given main table, get blob table. 2159 */ 2160 const Table * getBlobTable(const Table *, const char * col_name); 2161 const Table * getBlobTable(const Table *, Uint32 col_no); 2162 2163 /* 2164 * Save a table definition in dictionary cache 2165 * @param table Object to put into cache 2166 */ 2167 void putTable(const Table * table); 2168 #endif 2169 2170 /** 2171 * Get index with given name, NULL if undefined 2172 * @param indexName Name of index to get. 2173 * @param tableName Name of table that index belongs to. 2174 * @return index if successful, otherwise 0. 2175 */ 2176 const Index * getIndex(const char * indexName, 2177 const char * tableName) const; 2178 2179 /** 2180 * Fetch list of indexes of given table. 2181 * @param list Reference to list where to store the listed indexes 2182 * @param tableName Name of table that index belongs to. 2183 * @return 0 if successful, otherwise -1 2184 */ 2185 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED 2186 int listIndexes(List & list, const char * tableName); 2187 #endif 2188 int listIndexes(List & list, const char * tableName) const; 2189 2190 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 2191 /** 2192 * Fetch list of indexes of given table. 2193 * @param list Reference to list where to store the listed indexes 2194 * @param table Reference to table that index belongs to. 2195 * @return 0 if successful, otherwise -1 2196 */ 2197 int listIndexes(List & list, const Table &table) const; 2198 #endif 2199 2200 /** @} *******************************************************************/ 2201 /** 2202 * @name Events 2203 * @{ 2204 */ 2205 2206 /** 2207 * Create event given defined Event instance 2208 * @param event Event to create 2209 * @return 0 if successful otherwise -1. 2210 */ 2211 int createEvent(const Event &event); 2212 2213 /** 2214 * Drop event with given name 2215 * @param eventName Name of event to drop. 2216 * @return 0 if successful otherwise -1. 2217 */ 2218 int dropEvent(const char * eventName, int force= 0); 2219 2220 /** 2221 * Get event with given name. 2222 * @param eventName Name of event to get. 2223 * @return an Event if successful, otherwise NULL. 2224 */ 2225 const Event * getEvent(const char * eventName); 2226 2227 /** 2228 * List defined events 2229 * @param list List of events returned in the dictionary 2230 * @return 0 if successful otherwise -1. 2231 */ 2232 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED 2233 int listEvents(List & list); 2234 #endif 2235 int listEvents(List & list) const; 2236 2237 /** @} *******************************************************************/ 2238 2239 /** 2240 * @name Table creation 2241 * @{ 2242 * 2243 * These methods should normally not be used in an application as 2244 * the result will not be visible from the MySQL Server 2245 */ 2246 2247 /** 2248 * Create defined table given defined Table instance 2249 * @param table Table to create 2250 * @return 0 if successful otherwise -1. 2251 */ 2252 int createTable(const Table &table); 2253 2254 /** 2255 * Create defined table given defined Table instance 2256 * return ObjectId 2257 * @param table Table to create 2258 * @return 0 if successful otherwise -1. 2259 */ 2260 int createTable(const Table &table, ObjectId * objid); 2261 2262 /** 2263 * Start table optimization given defined table object 2264 * @param t Object of table to optimize 2265 * @param Pre-allocated OptimizeTableHandle 2266 * @return 0 if successful otherwise -1. 2267 */ 2268 int 2269 optimizeTable(const Table &t, OptimizeTableHandle &h); 2270 2271 /** 2272 * Start index optimization given defined index object 2273 * @param ind Object of index to optimize 2274 * @param Pre-allocated OptimizeIndexHandle 2275 * @return 0 if successful otherwise -1. 2276 */ 2277 int 2278 optimizeIndex(const Index &ind, OptimizeIndexHandle &h); 2279 2280 /** 2281 * Drop table given retrieved Table instance 2282 * @param table Table to drop 2283 * @return 0 if successful otherwise -1. 2284 */ 2285 int dropTable(Table & table); 2286 2287 /** 2288 * Drop table given table name 2289 * @param name Name of table to drop 2290 * @return 0 if successful otherwise -1. 2291 */ 2292 int dropTable(const char * name); 2293 2294 /** 2295 * Check if alter of table given defined 2296 * Table instance to new definition is supported 2297 * @param f Table to alter 2298 * @param t New definition of table 2299 * @return TRUE supported <br> 2300 * FALSE not supported <br> 2301 */ 2302 bool supportedAlterTable(const Table & f, const Table & t); 2303 2304 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 2305 /** 2306 * Alter defined table given defined Table instance 2307 * @param f Table to alter 2308 * @param t New definition of table 2309 * @return -2 (incompatible version) <br> 2310 * -1 general error <br> 2311 * 0 success 2312 */ 2313 int alterTable(const Table & f, const Table & t); 2314 2315 /** 2316 * Invalidate cached table object 2317 * @param name Name of table to invalidate 2318 */ 2319 void invalidateTable(const char * name); 2320 #endif 2321 2322 /** 2323 * Remove table from local cache 2324 */ 2325 void removeCachedTable(const char * table); 2326 /** 2327 * Remove index from local cache 2328 */ 2329 void removeCachedIndex(const char * index, const char * table); 2330 2331 2332 /** @} *******************************************************************/ 2333 /** 2334 * @name Index creation 2335 * @{ 2336 * 2337 * These methods should normally not be used in an application as 2338 * the result will not be visible from the MySQL Server 2339 * 2340 */ 2341 2342 /** 2343 * Create index given defined Index instance 2344 * @param index Index to create 2345 * @return 0 if successful otherwise -1. 2346 */ 2347 int createIndex(const Index &index, bool offline = false); 2348 int createIndex(const Index &index, const Table &table, bool offline = false); 2349 2350 /** 2351 * Drop index with given name 2352 * @param indexName Name of index to drop. 2353 * @param tableName Name of table that index belongs to. 2354 * @return 0 if successful otherwise -1. 2355 */ 2356 int dropIndex(const char * indexName, 2357 const char * tableName); 2358 2359 /* 2360 * Force update of ordered index stats. Scans an assigned fragment 2361 * in the kernel and updates result in stats tables. This one-time 2362 * update is independent of IndexStatAuto settings. Common use case 2363 * is mysql "analyze table". 2364 */ 2365 int updateIndexStat(const Index&, const Table&); 2366 2367 /* 2368 * Force update of ordered index stats where index is given by id. 2369 */ 2370 int updateIndexStat(Uint32 indexId, Uint32 indexVersion, Uint32 tableId); 2371 2372 /* 2373 * Delete ordered index stats. If IndexStatAutoUpdate is set, also 2374 * stops automatic updates, until another forced update is done. 2375 */ 2376 int deleteIndexStat(const Index&, const Table&); 2377 2378 /* 2379 * Delete ordered index stats where index is given by id. 2380 */ 2381 int deleteIndexStat(Uint32 indexId, Uint32 indexVersion, Uint32 tableId); 2382 2383 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 2384 void removeCachedTable(const Table *table); 2385 void removeCachedIndex(const Index *index); 2386 void invalidateTable(const Table *table); 2387 /** 2388 * Invalidate cached index object 2389 */ 2390 void invalidateIndex(const char * indexName, 2391 const char * tableName); 2392 void invalidateIndex(const Index *index); 2393 /** 2394 * Force gcp and wait for gcp complete 2395 */ 2396 int forceGCPWait(); 2397 int forceGCPWait(int type); 2398 2399 /** 2400 * Get restart gci 2401 */ 2402 int getRestartGCI(Uint32 * gci); 2403 #endif 2404 2405 /** @} *******************************************************************/ 2406 2407 /** @} *******************************************************************/ 2408 /** 2409 * @name Disk data objects 2410 * @{ 2411 */ 2412 2413 /* 2414 * The four "create" operations can return warning flags defined 2415 * below. See getWarningFlags(). 2416 */ 2417 enum { 2418 WarnUndobufferRoundUp = 0x1, // rounded up to kernel page size 2419 WarnUndofileRoundDown = 0x2, // rounded down to kernel page size 2420 WarnExtentRoundUp = 0x4, // rounded up to kernel page size 2421 WarnDatafileRoundDown = 0x8, // rounded down to kernel page size 2422 WarnDatafileRoundUp = 0x10 // rounded up to extent size 2423 }; 2424 2425 int createLogfileGroup(const LogfileGroup &, ObjectId* = 0); 2426 int dropLogfileGroup(const LogfileGroup&); 2427 LogfileGroup getLogfileGroup(const char * name); 2428 2429 int createTablespace(const Tablespace &, ObjectId* = 0); 2430 int dropTablespace(const Tablespace&); 2431 Tablespace getTablespace(const char * name); 2432 Tablespace getTablespace(Uint32 tablespaceId); 2433 2434 int createDatafile(const Datafile &, bool overwrite_existing = false, ObjectId* = 0); 2435 int dropDatafile(const Datafile&); 2436 Datafile getDatafile(Uint32 node, const char * path); 2437 2438 int createUndofile(const Undofile &, bool overwrite_existing = false, ObjectId * = 0); 2439 int dropUndofile(const Undofile&); 2440 Undofile getUndofile(Uint32 node, const char * path); 2441 2442 2443 /** @} *******************************************************************/ 2444 /** 2445 * @name HashMap 2446 * @{ 2447 */ 2448 2449 /** 2450 * Create a HashMap in database 2451 */ 2452 int createHashMap(const HashMap&, ObjectId* = 0); 2453 2454 /** 2455 * Get a HashMap by name 2456 */ 2457 int getHashMap(HashMap& dst, const char* name); 2458 2459 /** 2460 * Get a HashMap for a table 2461 */ 2462 int getHashMap(HashMap& dst, const Table* table); 2463 2464 /** 2465 * Get default HashMap 2466 */ 2467 int getDefaultHashMap(HashMap& dst, Uint32 fragments); 2468 2469 2470 /** 2471 * Init a default HashMap 2472 */ 2473 int initDefaultHashMap(HashMap& dst, Uint32 fragments); 2474 2475 /** 2476 * create (or retreive) a HashMap suitable for alter 2477 * NOTE: Requires a started schema transaction 2478 */ 2479 int prepareHashMap(const Table& oldTable, Table& newTable); 2480 2481 /** @} *******************************************************************/ 2482 2483 /** 2484 * @name Schema transactions 2485 * 2486 * Metadata operations are create, alter, and drop of objects of 2487 * various types. An operation may create additional sub-operations 2488 * in the kernel. 2489 * 2490 * By default, each user operation is executed separately. That is, 2491 * a schema transaction is started implicitly, the operation and its 2492 * suboperations are executed, and the transaction is closed. 2493 * 2494 * The Ndb object and its associated Dictionary support one schema 2495 * transaction at a time. 2496 * 2497 * Using begin and end transaction explicitly it is possible to 2498 * execute a set of user defined operations atomically i.e. either 2499 * all operations succeed or all are aborted (rolled back). 2500 * 2501 * The steps are 1) beginSchemaTrans 2) submit operations such as 2502 * createTable 3) endSchemaTrans. 2503 * 2504 * Each operation is sent to the kernel which parses and saves it. 2505 * Parse failure does rollback to previous user operation before 2506 * returning. The user can continue or abort entire transaction. 2507 * 2508 * After all operations have been submitted, endSchemaTrans with 2509 * flags 0 (the default) processes and commits them. On error 2510 * return the transaction is already aborted. 2511 * 2512 * If the user exits before calling endSchemaTrans, the kernel 2513 * aborts the transaction. If the user exits before the call to 2514 * endSchemaTrans returns, the kernel continues with the request. 2515 * Completion status is reported in cluster log. 2516 */ 2517 2518 //@{ 2519 /** 2520 * Begin schema transaction. Returns error if a transaction is 2521 * already active or if the kernel metadata is locked. 2522 * 2523 * @return 0 on success, -1 on error 2524 */ 2525 int beginSchemaTrans(); 2526 2527 /** 2528 * End schema transaction, with commit or with abort. Combines 2529 * execute and close which do not exist separately. May be called 2530 * and succeeds even if no transaction is active. 2531 * 2532 * @note Like any method, may overwrite current error code. 2533 * First save error code from any failed operation. 2534 * 2535 * @param flags 2536 * Bitmask of options. 2537 * Default 0 commits the transaction. 2538 * Including option 1 aborts the transaction. 2539 * See SchemaTransFlag for others. 2540 * @return 0 on success, -1 on error 2541 */ 2542 int endSchemaTrans(Uint32 flags = 0); 2543 2544 /** 2545 * Flags for endSchemaTrans, or-ed together. 2546 */ 2547 enum SchemaTransFlag { 2548 // abort transaction 2549 SchemaTransAbort = 1, 2550 // do not wait for reply, status is reported in cluster log 2551 SchemaTransBackground = 2 2552 }; 2553 2554 /** 2555 * Check if a schema transaction exists currently. 2556 */ 2557 bool hasSchemaTrans() const; 2558 //@} 2559 2560 protected: 2561 Dictionary(Ndb & ndb); 2562 ~Dictionary(); 2563 2564 private: 2565 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 2566 friend class NdbDictionaryImpl; 2567 friend class UtilTransactions; 2568 friend class NdbBlob; 2569 #endif 2570 class NdbDictionaryImpl & m_impl; 2571 Dictionary(NdbDictionaryImpl&); 2572 const Table * getIndexTable(const char * indexName, 2573 const char * tableName) const; 2574 public: 2575 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL 2576 const Table * getTable(const char * name, void **data) const; 2577 void set_local_table_data_size(unsigned sz); 2578 2579 const Index * getIndexGlobal(const char * indexName, 2580 const Table &ndbtab) const; 2581 const Index * getIndexGlobal(const char * indexName, 2582 const char * tableName) const; 2583 const Table * getTableGlobal(const char * tableName) const; 2584 int alterTableGlobal(const Table &f, const Table &t); 2585 int dropTableGlobal(const Table &ndbtab); 2586 int dropIndexGlobal(const Index &index); 2587 int removeIndexGlobal(const Index &ndbidx, int invalidate) const; 2588 int removeTableGlobal(const Table &ndbtab, int invalidate) const; 2589 void invalidateDbGlobal(const char * dbname); 2590 #endif 2591 2592 /* 2593 Create an NdbRecord for use in table operations. 2594 */ 2595 NdbRecord *createRecord(const Table *table, 2596 const RecordSpecification *recSpec, 2597 Uint32 length, 2598 Uint32 elemSize, 2599 Uint32 flags= 0); 2600 2601 /* 2602 Create an NdbRecord for use in index operations. 2603 */ 2604 NdbRecord *createRecord(const Index *index, 2605 const Table *table, 2606 const RecordSpecification *recSpec, 2607 Uint32 length, 2608 Uint32 elemSize, 2609 Uint32 flags= 0); 2610 /* 2611 Create an NdbRecord for use in index operations. 2612 This variant assumes that the index is for a table in 2613 the current database and schema 2614 */ 2615 NdbRecord *createRecord(const Index *index, 2616 const RecordSpecification *recSpec, 2617 Uint32 length, 2618 Uint32 elemSize, 2619 Uint32 flags= 0); 2620 2621 /* 2622 Free an NdbRecord object created earlier with 2623 createRecord 2624 */ 2625 void releaseRecord(NdbRecord *rec); 2626 }; // class Dictionary 2627 2628 class NdbDataPrintFormat 2629 { 2630 public: 2631 NdbDataPrintFormat(); 2632 virtual ~NdbDataPrintFormat(); 2633 const char *lines_terminated_by; 2634 const char *fields_terminated_by; 2635 const char *start_array_enclosure; 2636 const char *end_array_enclosure; 2637 const char *fields_enclosed_by; 2638 const char *fields_optionally_enclosed_by; 2639 const char *hex_prefix; 2640 const char *null_string; 2641 int hex_format; 2642 }; 2643 2644 static 2645 class NdbOut& printFormattedValue(class NdbOut& out, 2646 const NdbDataPrintFormat& format, 2647 const NdbDictionary::Column* c, 2648 const void* val); 2649 2650 2651 }; // class NdbDictionary 2652 2653 class NdbOut& operator <<(class NdbOut& out, const NdbDictionary::Column& col); 2654 2655 #endif 2656