Commit dd58dd51 authored by pekka@mysql.com's avatar pekka@mysql.com

ndb - bug#14509 [related] setAutoIncrement: add error handling

parent e554f9b3
...@@ -1432,7 +1432,7 @@ public: ...@@ -1432,7 +1432,7 @@ 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 0 on error * @return tuple id or ~(Uint64)0 on error.
*/ */
Uint64 getAutoIncrementValue(const char* aTableName, Uint64 getAutoIncrementValue(const char* aTableName,
Uint32 cacheSize = 1); Uint32 cacheSize = 1);
...@@ -1440,14 +1440,14 @@ public: ...@@ -1440,14 +1440,14 @@ public:
Uint32 cacheSize = 1); Uint32 cacheSize = 1);
Uint64 readAutoIncrementValue(const char* aTableName); Uint64 readAutoIncrementValue(const char* aTableName);
Uint64 readAutoIncrementValue(const NdbDictionary::Table * aTable); Uint64 readAutoIncrementValue(const NdbDictionary::Table * aTable);
bool setAutoIncrementValue(const char* aTableName, Uint64 val, Uint64 setAutoIncrementValue(const char* aTableName, Uint64 val,
bool increase = false); bool increase = false);
bool setAutoIncrementValue(const NdbDictionary::Table * aTable, Uint64 val, Uint64 setAutoIncrementValue(const NdbDictionary::Table * aTable, Uint64 val,
bool increase = false); bool increase = false);
private: private:
Uint64 getTupleIdFromNdb(Ndb_local_table_info* info, Uint32 cacheSize); Uint64 getTupleIdFromNdb(Ndb_local_table_info* info, Uint32 cacheSize);
Uint64 readTupleIdFromNdb(Ndb_local_table_info* info); Uint64 readTupleIdFromNdb(Ndb_local_table_info* info);
bool setTupleIdInNdb(Ndb_local_table_info* info, Uint64 val, bool increase); Uint64 setTupleIdInNdb(Ndb_local_table_info* info, Uint64 val, bool increase);
Uint64 opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op); Uint64 opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op);
public: public:
......
...@@ -781,8 +781,7 @@ Uint64 ...@@ -781,8 +781,7 @@ Uint64
Ndb::getAutoIncrementValue(const NdbDictionary::Table * aTable, Uint32 cacheSize) Ndb::getAutoIncrementValue(const NdbDictionary::Table * aTable, Uint32 cacheSize)
{ {
DBUG_ENTER("getAutoIncrementValue"); DBUG_ENTER("getAutoIncrementValue");
if (aTable == 0) assert(aTable != 0);
DBUG_RETURN(~(Uint64)0);
const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable); const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable);
const BaseString& internal_tabname = table->m_internalName; const BaseString& internal_tabname = table->m_internalName;
...@@ -843,8 +842,7 @@ Uint64 ...@@ -843,8 +842,7 @@ Uint64
Ndb::readAutoIncrementValue(const NdbDictionary::Table * aTable) Ndb::readAutoIncrementValue(const NdbDictionary::Table * aTable)
{ {
DBUG_ENTER("readAutoIncrementValue"); DBUG_ENTER("readAutoIncrementValue");
if (aTable == 0) assert(aTable != 0);
DBUG_RETURN(~(Uint64)0);
const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable); const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable);
const BaseString& internal_tabname = table->m_internalName; const BaseString& internal_tabname = table->m_internalName;
...@@ -880,7 +878,7 @@ Ndb::readTupleIdFromNdb(Ndb_local_table_info* info) ...@@ -880,7 +878,7 @@ Ndb::readTupleIdFromNdb(Ndb_local_table_info* info)
DBUG_RETURN(tupleId); DBUG_RETURN(tupleId);
} }
bool Uint64
Ndb::setAutoIncrementValue(const char* aTableName, Uint64 val, bool increase) Ndb::setAutoIncrementValue(const char* aTableName, Uint64 val, bool increase)
{ {
DBUG_ENTER("setAutoIncrementValue"); DBUG_ENTER("setAutoIncrementValue");
...@@ -890,17 +888,16 @@ Ndb::setAutoIncrementValue(const char* aTableName, Uint64 val, bool increase) ...@@ -890,17 +888,16 @@ Ndb::setAutoIncrementValue(const char* aTableName, Uint64 val, bool increase)
theDictionary->get_local_table_info(internal_tabname, false); theDictionary->get_local_table_info(internal_tabname, false);
if (info == 0) { if (info == 0) {
theError.code = theDictionary->getNdbError().code; theError.code = theDictionary->getNdbError().code;
DBUG_RETURN(false); DBUG_RETURN(~(Uint64)0);
} }
DBUG_RETURN(setTupleIdInNdb(info, val, increase)); DBUG_RETURN(setTupleIdInNdb(info, val, increase));
} }
bool Uint64
Ndb::setAutoIncrementValue(const NdbDictionary::Table * aTable, Uint64 val, bool increase) Ndb::setAutoIncrementValue(const NdbDictionary::Table * aTable, Uint64 val, bool increase)
{ {
DBUG_ENTER("setAutoIncrementValue"); DBUG_ENTER("setAutoIncrementValue");
if (aTable == 0) assert(aTable != 0);
DBUG_RETURN(false);
const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable); const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable);
const BaseString& internal_tabname = table->m_internalName; const BaseString& internal_tabname = table->m_internalName;
...@@ -908,12 +905,12 @@ Ndb::setAutoIncrementValue(const NdbDictionary::Table * aTable, Uint64 val, bool ...@@ -908,12 +905,12 @@ Ndb::setAutoIncrementValue(const NdbDictionary::Table * aTable, Uint64 val, bool
theDictionary->get_local_table_info(internal_tabname, false); theDictionary->get_local_table_info(internal_tabname, false);
if (info == 0) { if (info == 0) {
theError.code = theDictionary->getNdbError().code; theError.code = theDictionary->getNdbError().code;
DBUG_RETURN(false); DBUG_RETURN(~(Uint64)0);
} }
DBUG_RETURN(setTupleIdInNdb(info, val, increase)); DBUG_RETURN(setTupleIdInNdb(info, val, increase));
} }
bool Uint64
Ndb::setTupleIdInNdb(Ndb_local_table_info* info, Uint64 val, bool increase) Ndb::setTupleIdInNdb(Ndb_local_table_info* info, Uint64 val, bool increase)
{ {
DBUG_ENTER("setTupleIdInNdb"); DBUG_ENTER("setTupleIdInNdb");
...@@ -923,11 +920,14 @@ Ndb::setTupleIdInNdb(Ndb_local_table_info* info, Uint64 val, bool increase) ...@@ -923,11 +920,14 @@ Ndb::setTupleIdInNdb(Ndb_local_table_info* info, Uint64 val, bool increase)
{ {
assert(info->m_first_tuple_id < info->m_last_tuple_id); assert(info->m_first_tuple_id < info->m_last_tuple_id);
if (val <= info->m_first_tuple_id + 1) if (val <= info->m_first_tuple_id + 1)
DBUG_RETURN(false); DBUG_RETURN(val);
if (val <= info->m_last_tuple_id) if (val <= info->m_last_tuple_id)
{ {
info->m_first_tuple_id = val - 1; info->m_first_tuple_id = val - 1;
DBUG_RETURN(true); DBUG_PRINT("info",
("Setting next auto increment cached value to %llu",
(ulonglong)val));
DBUG_RETURN(val);
} }
} }
/* /*
...@@ -954,8 +954,7 @@ Ndb::opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op) ...@@ -954,8 +954,7 @@ Ndb::opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op)
NdbOperation* tOperation= 0; // Compiler warning if not initialized NdbOperation* tOperation= 0; // Compiler warning if not initialized
Uint64 tValue; Uint64 tValue;
NdbRecAttr* tRecAttrResult; NdbRecAttr* tRecAttrResult;
int result; Uint64 ret = ~(Uint64)0;
Uint64 ret;
CHECK_STATUS_MACRO_ZERO; CHECK_STATUS_MACRO_ZERO;
...@@ -1017,17 +1016,17 @@ Ndb::opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op) ...@@ -1017,17 +1016,17 @@ Ndb::opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op)
tOperation->def_label(0); tOperation->def_label(0);
tOperation->interpret_exit_nok(9999); tOperation->interpret_exit_nok(9999);
if ( (result = tConnection->execute( Commit )) == -1 ) if (tConnection->execute( Commit ) == -1)
{ {
if (tConnection->theError.code != 9999) if (tConnection->theError.code != 9999)
goto error_handler; goto error_handler;
ret = opValue;
// NEXTID >= opValue, return ~(Uint64)0 for now since
// there is no error check...
ret = ~(Uint64)0;
} }
else else
{ {
DBUG_PRINT("info",
("Setting next auto increment value (db) to %llu",
(ulonglong)opValue));
info->m_first_tuple_id = info->m_last_tuple_id = opValue - 1; info->m_first_tuple_id = info->m_last_tuple_id = opValue - 1;
ret = opValue; ret = opValue;
} }
......
...@@ -1742,14 +1742,11 @@ NdbDictInterface::createOrAlterTable(Ndb & ndb, ...@@ -1742,14 +1742,11 @@ NdbDictInterface::createOrAlterTable(Ndb & ndb,
DBUG_RETURN(ret); DBUG_RETURN(ret);
if (haveAutoIncrement) { if (haveAutoIncrement) {
if (!ndb.setAutoIncrementValue(impl.m_externalName.c_str(), if (ndb.setAutoIncrementValue(impl.m_externalName.c_str(),
autoIncrementValue)) { autoIncrementValue) == ~(Uint64)0) {
if (ndb.theError.code == 0) { DBUG_ASSERT(ndb.theError.code != 0);
m_error.code= 4336;
ndb.theError = m_error;
} else
m_error= ndb.theError; m_error= ndb.theError;
ret = -1; // errorcode set in initialize_autoincrement ret = -1;
} }
} }
} }
......
...@@ -150,7 +150,7 @@ BackupRestore::finalize_table(const TableS & table){ ...@@ -150,7 +150,7 @@ BackupRestore::finalize_table(const TableS & table){
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= m_ndb->readAutoIncrementValue(get_table(table.m_dictTable));
if (max_val+1 > auto_val || auto_val == ~(Uint64)0) if (max_val+1 > auto_val || auto_val == ~(Uint64)0)
ret= m_ndb->setAutoIncrementValue(get_table(table.m_dictTable), max_val+1, false); ret= m_ndb->setAutoIncrementValue(get_table(table.m_dictTable), max_val+1, false) != ~(Uint64)0;
} }
return ret; return ret;
} }
......
...@@ -2197,11 +2197,11 @@ int ha_ndbcluster::write_row(byte *record) ...@@ -2197,11 +2197,11 @@ int ha_ndbcluster::write_row(byte *record)
Ndb *ndb= get_ndb(); Ndb *ndb= get_ndb();
Uint64 next_val= (Uint64) table->next_number_field->val_int() + 1; Uint64 next_val= (Uint64) table->next_number_field->val_int() + 1;
DBUG_PRINT("info", DBUG_PRINT("info",
("Trying to set next auto increment value to %lu", ("Trying to set next auto increment value to %llu",
(ulong) 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)
DBUG_PRINT("info", == ~(Uint64)0)
("Setting next auto increment value to %u", next_val)); ERR_RETURN(ndb->getNdbError());
} }
m_skip_auto_increment= TRUE; m_skip_auto_increment= TRUE;
......
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