2951 Kevin Lewis 2008-12-19
These are changes that Jim found in code not currently
used by Falcon. If we would ever expose the Falcon
string to date conversion method, the bug would have
become visible.
The problem was with daylight saving time transition
next November. The date 2009-11-06 was coming back
2009-11-05. This fix is in DateTime::timeRule().
Also in this changeset is a fix to the initializing
values for TimeZoneRule::time. The units should be
seconds after midnight (e.g. 7200).
modified:
storage/falcon/DateTime.cpp
2950 Kevin Lewis 2008-12-19
Various code cleanup
The deadlock detector shows that Database::syncSysDDL is always
locked before TableSpaceManager::syncObject, in every call stack.
But sometimes it is locked after as well. In TableSpaceManager
functions where both are locked, make sure the syncSysDDL is
always locked first.
In Transaction::visible, there is no reason to check both
the start event and the stop event when just checking the
stop event will do.
modified:
storage/falcon/TableSpaceManager.cpp
storage/falcon/Transaction.cpp
storage/falcon/TransactionManager.cpp
2949 Kevin Lewis 2008-12-19
Bug#41194 - The Transaction knows about the serial log.
Let it make calls to SerialLogRecord functions directly.
Separate the serial log flush of commit and rollback records
from when we allow the gophers to start processing them.
Once those records are flushed, the recovery will be able to
process them, but we do not want the gophers to do that until
the commit or rollback is fully finished.
There is no need for the prepare flush to also start a gopher.
modified:
storage/falcon/Database.cpp
storage/falcon/Database.h
storage/falcon/Dbb.cpp
storage/falcon/Dbb.h
storage/falcon/SRLCommit.cpp
storage/falcon/SRLPrepare.cpp
storage/falcon/SRLRollback.cpp
storage/falcon/SRLRollback.h
storage/falcon/SerialLogRecord.cpp
storage/falcon/SerialLogRecord.h
storage/falcon/Transaction.cpp
=== modified file 'storage/falcon/Database.cpp'
--- a/storage/falcon/Database.cpp 2008-11-20 17:05:50 +0000
+++ b/storage/falcon/Database.cpp 2008-12-19 18:45:32 +0000
@@ -2251,16 +2251,6 @@ void Database::deleteRepositoryBlob(cons
repository->deleteBlob (volume, blobId, transaction);
}
-void Database::commit(Transaction *transaction)
-{
- dbb->commit(transaction);
-}
-
-void Database::rollback(Transaction *transaction)
-{
- dbb->rollback(transaction->transactionId, transaction->hasUpdates);
-}
-
void Database::renameTable(Table* table, const char* newSchema, const char* newName)
{
newSchema = getSymbol(newSchema);
=== modified file 'storage/falcon/Database.h'
--- a/storage/falcon/Database.h 2008-10-16 01:04:03 +0000
+++ b/storage/falcon/Database.h 2008-12-19 18:45:32 +0000
@@ -116,8 +116,6 @@ public:
void shutdownNow();
void dropDatabase();
- void rollback (Transaction *transaction);
- void commit (Transaction *transaction);
void start();
void deleteRepositoryBlob(const char *schema, const char *repositoryName, int volume, int64 blobId, Transaction *transaction);
void deleteRepository (Repository *repository);
=== modified file 'storage/falcon/DateTime.cpp'
--- a/storage/falcon/DateTime.cpp 2008-10-31 15:42:42 +0000
+++ b/storage/falcon/DateTime.cpp 2008-12-20 05:33:13 +0000
@@ -110,37 +110,37 @@ static TimeZoneRule noDST[] = { 0,
static TimeZoneRule USDST[] = { 2007, 2,8,-1,7200000, 10,1,-1,7200000,
0, 3,1,-1,7200000, 9,-1,1,7200000 };
-static TimeZoneRule ParisDST[] = { 0, 2,-1,1,7200000, 9,-1,1,7200000 };
-static TimeZoneRule LondonDST[] = { 0, 2,-1,1,3600000, 9,-1,1,3600000 };
-static TimeZoneRule WarsawDST[] = { 0, 2,-1,1,3600000, 9,-1,1,7200000 };
+static TimeZoneRule ParisDST[] = { 0, 2,-1,1,7200, 9,-1,1,7200 };
+static TimeZoneRule LondonDST[] = { 0, 2,-1,1,3600, 9,-1,1,3600 };
+static TimeZoneRule WarsawDST[] = { 0, 2,-1,1,3600, 9,-1,1,7200 };
static TimeZoneRule BrazilDST[] = { 0, 9,1,-1,0, 1,11,-1,0 };
static TimeZoneRule AzoresDST[] = { 0, 2,-1,1,0, 9,-1,1,0 };
-static TimeZoneRule InstanbulDST[] = { 0, 2,-1,1,10800000, 9,-1,1,10800000 };
-static TimeZoneRule AustralianDST[] = { 0, 9,-1,1,7200000, 2,-1,1,10800000 };
+static TimeZoneRule InstanbulDST[] = { 0, 2,-1,1,10800, 9,-1,1,10800 };
+static TimeZoneRule AustralianDST[] = { 0, 9,-1,1,7200, 2,-1,1,10800 };
static TimeZoneRule CairoDST[] = { 0, 3,-1,6,0, 8,-1,6,0 };
-static TimeZoneRule AucklandDST[] = { 0, 9,1,-1,7200000, 2,15,-1,10800000 };
-static TimeZoneRule RussianDST[] = { 0, 2,-1,1,7200000, 9,-1,1,10800000 };
+static TimeZoneRule AucklandDST[] = { 0, 9,1,-1,7200, 2,15,-1,10800 };
+static TimeZoneRule RussianDST[] = { 0, 2,-1,1,7200, 9,-1,1,10800 };
static TimeZoneRule RarotongaDST[] = { 0, 9,-1,1,0, 2,1,-1,0 };
static TimeZoneRule TehranDST[] = { 0, 2,4,0,0, 8,4,0,0 };
static TimeZoneRule ChileDST[] = { 0, 9,9,-1,0, 2,9,-1,0 };
-static TimeZoneRule CubaDST[] = { 0, 3,1,-1,0, 9,8,-1,3600000 };
-static TimeZoneRule HaitiDST[] = { 0, 3,1,-1,3600000, 9,-1,1,7200000 };
+static TimeZoneRule CubaDST[] = { 0, 3,1,-1,0, 9,8,-1,3600 };
+static TimeZoneRule HaitiDST[] = { 0, 3,1,-1,3600, 9,-1,1,7200 };
static TimeZoneRule GrandTurkDST[] = { 0, 3,1,-1,0, 9,-1,1,0 };
-static TimeZoneRule GodthabDST[] = { 0, 2,-1,1,-7200000, 9,-1,1,-7200000 };
-static TimeZoneRule TripoliDST[] = { 0, 2,-1,5,7200000, 9,1,-5,10800000 };
-static TimeZoneRule AmmanDST[] = { 0, 3,1,-6,0, 8,15,-6,3600000 };
-static TimeZoneRule RigaDST[] = { 0, 2,-1,1,7200000, 8,-1,1,10800000 };
+static TimeZoneRule GodthabDST[] = { 0, 2,-1,1,-7200, 9,-1,1,-7200 };
+static TimeZoneRule TripoliDST[] = { 0, 2,-1,5,7200, 9,1,-5,10800 };
+static TimeZoneRule AmmanDST[] = { 0, 3,1,-6,0, 8,15,-6,3600 };
+static TimeZoneRule RigaDST[] = { 0, 2,-1,1,7200, 8,-1,1,10800 };
static TimeZoneRule BeruitDST[] = { 0, 2,-1,1,0, 8,-1,1,0 };
-static TimeZoneRule WindhoekDST[] = { 0, 8,1,-1,7200000, 3,1,-1,7200000 };
+static TimeZoneRule WindhoekDST[] = { 0, 8,1,-1,7200, 3,1,-1,7200 };
static TimeZoneRule DamascusDST[] = { 0, 3,1,0,0, 9,1,0,0 };
static TimeZoneRule JerusalamDST[] = { 0, 2,15,-6,0, 8,15,-1,0 };
-static TimeZoneRule BagdadDST[] = { 0, 3,1,0,10800000, 9,1,0,14400000 };
-static TimeZoneRule BakuDST[] = { 0, 2,-1,1,18000000, 9,-1,1,18000000 };
+static TimeZoneRule BagdadDST[] = { 0, 3,1,0,10800, 9,1,0,14400 };
+static TimeZoneRule BakuDST[] = { 0, 2,-1,1,18000, 9,-1,1,18000 };
static TimeZoneRule BishkekDST[] = { 0, 3,7,-1,0, 8,-1,1,0 };
-static TimeZoneRule HobartDST[] = { 0, 9,1,-1,7200000, 2,-1,1,10800000 };
-static TimeZoneRule NoumeaDST[] = { 0, 10,-1,1,7200000, 2,1,-1,10800000 };
-static TimeZoneRule ChathamDST[] = { 0, 9,1,-1,9900000, 2,15,-1,13500000 };
+static TimeZoneRule HobartDST[] = { 0, 9,1,-1,7200, 2,-1,1,10800 };
+static TimeZoneRule NoumeaDST[] = { 0, 10,-1,1,7200, 2,1,-1,10800 };
+static TimeZoneRule ChathamDST[] = { 0, 9,1,-1,9900, 2,15,-1,13500 };
static TimeZoneRule StandleyDST[] = { 0, 8,8,-1,0, 3,16,-1,0 };
static TimeZoneRule AsuncionDST[] = { 0, 9,1,0,0, 2,1,0,0 };
//static TimeZoneRule DST = { };
@@ -1258,8 +1258,6 @@ int DateTime::timeRule(tm *time, int64 f
changeDay += 7;
}
- ++changeDay;
-
if (time->tm_mday < changeDay)
return -1;
=== modified file 'storage/falcon/Dbb.cpp'
--- a/storage/falcon/Dbb.cpp 2008-10-30 00:22:54 +0000
+++ b/storage/falcon/Dbb.cpp 2008-12-19 18:45:32 +0000
@@ -1169,34 +1169,6 @@ void Dbb::reportStatistics()
priorFlushWrites = flushWrites;
}
-void Dbb::commit(Transaction *transaction)
-{
- if (transaction->hasUpdates)
- serialLog->logControl->commit.append(transaction);
-}
-
-void Dbb::prepareTransaction(TransId transId, int xidLength, const UCHAR *xid)
-{
- serialLog->logControl->prepare.append(transId, xidLength, xid);
-}
-
-void Dbb::rollback(TransId transId, bool updateTransaction)
-{
- if (updateTransaction)
- {
- if (serialLog)
- serialLog->logControl->rollback.append(transId, updateTransaction);
- //flush();
- }
-}
-
-/***
-void Dbb::setRecovering(bool flag)
-{
- recovering = flag;
-}
-***/
-
void Dbb::enableSerialLog()
{
Bdb *bdb = fetchPage(HEADER_PAGE, PAGE_header, Exclusive);
=== modified file 'storage/falcon/Dbb.h'
--- a/storage/falcon/Dbb.h 2008-10-30 00:22:54 +0000
+++ b/storage/falcon/Dbb.h 2008-12-19 18:45:32 +0000
@@ -113,10 +113,7 @@ public:
void createSection(int32 sectionId, TransId transId);
void dropDatabase();
void enableSerialLog();
- void rollback (TransId transId, bool updateTransaction);
void updateRecord(int32 sectionId, int32 recordId, Stream *stream, TransId transId, bool earlyWrite);
- void prepareTransaction(TransId transId, int xidLength, const UCHAR *xid);
- void commit(Transaction *transaction);
void reportStatistics();
bool hasDirtyPages();
bool deleteShadow (DatabaseCopy *shadow);
=== modified file 'storage/falcon/SRLCommit.cpp'
--- a/storage/falcon/SRLCommit.cpp 2007-10-04 20:45:34 +0000
+++ b/storage/falcon/SRLCommit.cpp 2008-12-19 18:45:32 +0000
@@ -46,18 +46,16 @@ void SRLCommit::append(Transaction *tran
transaction->addRef();
START_RECORD(srlCommit, "SRLCommit::append");
putInt(transaction->transactionId);
- //uint64 commitBlockNumber = log->nextBlockNumber;
uint64 commitBlockNumber = log->getWriteBlockNumber();
SerialLogTransaction *srlTransaction = log->getTransaction(transaction->transactionId);
-
+ srlTransaction->setTransaction(transaction);
+
+ // Flush transactions with changes immediately for durability
+
if (transaction->hasUpdates)
log->flush(false, commitBlockNumber, &sync);
else
sync.unlock();
-
- srlTransaction->setTransaction(transaction);
- srlTransaction->setState(sltCommitted);
- wakeup();
}
void SRLCommit::read()
=== modified file 'storage/falcon/SRLPrepare.cpp'
--- a/storage/falcon/SRLPrepare.cpp 2008-07-24 08:45:03 +0000
+++ b/storage/falcon/SRLPrepare.cpp 2008-12-19 18:45:32 +0000
@@ -47,15 +47,12 @@ void SRLPrepare::append(TransId transId,
putInt(transId);
putInt(xidLength);
putData(xidLength, xid);
- SerialLogTransaction *transaction = log->getTransaction(transId);
+ SerialLogTransaction *srlTransaction = log->getTransaction(transId);
log->flush(false, log->nextBlockNumber, &sync);
- if (transaction)
- transaction->setState(sltPrepared);
-
- if (transaction)
- wakeup();
+ if (srlTransaction)
+ srlTransaction->setState(sltPrepared);
}
void SRLPrepare::read()
=== modified file 'storage/falcon/SRLRollback.cpp'
--- a/storage/falcon/SRLRollback.cpp 2008-07-24 08:45:03 +0000
+++ b/storage/falcon/SRLRollback.cpp 2008-12-19 18:45:32 +0000
@@ -38,23 +38,16 @@ SRLRollback::~SRLRollback()
}
-void SRLRollback::append(TransId transId, bool updateTransaction)
+void SRLRollback::append(Transaction *transaction)
{
START_RECORD(srlRollback, "SRLRollback::append");
- putInt(transId);
+ putInt(transaction->transactionId);
uint64 commitBlockNumber = log->nextBlockNumber;
- SerialLogTransaction *transaction = log->findTransaction(transId);
- if (updateTransaction)
+ if (transaction->hasUpdates)
log->flush(false, commitBlockNumber, &sync);
else
sync.unlock();
-
- if (transaction)
- {
- transaction->setState(sltRolledBack);
- wakeup();
- }
}
void SRLRollback::read()
=== modified file 'storage/falcon/SRLRollback.h'
--- a/storage/falcon/SRLRollback.h 2007-09-20 15:44:25 +0000
+++ b/storage/falcon/SRLRollback.h 2008-12-19 18:45:32 +0000
@@ -33,7 +33,7 @@ public:
virtual void print();
virtual void pass1();
virtual void read();
- void append(TransId transId, bool updateTransaction);
+ void append(Transaction *transaction);
SRLRollback();
virtual ~SRLRollback();
=== modified file 'storage/falcon/SerialLogRecord.cpp'
--- a/storage/falcon/SerialLogRecord.cpp 2008-11-20 17:05:50 +0000
+++ b/storage/falcon/SerialLogRecord.cpp 2008-12-19 18:45:32 +0000
@@ -226,11 +226,6 @@ void SerialLogRecord::startRecord()
log->startRecord();
}
-void SerialLogRecord::wakeup()
-{
- log->wakeup();
-}
-
void SerialLogRecord::putStream(Stream *stream)
{
putInt(stream->totalLength);
=== modified file 'storage/falcon/SerialLogRecord.h'
--- a/storage/falcon/SerialLogRecord.h 2008-11-14 02:30:11 +0000
+++ b/storage/falcon/SerialLogRecord.h 2008-12-19 18:45:32 +0000
@@ -98,7 +98,6 @@ public:
int getInt(const UCHAR** ptr);
const UCHAR* getData(int32 length);
void putStream (Stream *stream);
- void wakeup();
void startRecord();
void putData(uint32 length, const UCHAR *data);
void putInt(int32 number);
=== modified file 'storage/falcon/TableSpaceManager.cpp'
--- a/storage/falcon/TableSpaceManager.cpp 2008-11-05 17:58:43 +0000
+++ b/storage/falcon/TableSpaceManager.cpp 2008-12-19 19:41:28 +0000
@@ -86,7 +86,10 @@ void TableSpaceManager::add(TableSpace *
TableSpace* TableSpaceManager::findTableSpace(const char *name)
{
- Sync syncObj(&syncObject, "TableSpaceManager::findTableSpace(1)");
+ Sync syncDDL(&database->syncSysDDL, "TableSpaceManager::findTableSpace(DDL)");
+ syncDDL.lock(Shared);
+
+ Sync syncObj(&syncObject, "TableSpaceManager::findTableSpace(syncObj)");
syncObj.lock(Shared);
TableSpace *tableSpace;
@@ -101,9 +104,6 @@ TableSpace* TableSpaceManager::findTable
if (tableSpace->name == name)
return tableSpace;
- Sync syncDDL(&database->syncSysDDL, "TableSpaceManager::findTableSpace(2)");
- syncDDL.lock(Shared);
-
PStatement statement = database->prepareStatement(
"select tablespace_id, filename, comment from system.tablespaces where tablespace=?");
statement->setString(1, name);
@@ -156,6 +156,7 @@ TableSpace* TableSpaceManager::createTab
{
Sync syncDDL(&database->syncSysDDL, "TableSpaceManager::createTableSpace");
syncDDL.lock(Exclusive);
+
Sequence *sequence = database->sequenceManager->getSequence(database->getSymbol("SYSTEM"), database->getSymbol("TABLESPACE_IDS"));
int type = (repository) ? TABLESPACE_TYPE_REPOSITORY : TABLESPACE_TYPE_TABLESPACE;
int id = (int) sequence->update(1, database->getSystemTransaction());
@@ -175,6 +176,7 @@ TableSpace* TableSpaceManager::createTab
if (!repository)
tableSpace->create();
+
createdFile = true;
add(tableSpace);
database->serialLog->logControl->createTableSpace.append(tableSpace);
@@ -183,11 +185,15 @@ TableSpace* TableSpaceManager::createTab
{
if (createdFile)
IO::deleteFile(fileName);
+
database->rollbackSystemTransaction();
delete tableSpace;
+
throw;
}
+
database->commitSystemTransaction();
+
return tableSpace;
}
@@ -272,12 +278,12 @@ void TableSpaceManager::dropDatabase(voi
void TableSpaceManager::dropTableSpace(TableSpace* tableSpace)
{
- Sync syncObj(&syncObject, "TableSpaceManager::dropTableSpace(1)");
+ Sync syncDDL(&database->syncSysDDL, "TableSpaceManager::dropTableSpace(DDL)");
+ syncDDL.lock(Exclusive);
+
+ Sync syncObj(&syncObject, "TableSpaceManager::dropTableSpace(syncObj)");
syncObj.lock(Exclusive);
- Sync syncDDL(&database->syncSysDDL, "TableSpaceManager::dropTableSpace(2)");
- syncDDL.lock(Shared);
-
PStatement statement = database->prepareStatement(
"delete from system.tablespaces where tablespace=?");
statement->setString(1, tableSpace->name);
@@ -419,14 +425,15 @@ void TableSpaceManager::redoCreateTableS
void TableSpaceManager::initialize(void)
{
- Sync syncObj(&syncObject, "TableSpaceManager::initialize");
+ Sync syncDDL(&database->syncSysDDL, "TableSpaceManager::initialize(DDL)");
+ syncDDL.lock(Exclusive);
+
+ Sync syncObj(&syncObject, "TableSpaceManager::initialize(syncObj)");
syncObj.lock(Shared);
for (TableSpace *tableSpace = tableSpaces; tableSpace; tableSpace = tableSpace->next)
if (tableSpace->needSave)
{
- Sync syncDDL(&database->syncSysDDL, "TableSpaceManager::dropTableSpace");
- syncDDL.lock(Shared);
tableSpace->save();
syncDDL.unlock();
database->commitSystemTransaction();
=== modified file 'storage/falcon/Transaction.cpp'
--- a/storage/falcon/Transaction.cpp 2008-12-16 20:40:38 +0000
+++ b/storage/falcon/Transaction.cpp 2008-12-19 19:41:28 +0000
@@ -37,6 +37,7 @@
#include "TransactionManager.h"
#include "SerialLog.h"
#include "SerialLogControl.h"
+#include "SerialLogTransaction.h"
#include "InfoTable.h"
#include "Thread.h"
#include "Format.h"
@@ -266,6 +267,11 @@ void Transaction::commit()
database->flushInversion(this);
+ // Write the commit message to the serial log for durability.
+ // If a crash happens after this, the recover will commit.
+
+ database->serialLog->logControl->commit.append(this);
+
// Transfer transaction from active list to committed list, set committed state
Sync syncActiveTransactions(&transactionManager->activeTransactions.syncObject, "Transaction::commit(2)");
@@ -293,8 +299,12 @@ void Transaction::commit()
syncActiveTransactions.unlock();
syncIsActive.unlock(); // signal waiting transactions
+
+ // signal a gopher to start processing this transaction
- database->commit(this);
+ SerialLogTransaction *srlTransaction = database->serialLog->getTransaction(transactionId);
+ srlTransaction->setState(sltCommitted);
+ database->serialLog->wakeup();
delete [] xid;
xid = NULL;
@@ -411,12 +421,13 @@ void Transaction::rollback()
ASSERT(writePending);
writePending = false;
-
+
if (hasUpdates)
+ {
database->serialLog->preCommit(this);
-
- database->rollback(this);
-
+ database->serialLog->logControl->rollback.append(this);
+ }
+
if (xid)
{
delete [] xid;
@@ -433,6 +444,16 @@ void Transaction::rollback()
syncActiveTransactions.unlock();
state = RolledBack;
syncIsActive.unlock();
+
+ // Finish the SerialLogTransaction and signal a gopher
+
+ if (hasUpdates)
+ {
+ SerialLogTransaction *srlTransaction = database->serialLog->getTransaction(transactionId);
+ srlTransaction->setState(sltRolledBack);
+ database->serialLog->wakeup();
+ }
+
release();
}
@@ -455,7 +476,10 @@ void Transaction::prepare(int xidLen, co
database->pageWriter->waitForWrites(this);
state = Limbo;
- database->dbb->prepareTransaction(transactionId, xidLength, xid);
+
+ // Flush a prepare record to the serial log
+
+ database->serialLog->logControl->prepare.append(transactionId, xidLength, xid);
Sync sync(&syncDeferredIndexes, "Transaction::prepare");
sync.lock(Shared);
@@ -696,12 +720,7 @@ bool Transaction::visible(Transaction *
// This is REPEATABLE_READ
ASSERT (IS_REPEATABLE_READ(isolationLevel));
- // If the transaction started after we did, consider the transaction active
-
- if (transId > transactionId)
- return false;
-
- // If the other transaction committed after we started then it should not
+ // If the other transaction committed after we started then it is not
// be visible to us
if (transaction->commitId > transactionId)
@@ -1413,12 +1432,15 @@ void Transaction::getInfo(InfoTable* inf
}
}
+// Called by the gopher thread to complete this transaction
+
void Transaction::fullyCommitted(void)
{
ASSERT(inList);
+ ASSERT(!isActive());
if (useCount < 2)
- Log::debug("Transaction::fullyCommitted: funny use count\n");
+ Log::debug("Transaction::fullyCommitted: Unusual use count=%d\n", useCount);
writeComplete();
releaseCommittedTransaction();
=== modified file 'storage/falcon/TransactionManager.cpp'
--- a/storage/falcon/TransactionManager.cpp 2008-12-16 20:40:38 +0000
+++ b/storage/falcon/TransactionManager.cpp 2008-12-19 19:41:28 +0000
@@ -365,9 +365,9 @@ void TransactionManager::purgeTransactio
// Check for any fully mature transactions to ditch
- Transaction* transaction = committedTransactions.first;
+ Transaction* transaction = committedTransactions.first;
- while ((transaction != NULL) &&
+ while ((transaction != NULL) &&
(transaction->state == Committed) &&
(transaction->commitId < oldestActive) &&
!transaction->writePending)
| Thread |
|---|
| • bzr push into mysql-6.0-falcon-team branch (klewis:2949 to 2951) Bug#41194 | Kevin Lewis | 20 Dec |