Below is the list of changes that have just been committed into a local
6.0 repository of jas. When jas does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2008-05-14 15:49:03-04:00, jas@rowvwade. +7 -0
Experiment with compare-and-swap backoff strategies.
storage/falcon/Backup.cpp@stripped, 2008-05-14 15:48:44-04:00, jas@rowvwade. +94 -0
New BitKeeper file ``storage/falcon/Backup.cpp''
storage/falcon/Backup.cpp@stripped, 2008-05-14 15:48:44-04:00, jas@rowvwade. +0 -0
storage/falcon/Backup.h@stripped, 2008-05-14 15:48:44-04:00, jas@rowvwade. +35 -0
New BitKeeper file ``storage/falcon/Backup.h''
storage/falcon/Backup.h@stripped, 2008-05-14 15:48:44-04:00, jas@rowvwade. +0 -0
storage/falcon/SyncObject.cpp@stripped, 2008-05-14 15:48:42-04:00, jas@rowvwade. +25 -4
Experiment with compare-and-swap backoff strategies.
storage/falcon/SyncObject.h@stripped, 2008-05-14 15:48:42-04:00, jas@rowvwade. +3 -0
Experiment with compare-and-swap backoff strategies.
storage/falcon/SyncTest.cpp@stripped, 2008-05-14 15:48:43-04:00, jas@rowvwade. +3 -2
Experiment with compare-and-swap backoff strategies.
storage/falcon/Thread.cpp@stripped, 2008-05-14 15:48:43-04:00, jas@rowvwade. +6 -0
Experiment with compare-and-swap backoff strategies.
storage/falcon/Thread.h@stripped, 2008-05-14 15:48:43-04:00, jas@rowvwade. +2 -0
Experiment with compare-and-swap backoff strategies.
diff -Nrup a/storage/falcon/Backup.cpp b/storage/falcon/Backup.cpp
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/storage/falcon/Backup.cpp 2008-05-14 15:48:44 -04:00
@@ -0,0 +1,94 @@
+/* Copyright (C) 2008 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include "Engine.h"
+#include "Backup.h"
+#include "Database.h"
+#include "Dbb.h"
+#include "Bdb.h"
+#include "IndexPage.h"
+#include "RecordLocatorPage.h"
+#include "DataPage.h"
+#include "DataOverFlowPage.h"
+#include "Hdr.h"
+#include "SectionPage.h"
+#include "IndexRootPage.h"
+#include "SequencePage.h"
+#include "PageInventoryPage.h"
+#include "InversionPage.h"
+#include "Log.h"
+#include "EncodedDataStream.h"
+
+Backup::Backup(Database *db)
+{
+ database = db;
+}
+
+Backup::~Backup(void)
+{
+}
+
+void Backup::backupPage(Dbb* dbb, int32 pageNumber, EncodedDataStream* stream)
+{
+ Bdb *bdb = dbb->fetchPage(pageNumber, PAGE_any, Shared);
+ Page *page = bdb->buffer;
+ stream->encodeInt(BACKUP_page);
+ stream->encodeInt(pageNumber);
+
+ switch (page->pageType)
+ {
+ case PAGE_header: // 1
+ ((Hdr*) page)->backup(stream);
+ break;
+
+ case PAGE_sections: // 2
+ ((SectionPage*) page)->backup(stream);
+ break;
+
+ case PAGE_record_locator: // 4
+ ((RecordLocatorPage*) page)->backup(stream);
+ break;
+
+ case PAGE_btree: // 5
+ ((IndexPage*) page)->backup(stream);
+ break;
+
+ case PAGE_data:
+ ((DataPage*) page)->backup(stream);
+ break;
+
+ case PAGE_inventory: // 8
+ ((PageInventoryPage*) page)->backup(stream);
+ break;
+
+ case PAGE_data_overflow: // 9
+ ((DataOverflowPage*) page)->backup(stream);
+ break;
+
+ case PAGE_inversion: // 10
+ ((InversionPage*) page)->backup(stream);
+ break;
+
+ case PAGE_free: // 11 Page has been released
+ Log::debug ("Page %d is a free page\n", pageNumber);
+ break;
+
+ default:
+ Log::debug ("Page %d is unknown type %d\n", pageNumber, page->pageType);
+ }
+
+
+ bdb->release();
+}
diff -Nrup a/storage/falcon/Backup.h b/storage/falcon/Backup.h
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/storage/falcon/Backup.h 2008-05-14 15:48:44 -04:00
@@ -0,0 +1,35 @@
+/* Copyright (C) 2008 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef _BACKUP_H_
+#define _BACKUP_H_
+
+static const int BACKUP_page = 1;
+
+class Database;
+class Dbb;
+class EncodedDataStream;
+
+class Backup
+{
+public:
+ Backup(Database *db);
+ ~Backup(void);
+ void backupPage(Dbb* dbb, int32 pageNumber, EncodedDataStream* stream);
+
+ Database* database;
+};
+
+#endif
diff -Nrup a/storage/falcon/SyncObject.cpp b/storage/falcon/SyncObject.cpp
--- a/storage/falcon/SyncObject.cpp 2008-04-21 22:11:37 -04:00
+++ b/storage/falcon/SyncObject.cpp 2008-05-14 15:48:42 -04:00
@@ -50,10 +50,12 @@
//#define STALL_THRESHOLD 1000
#define BACKOFF \
- if (false)\
- thread->sleep(1);\
+ if (thread)\
+ backoff(thread);\
else\
- thread = Thread::getThread("SyncObject::lock")
+ { thread = Thread::getThread("SyncObject::lock"); thread->backoff = BACKOFF_INTERVAL; }
+
+#define BACKOFF_INTERVAL (thread->random % 100)
#ifdef TRACE_SYNC_OBJECTS
@@ -109,6 +111,7 @@ SyncObject::SyncObject()
#ifdef TRACE_SYNC_OBJECTS
sharedCount = 0;
+ collisionCount = 0;
exclusiveCount = 0;
waitCount = 0;
queueLength = 0;
@@ -163,6 +166,7 @@ void SyncObject::lock(Sync *sync, LockTy
return;
}
+ BUMP_INTERLOCKED(collisionCount);
BACKOFF;
}
@@ -190,7 +194,8 @@ void SyncObject::lock(Sync *sync, LockTy
BACKOFF;
}
- thread = Thread::getThread("SyncObject::lock");
+ if (!thread)
+ thread = Thread::getThread("SyncObject::lock");
if (thread == exclusiveThread)
{
@@ -205,6 +210,7 @@ void SyncObject::lock(Sync *sync, LockTy
else
{
thread = Thread::getThread("SyncObject::lock");
+ thread->backoff = BACKOFF_INTERVAL;
ASSERT(thread);
if (thread == exclusiveThread)
@@ -717,4 +723,19 @@ void SyncObject::setName(const char* str
void SyncObject::timedout(int timeout)
{
throw SQLError(LOCK_TIMEOUT, "lock timed out after %d milliseconds\n", timeout);
+}
+
+int SyncObject::getCollisionCount(void)
+{
+ return collisionCount;
+}
+
+void SyncObject::backoff(Thread* thread)
+{
+ //thread->sleep(1);
+
+ for (int n = 0; n < thread->backoff; ++n)
+ ;
+
+ thread->backoff += thread->backoff;
}
diff -Nrup a/storage/falcon/SyncObject.h b/storage/falcon/SyncObject.h
--- a/storage/falcon/SyncObject.h 2008-04-09 04:23:49 -04:00
+++ b/storage/falcon/SyncObject.h 2008-05-14 15:48:42 -04:00
@@ -69,12 +69,14 @@ public:
void grantLocks(void);
//void assertionFailed(void);
int getState(void);
+ int getCollisionCount(void);
void validate(LockType lockType);
void unlock(void);
bool ourExclusiveLock(void);
void frequentStaller(Thread *thread, Sync *sync);
void setName(const char* name);
void timedout(int timeout);
+ void backoff(Thread* thread);
virtual void unlock (Sync *sync, LockType type);
virtual void lock (Sync *sync, LockType type, int timeout = 0);
@@ -101,6 +103,7 @@ protected:
#ifdef TRACE_SYNC_OBJECTS
int objectId;
INTERLOCK_TYPE sharedCount;
+ INTERLOCK_TYPE collisionCount;
int exclusiveCount;
int waitCount;
int queueLength;
diff -Nrup a/storage/falcon/SyncTest.cpp b/storage/falcon/SyncTest.cpp
--- a/storage/falcon/SyncTest.cpp 2007-10-04 12:10:10 -04:00
+++ b/storage/falcon/SyncTest.cpp 2008-05-14 15:48:43 -04:00
@@ -47,6 +47,7 @@ void SyncTest::test()
for (int n = 1; n <= MAX_THREADS; ++n)
{
sync.lock(Exclusive);
+ int collisions = syncObject.getCollisionCount();
stop = false;
int thd;
@@ -76,7 +77,7 @@ void SyncTest::test()
}
sync.unlock();
- Thread::sleep(1000);
+ Thread::sleep(5000);
stop = true;
threadBarn->waitForAll();
int total = 0;
@@ -84,7 +85,7 @@ void SyncTest::test()
for (thd = 0; thd < n; ++thd)
total += threads[thd].count;
- printf("%d threads, %d cycles:", n, total);
+ printf("%d threads, %d cycles, %d collisions:", n, total, syncObject.getCollisionCount() - collisions);
for (thd = 0; thd < n; ++thd)
printf(" %d", threads[thd].count);
diff -Nrup a/storage/falcon/Thread.cpp b/storage/falcon/Thread.cpp
--- a/storage/falcon/Thread.cpp 2007-11-05 18:00:23 -05:00
+++ b/storage/falcon/Thread.cpp 2008-05-14 15:48:43 -04:00
@@ -18,6 +18,9 @@
//////////////////////////////////////////////////////////////////////
#include <stdio.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
#ifdef _WIN32
#include <windows.h>
@@ -76,6 +79,8 @@ static int initThreads()
threadIndex = TlsAlloc();
#endif
+ srand((uint) time(NULL));
+
return 1;
}
@@ -113,6 +118,7 @@ void Thread::init(const char *desc)
lockGranted = false;
prior = NULL;
next = NULL;
+ random = rand();
}
Thread::~Thread()
diff -Nrup a/storage/falcon/Thread.h b/storage/falcon/Thread.h
--- a/storage/falcon/Thread.h 2007-11-09 10:06:09 -05:00
+++ b/storage/falcon/Thread.h 2008-05-14 15:48:43 -04:00
@@ -106,6 +106,8 @@ public:
bool marked;
int pageMarks;
int eventNumber; // for debugging
+ int random;
+ int backoff;
const char *description;
const char *where;
const TimeZone *defaultTimeZone;