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

ndb - bug#14509 (5.0) part 2: create SYSTAB_0 row on first use

parent 5efff1fe
...@@ -1607,10 +1607,9 @@ void Ndbcntr::systemErrorLab(Signal* signal, int line) ...@@ -1607,10 +1607,9 @@ void Ndbcntr::systemErrorLab(Signal* signal, int line)
/* |-2048| # 1 00000001 | */ /* |-2048| # 1 00000001 | */
/* | : | : | */ /* | : | : | */
/* | -1 | # 1 00000001 | */ /* | -1 | # 1 00000001 | */
/* | 0 | 0 | */ /* | 1 | 0 | tupleid sequence now created on first use */
/* | 1 | 0 | */ /* | : | : | v */
/* | : | : | */ /* | 2048| 0 | v */
/* | 2047| 0 | */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void Ndbcntr::createSystableLab(Signal* signal, unsigned index) void Ndbcntr::createSystableLab(Signal* signal, unsigned index)
{ {
...@@ -1819,8 +1818,7 @@ void Ndbcntr::crSystab8Lab(Signal* signal) ...@@ -1819,8 +1818,7 @@ void Ndbcntr::crSystab8Lab(Signal* signal)
jam(); jam();
ckey = 1; ckey = 1;
ctransidPhase = ZFALSE; ctransidPhase = ZFALSE;
crSystab7Lab(signal); // skip 2nd loop - tupleid sequence now created on first use
return;
}//if }//if
signal->theData[0] = ctcConnectionP; signal->theData[0] = ctcConnectionP;
signal->theData[1] = reference(); signal->theData[1] = reference();
......
...@@ -813,6 +813,10 @@ Ndb::getTupleIdFromNdb(Ndb_local_table_info* info, Uint32 cacheSize) ...@@ -813,6 +813,10 @@ Ndb::getTupleIdFromNdb(Ndb_local_table_info* info, Uint32 cacheSize)
if (cacheSize == 0) if (cacheSize == 0)
cacheSize = 1; cacheSize = 1;
DBUG_PRINT("info", ("reading %u values from database", (uint)cacheSize)); DBUG_PRINT("info", ("reading %u values from database", (uint)cacheSize));
/*
* reserve next cacheSize entries in db. adds cacheSize to NEXTID
* and returns first tupleId in the new range.
*/
tupleId = opTupleIdOnNdb(info, cacheSize, 0); tupleId = opTupleIdOnNdb(info, cacheSize, 0);
} }
DBUG_RETURN(tupleId); DBUG_RETURN(tupleId);
...@@ -865,8 +869,12 @@ Ndb::readTupleIdFromNdb(Ndb_local_table_info* info) ...@@ -865,8 +869,12 @@ Ndb::readTupleIdFromNdb(Ndb_local_table_info* info)
assert(info->m_first_tuple_id < info->m_last_tuple_id); assert(info->m_first_tuple_id < info->m_last_tuple_id);
tupleId = info->m_first_tuple_id + 1; tupleId = info->m_first_tuple_id + 1;
} }
else // Cache is empty, check next in database else
{ {
/*
* peek at NEXTID. does not reserve it so the value is valid
* only if no other transactions are allowed.
*/
tupleId = opTupleIdOnNdb(info, 0, 3); tupleId = opTupleIdOnNdb(info, 0, 3);
} }
DBUG_RETURN(tupleId); DBUG_RETURN(tupleId);
...@@ -913,7 +921,6 @@ Ndb::setTupleIdInNdb(Ndb_local_table_info* info, Uint64 val, bool increase) ...@@ -913,7 +921,6 @@ Ndb::setTupleIdInNdb(Ndb_local_table_info* info, Uint64 val, bool increase)
{ {
if (info->m_first_tuple_id != info->m_last_tuple_id) if (info->m_first_tuple_id != info->m_last_tuple_id)
{ {
// We have a cache sequence
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(false);
...@@ -922,11 +929,17 @@ Ndb::setTupleIdInNdb(Ndb_local_table_info* info, Uint64 val, bool increase) ...@@ -922,11 +929,17 @@ Ndb::setTupleIdInNdb(Ndb_local_table_info* info, Uint64 val, bool increase)
info->m_first_tuple_id = val - 1; info->m_first_tuple_id = val - 1;
DBUG_RETURN(true); DBUG_RETURN(true);
} }
// else continue;
} }
/*
* if value <= NEXTID, do nothing. otherwise update NEXTID to
* value and set cached range to first = last = value - 1.
*/
DBUG_RETURN((opTupleIdOnNdb(info, val, 2) == val)); DBUG_RETURN((opTupleIdOnNdb(info, val, 2) == val));
} }
else else
/*
* update NEXTID to given value. reset cached range.
*/
DBUG_RETURN((opTupleIdOnNdb(info, val, 1) == val)); DBUG_RETURN((opTupleIdOnNdb(info, val, 1) == val));
} }
...@@ -980,7 +993,8 @@ Ndb::opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op) ...@@ -980,7 +993,8 @@ Ndb::opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op)
ret = info->m_first_tuple_id; ret = info->m_first_tuple_id;
break; break;
case 1: case 1:
tOperation->updateTuple(); // create on first use
tOperation->writeTuple();
tOperation->equal("SYSKEY_0", aTableId ); tOperation->equal("SYSKEY_0", aTableId );
tOperation->setValue("NEXTID", opValue); tOperation->setValue("NEXTID", opValue);
...@@ -996,6 +1010,7 @@ Ndb::opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op) ...@@ -996,6 +1010,7 @@ Ndb::opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op)
tOperation->equal("SYSKEY_0", aTableId ); tOperation->equal("SYSKEY_0", aTableId );
tOperation->load_const_u64(1, opValue); tOperation->load_const_u64(1, opValue);
tOperation->read_attr("NEXTID", 2); tOperation->read_attr("NEXTID", 2);
// compare NEXTID >= opValue
tOperation->branch_le(2, 1, 0); tOperation->branch_le(2, 1, 0);
tOperation->write_attr("NEXTID", 1); tOperation->write_attr("NEXTID", 1);
tOperation->interpret_exit_ok(); tOperation->interpret_exit_ok();
...@@ -1003,10 +1018,14 @@ Ndb::opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op) ...@@ -1003,10 +1018,14 @@ Ndb::opTupleIdOnNdb(Ndb_local_table_info* info, Uint64 opValue, Uint32 op)
tOperation->interpret_exit_nok(9999); tOperation->interpret_exit_nok(9999);
if ( (result = tConnection->execute( Commit )) == -1 ) if ( (result = tConnection->execute( Commit )) == -1 )
goto error_handler; {
if (tConnection->theError.code != 9999)
if (result == 9999) goto error_handler;
// NEXTID >= opValue, return ~(Uint64)0 for now since
// there is no error check...
ret = ~(Uint64)0; ret = ~(Uint64)0;
}
else else
{ {
info->m_first_tuple_id = info->m_last_tuple_id = opValue - 1; info->m_first_tuple_id = info->m_last_tuple_id = opValue - 1;
......
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