Commit 54963c2e authored by pekka@mysql.com's avatar pekka@mysql.com

ndb - bug#14509 [related] re-do auto-incr error handling

parent fc732046
...@@ -1432,23 +1432,28 @@ public: ...@@ -1432,23 +1432,28 @@ public:
* *
* @param cacheSize number of values to cache in this Ndb object * @param cacheSize number of values to cache in this Ndb object
* *
* @return tuple id or ~(Uint64)0 on error. * @return 0 or -1 on error, and tupleId in out parameter
*/ */
Uint64 getAutoIncrementValue(const char* aTableName, int getAutoIncrementValue(const char* aTableName,
Uint32 cacheSize = 1); Uint64 & tupleId, Uint32 cacheSize);
Uint64 getAutoIncrementValue(const NdbDictionary::Table * aTable, int getAutoIncrementValue(const NdbDictionary::Table * aTable,
Uint32 cacheSize = 1); Uint64 & tupleId, Uint32 cacheSize);
Uint64 readAutoIncrementValue(const char* aTableName); int readAutoIncrementValue(const char* aTableName,
Uint64 readAutoIncrementValue(const NdbDictionary::Table * aTable); Uint64 & tupleId);
Uint64 setAutoIncrementValue(const char* aTableName, Uint64 val, int readAutoIncrementValue(const NdbDictionary::Table * aTable,
bool increase = false); Uint64 & tupleId);
Uint64 setAutoIncrementValue(const NdbDictionary::Table * aTable, Uint64 val, int setAutoIncrementValue(const char* aTableName,
bool increase = false); Uint64 tupleId, bool increase);
int setAutoIncrementValue(const NdbDictionary::Table * aTable,
Uint64 tupleId, bool increase);
private: private:
Uint64 getTupleIdFromNdb(Ndb_local_table_info* info, Uint32 cacheSize); int getTupleIdFromNdb(Ndb_local_table_info* info,
Uint64 readTupleIdFromNdb(Ndb_local_table_info* info); Uint64 & tupleId, Uint32 cacheSize);
Uint64 setTupleIdInNdb(Ndb_local_table_info* info, Uint64 val, bool increase); int readTupleIdFromNdb(Ndb_local_table_info* info,
Uint64 opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op); Uint64 & tupleId);
int setTupleIdInNdb(Ndb_local_table_info* info,
Uint64 tupleId, bool increase);
int opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 & opValue, Uint32 op);
public: public:
/** /**
......
This diff is collapsed.
...@@ -1743,7 +1743,7 @@ NdbDictInterface::createOrAlterTable(Ndb & ndb, ...@@ -1743,7 +1743,7 @@ NdbDictInterface::createOrAlterTable(Ndb & ndb,
if (haveAutoIncrement) { if (haveAutoIncrement) {
if (ndb.setAutoIncrementValue(impl.m_externalName.c_str(), if (ndb.setAutoIncrementValue(impl.m_externalName.c_str(),
autoIncrementValue) == ~(Uint64)0) { autoIncrementValue, false) == -1) {
DBUG_ASSERT(ndb.theError.code != 0); DBUG_ASSERT(ndb.theError.code != 0);
m_error= ndb.theError; m_error= ndb.theError;
ret = -1; ret = -1;
......
...@@ -1139,9 +1139,13 @@ runCreateAutoincrementTable(NDBT_Context* ctx, NDBT_Step* step){ ...@@ -1139,9 +1139,13 @@ runCreateAutoincrementTable(NDBT_Context* ctx, NDBT_Step* step){
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
Uint64 value = myNdb->getAutoIncrementValue(tabname, 1); Uint64 value;
if (myNdb->getAutoIncrementValue(tabname, value, 1) == -1) {
if (value != (startvalue+i)) { g_err << "getAutoIncrementValue failed on " << tabname << endl;
APIERROR(myNdb->getNdbError());
return NDBT_FAILED;
}
else if (value != (startvalue+i)) {
g_err << "value = " << value << " expected " << startvalue+i << endl;; g_err << "value = " << value << " expected " << startvalue+i << endl;;
APIERROR(myNdb->getNdbError()); APIERROR(myNdb->getNdbError());
// ret = NDBT_FAILED; // ret = NDBT_FAILED;
......
...@@ -148,9 +148,12 @@ BackupRestore::finalize_table(const TableS & table){ ...@@ -148,9 +148,12 @@ BackupRestore::finalize_table(const TableS & table){
if (table.have_auto_inc()) if (table.have_auto_inc())
{ {
Uint64 max_val= table.get_max_auto_val(); Uint64 max_val= table.get_max_auto_val();
Uint64 auto_val= m_ndb->readAutoIncrementValue(get_table(table.m_dictTable)); Uint64 auto_val;
if (max_val+1 > auto_val || auto_val == ~(Uint64)0) int r= m_ndb->readAutoIncrementValue(get_table(table.m_dictTable), auto_val);
ret= m_ndb->setAutoIncrementValue(get_table(table.m_dictTable), max_val+1, false) != ~(Uint64)0; if (r == -1 && m_ndb->getNdbError().code != 626)
ret= false;
else if (r == -1 || max_val+1 > auto_val)
ret= m_ndb->setAutoIncrementValue(get_table(table.m_dictTable), max_val+1, false) != -1;
} }
return ret; return ret;
} }
......
...@@ -73,7 +73,6 @@ handlerton ndbcluster_hton = { ...@@ -73,7 +73,6 @@ handlerton ndbcluster_hton = {
HTON_NO_FLAGS HTON_NO_FLAGS
}; };
#define NDB_FAILED_AUTO_INCREMENT ~(Uint64)0
#define NDB_AUTO_INCREMENT_RETRIES 10 #define NDB_AUTO_INCREMENT_RETRIES 10
#define NDB_INVALID_SCHEMA_OBJECT 241 #define NDB_INVALID_SCHEMA_OBJECT 241
...@@ -2112,14 +2111,15 @@ int ha_ndbcluster::write_row(byte *record) ...@@ -2112,14 +2111,15 @@ int ha_ndbcluster::write_row(byte *record)
{ {
// Table has hidden primary key // Table has hidden primary key
Ndb *ndb= get_ndb(); Ndb *ndb= get_ndb();
Uint64 auto_value= NDB_FAILED_AUTO_INCREMENT; int ret;
Uint64 auto_value;
uint retries= NDB_AUTO_INCREMENT_RETRIES; uint retries= NDB_AUTO_INCREMENT_RETRIES;
do { do {
auto_value= ndb->getAutoIncrementValue((const NDBTAB *) m_table); ret= ndb->getAutoIncrementValue((const NDBTAB *) m_table, auto_value, 1);
} while (auto_value == NDB_FAILED_AUTO_INCREMENT && } while (ret == -1 &&
--retries && --retries &&
ndb->getNdbError().status == NdbError::TemporaryError); ndb->getNdbError().status == NdbError::TemporaryError);
if (auto_value == NDB_FAILED_AUTO_INCREMENT) if (ret == -1)
ERR_RETURN(ndb->getNdbError()); ERR_RETURN(ndb->getNdbError());
if (set_hidden_key(op, table->s->fields, (const byte*)&auto_value)) if (set_hidden_key(op, table->s->fields, (const byte*)&auto_value))
ERR_RETURN(op->getNdbError()); ERR_RETURN(op->getNdbError());
...@@ -2200,7 +2200,7 @@ int ha_ndbcluster::write_row(byte *record) ...@@ -2200,7 +2200,7 @@ int ha_ndbcluster::write_row(byte *record)
("Trying to set next auto increment value to %llu", ("Trying to set next auto increment value to %llu",
(ulonglong) next_val)); (ulonglong) next_val));
if (ndb->setAutoIncrementValue((const NDBTAB *) m_table, next_val, TRUE) if (ndb->setAutoIncrementValue((const NDBTAB *) m_table, next_val, TRUE)
== ~(Uint64)0) == -1)
ERR_RETURN(ndb->getNdbError()); ERR_RETURN(ndb->getNdbError());
} }
m_skip_auto_increment= TRUE; m_skip_auto_increment= TRUE;
...@@ -3047,8 +3047,14 @@ void ha_ndbcluster::info(uint flag) ...@@ -3047,8 +3047,14 @@ void ha_ndbcluster::info(uint flag)
{ {
Ndb *ndb= get_ndb(); Ndb *ndb= get_ndb();
auto_increment_value= if (ndb->readAutoIncrementValue((const NDBTAB *) m_table,
ndb->readAutoIncrementValue((const NDBTAB *) m_table); auto_increment_value) == -1)
{
const NdbError err= ndb->getNdbError();
sql_print_error("Error %lu in readAutoIncrementValue(): %s",
(ulong) err.code, err.message);
auto_increment_value= ~(Uint64)0;
}
} }
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
...@@ -4360,17 +4366,17 @@ ulonglong ha_ndbcluster::get_auto_increment() ...@@ -4360,17 +4366,17 @@ ulonglong ha_ndbcluster::get_auto_increment()
m_rows_to_insert - m_rows_inserted : m_rows_to_insert - m_rows_inserted :
((m_rows_to_insert > m_autoincrement_prefetch) ? ((m_rows_to_insert > m_autoincrement_prefetch) ?
m_rows_to_insert : m_autoincrement_prefetch)); m_rows_to_insert : m_autoincrement_prefetch));
auto_value= NDB_FAILED_AUTO_INCREMENT; int ret;
uint retries= NDB_AUTO_INCREMENT_RETRIES; uint retries= NDB_AUTO_INCREMENT_RETRIES;
do { do {
auto_value= ret=
(m_skip_auto_increment) ? m_skip_auto_increment ?
ndb->readAutoIncrementValue((const NDBTAB *) m_table) ndb->readAutoIncrementValue((const NDBTAB *) m_table, auto_value) :
: ndb->getAutoIncrementValue((const NDBTAB *) m_table, cache_size); ndb->getAutoIncrementValue((const NDBTAB *) m_table, auto_value, cache_size);
} while (auto_value == NDB_FAILED_AUTO_INCREMENT && } while (ret == -1 &&
--retries && --retries &&
ndb->getNdbError().status == NdbError::TemporaryError); ndb->getNdbError().status == NdbError::TemporaryError);
if (auto_value == NDB_FAILED_AUTO_INCREMENT) if (ret == -1)
{ {
const NdbError err= ndb->getNdbError(); const NdbError err= ndb->getNdbError();
sql_print_error("Error %lu in ::get_auto_increment(): %s", sql_print_error("Error %lu in ::get_auto_increment(): %s",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment