8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 02:03:04 +01:00

Corrections according to Adriano review

This commit is contained in:
Vlad Khorsun 2022-06-02 22:36:08 +03:00
parent fa90269460
commit f881f3119c
13 changed files with 229 additions and 239 deletions

View File

@ -31,12 +31,11 @@
#include "../common/classes/SafeArg.h"
#include "../burp/burp_proto.h"
#include "../burp/mvol_proto.h"
//#include "../common/stuff.h"
//#include "../jrd/align.h"
using MsgFormat::SafeArg;
using namespace Firebird;
namespace Firebird
namespace Burp
{
/// class IOBuffer
@ -57,11 +56,6 @@ IOBuffer::IOBuffer(void* item, FB_SIZE_T size) :
m_aligned = m_memory;
}
IOBuffer::~IOBuffer()
{
delete[] m_memory;
}
class BurpGblHolder
{
@ -163,10 +157,10 @@ void BackupRelationTask::SetRelation(burp_rel* relation)
m_readDone = false;
m_nextPP = 0;
m_metadata.setRelation(m_relation, GetMaxWorkers() > 2);
m_metadata.setRelation(m_relation, getMaxWorkers() > 2);
}
bool BackupRelationTask::Handler(WorkItem& _item)
bool BackupRelationTask::handler(WorkItem& _item)
{
Item* item = reinterpret_cast<Item*>(&_item);
@ -201,7 +195,7 @@ bool BackupRelationTask::Handler(WorkItem& _item)
return false;
}
bool BackupRelationTask::GetWorkItem(BackupRelationTask::WorkItem** pItem)
bool BackupRelationTask::getWorkItem(BackupRelationTask::WorkItem** pItem)
{
Item* item = reinterpret_cast<Item*> (*pItem);
@ -220,12 +214,14 @@ bool BackupRelationTask::GetWorkItem(BackupRelationTask::WorkItem** pItem)
if (item == NULL && !m_readDone)
{
for (Item** p = m_items.begin(); p < m_items.end(); p++)
{
if (!(*p)->m_inuse)
{
(*p)->m_inuse = true;
*pItem = item = *p;
break;
}
}
}
if (!item)
@ -256,12 +252,12 @@ bool BackupRelationTask::GetWorkItem(BackupRelationTask::WorkItem** pItem)
return (item && item->m_inuse);
}
bool BackupRelationTask::GetResult(IStatus* /*status*/)
bool BackupRelationTask::getResult(IStatus* /*status*/)
{
return !m_error;
}
int BackupRelationTask::GetMaxWorkers()
int BackupRelationTask::getMaxWorkers()
{
unsigned int readers = m_items.getCount() - 1;
@ -274,8 +270,10 @@ int BackupRelationTask::GetMaxWorkers()
IOBuffer* BackupRelationTask::getCleanBuffer(Item& item)
{
while (!m_stop)
{
if (item.m_cleanSem.tryEnter(0, 200))
break;
}
if (m_stop)
return NULL;
@ -414,8 +412,10 @@ BackupRelationTask* BackupRelationTask::getBackupTask(BurpGlobals* tdgbl)
IOBuffer* BackupRelationTask::getDirtyBuffer()
{
while (!m_stop)
{
if (m_dirtySem.tryEnter(0, 200))
break;
}
if (m_stop)
return NULL;
@ -678,7 +678,7 @@ void RestoreRelationTask::SetRelation(BurpGlobals* tdgbl, burp_rel* relation)
m_metadata.setRelation(tdgbl, m_relation);
}
bool RestoreRelationTask::Handler(WorkItem& _item)
bool RestoreRelationTask::handler(WorkItem& _item)
{
Item* item = reinterpret_cast<Item*>(&_item);
@ -715,7 +715,7 @@ bool RestoreRelationTask::Handler(WorkItem& _item)
return false;
}
bool RestoreRelationTask::GetWorkItem(WorkItem** pItem)
bool RestoreRelationTask::getWorkItem(WorkItem** pItem)
{
Item* item = reinterpret_cast<Item*> (*pItem);
@ -735,12 +735,14 @@ bool RestoreRelationTask::GetWorkItem(WorkItem** pItem)
if (item == NULL && haveWork)
{
for (Item** p = m_items.begin(); p < m_items.end(); p++)
{
if (!(*p)->m_inuse && (!(*p)->m_reader || !m_readDone))
{
(*p)->m_inuse = true;
*pItem = item = *p;
break;
}
}
}
if (!item)
@ -764,12 +766,12 @@ bool RestoreRelationTask::GetWorkItem(WorkItem** pItem)
return (item && item->m_inuse);
}
bool RestoreRelationTask::GetResult(IStatus* status)
bool RestoreRelationTask::getResult(IStatus* status)
{
return !m_error;
}
int RestoreRelationTask::GetMaxWorkers()
int RestoreRelationTask::getMaxWorkers()
{
return m_items.getCount();
}
@ -788,7 +790,7 @@ void RestoreRelationTask::verbRecs(FB_UINT64& records, bool total)
if (!total)
++records;
const FB_UINT64 verb = m_masterGbl->verboseInterval / GetMaxWorkers();
const FB_UINT64 verb = m_masterGbl->verboseInterval / getMaxWorkers();
if (records < verb && !total)
return;
@ -946,8 +948,10 @@ bool RestoreRelationTask::freeItem(Item& item, bool commit)
IOBuffer* RestoreRelationTask::getCleanBuffer()
{
while (!m_stop)
{
if (m_cleanSem.tryEnter(0, 200))
break;
}
if (m_stop)
return NULL;
@ -1086,7 +1090,7 @@ RestoreRelationTask::Item::EnsureUnlockBuffer::~EnsureUnlockBuffer()
void RestoreRelationTask::ExcReadDone::stuffByException(StaticStatusVector& status) const throw()
{
ISC_STATUS sv[] = {isc_arg_gds, isc_random, isc_arg_string,
(ISC_STATUS)(IPTR) "Unexpected call to Firebird::RestoreRelationTask::ExcReadDone::stuffException()", isc_arg_end};
(ISC_STATUS)(IPTR) "Unexpected call to RestoreRelationTask::ExcReadDone::stuffException()", isc_arg_end};
try
{
@ -1100,7 +1104,7 @@ void RestoreRelationTask::ExcReadDone::stuffByException(StaticStatusVector& stat
const char* RestoreRelationTask::ExcReadDone::what() const throw()
{
return "Firebird::RestoreRelationTask::ExcReadDone";
return "RestoreRelationTask::ExcReadDone";
}
void RestoreRelationTask::ExcReadDone::raise()

View File

@ -34,15 +34,16 @@
#include "../common/Task.h"
#include "../common/UtilSvc.h"
#include "../common/classes/array.h"
#include "../common/classes/auto.h"
#include "../common/classes/condition.h"
#include "../common/classes/fb_atomic.h"
namespace Firebird {
namespace Burp {
class ReadRelationMeta
{
public:
ReadRelationMeta() :
ReadRelationMeta() :
m_blr(*getDefaultMemoryPool())
{
clear();
@ -88,9 +89,9 @@ public:
void reset(const ReadRelationMeta* meta);
void clear();
void compile(Firebird::CheckStatusWrapper* status, IAttachment* db);
void compile(Firebird::CheckStatusWrapper* status, Firebird::IAttachment* db);
void setParams(ULONG loPP, ULONG hiPP);
void start(Firebird::CheckStatusWrapper* status, ITransaction* tran);
void start(Firebird::CheckStatusWrapper* status, Firebird::ITransaction* tran);
void receive(Firebird::CheckStatusWrapper* status);
void release(Firebird::CheckStatusWrapper* status);
@ -110,7 +111,7 @@ public:
}
private:
struct INMSG
struct InMsg
{
ULONG loPP;
ULONG hiPP;
@ -118,10 +119,10 @@ private:
const burp_rel* m_relation;
const ReadRelationMeta* m_meta;
INMSG m_inMgs;
InMsg m_inMgs;
Firebird::Array<UCHAR> m_outMsg;
SSHORT* m_eof;
IRequest* m_request;
Firebird::IRequest* m_request;
};
@ -137,7 +138,7 @@ public:
void setRelation(BurpGlobals* tdgbl, const burp_rel* relation);
void clear();
IBatch* createBatch(BurpGlobals* tdgbl, IAttachment* att);
Firebird::IBatch* createBatch(BurpGlobals* tdgbl, Firebird::IAttachment* att);
//private:
bool prepareBatch(BurpGlobals* tdgbl);
@ -183,8 +184,8 @@ public:
void reset(WriteRelationMeta* meta);
void clear();
void compile(BurpGlobals* tdgbl, IAttachment* att);
void send(BurpGlobals* tdgbl, ITransaction* tran, bool lastRec);
void compile(BurpGlobals* tdgbl, Firebird::IAttachment* att);
void send(BurpGlobals* tdgbl, Firebird::ITransaction* tran, bool lastRec);
void release();
ULONG getDataLength() const
@ -197,7 +198,7 @@ public:
return m_inMsg.begin();
}
IBatch* getBatch() const
Firebird::IBatch* getBatch() const
{
return m_batch;
}
@ -222,8 +223,8 @@ private:
WriteRelationMeta* m_meta;
Firebird::Array<UCHAR> m_inMsg;
Firebird::Array<UCHAR> m_batchMsg;
IBatch* m_batch;
IRequest* m_request;
Firebird::IBatch* m_batch;
Firebird::IRequest* m_request;
int m_recs;
bool m_resync;
};
@ -231,7 +232,7 @@ private:
// forward declaration
class IOBuffer;
class BackupRelationTask : public Jrd::Task
class BackupRelationTask : public Firebird::Task
{
public:
BackupRelationTask(BurpGlobals* tdgbl);
@ -239,12 +240,12 @@ public:
void SetRelation(burp_rel* relation);
bool Handler(WorkItem& _item);
bool GetWorkItem(WorkItem** pItem);
bool GetResult(IStatus* status);
int GetMaxWorkers();
bool handler(WorkItem& _item);
bool getWorkItem(WorkItem** pItem);
bool getResult(Firebird::IStatus* status);
int getMaxWorkers();
class Item : public Task::WorkItem
class Item : public Firebird::Task::WorkItem
{
public:
Item(BackupRelationTask* task, bool writer) : WorkItem(task),
@ -260,7 +261,7 @@ public:
m_buffer(NULL)
{}
BackupRelationTask* getBackupTask() const
BackupRelationTask* getBackupTask() const
{
return reinterpret_cast<BackupRelationTask*> (m_task);
}
@ -279,16 +280,16 @@ public:
bool m_writer; // file writer or table reader
bool m_ownAttach;
BurpGlobals* m_gbl;
IAttachment* m_att;
ITransaction* m_tra;
Firebird::IAttachment* m_att;
Firebird::ITransaction* m_tra;
burp_rel* m_relation;
ReadRelationReq m_request;
ULONG m_ppSequence; // PP to read
Mutex m_mutex;
HalfStaticArray<IOBuffer*, 2> m_cleanBuffers;
Firebird::Mutex m_mutex;
Firebird::HalfStaticArray<IOBuffer*, 2> m_cleanBuffers;
IOBuffer* m_buffer;
Semaphore m_cleanSem;
Firebird::Semaphore m_cleanSem;
};
static BackupRelationTask* getBackupTask(BurpGlobals* tdgbl);
@ -304,7 +305,7 @@ public:
return m_stop;
}
Mutex burpOutMutex;
Firebird::Mutex burpOutMutex;
private:
void initItem(BurpGlobals* tdgbl, Item& item);
void freeItem(Item& item);
@ -325,19 +326,19 @@ private:
bool m_readDone; // true when all readers are done
ULONG m_nextPP;
Mutex m_mutex;
HalfStaticArray<Item*, 8> m_items;
Firebird::Mutex m_mutex;
Firebird::HalfStaticArray<Item*, 8> m_items;
ISC_STATUS_ARRAY m_status;
volatile bool m_stop;
bool m_error;
HalfStaticArray<IOBuffer*, 16> m_buffers;
HalfStaticArray<IOBuffer*, 8> m_dirtyBuffers;
Semaphore m_dirtySem;
Firebird::HalfStaticArray<IOBuffer*, 16> m_buffers;
Firebird::HalfStaticArray<IOBuffer*, 8> m_dirtyBuffers;
Firebird::Semaphore m_dirtySem;
};
class RestoreRelationTask : public Jrd::Task
class RestoreRelationTask : public Firebird::Task
{
public:
RestoreRelationTask(BurpGlobals* tdgbl);
@ -345,12 +346,12 @@ public:
void SetRelation(BurpGlobals* tdgbl, burp_rel* relation);
bool Handler(WorkItem& _item);
bool GetWorkItem(WorkItem** pItem);
bool GetResult(IStatus* status);
int GetMaxWorkers();
bool handler(WorkItem& _item);
bool getWorkItem(WorkItem** pItem);
bool getResult(Firebird::IStatus* status);
int getMaxWorkers();
class Item : public Task::WorkItem
class Item : public Firebird::Task::WorkItem
{
public:
Item(RestoreRelationTask* task, bool reader) : WorkItem(task),
@ -383,20 +384,20 @@ public:
bool m_reader; // file reader or table writer
bool m_ownAttach;
BurpGlobals* m_gbl;
IAttachment* m_att;
ITransaction* m_tra;
Firebird::IAttachment* m_att;
Firebird::ITransaction* m_tra;
burp_rel* m_relation;
WriteRelationReq m_request;
Mutex m_mutex;
Firebird::Mutex m_mutex;
IOBuffer* m_buffer;
};
class ExcReadDone : public Exception
class ExcReadDone : public Firebird::Exception
{
public:
ExcReadDone() throw() : Exception() { }
virtual void stuffByException(StaticStatusVector& status_vector) const throw();
ExcReadDone() throw() : Firebird::Exception() { }
virtual void stuffByException(Firebird::StaticStatusVector& status_vector) const throw();
virtual const char* what() const throw();
static void raise();
};
@ -425,7 +426,7 @@ public:
// commit and detach all worker connections
bool finish();
Mutex burpOutMutex;
Firebird::Mutex burpOutMutex;
private:
void initItem(BurpGlobals* tdgbl, Item& item);
bool freeItem(Item& item, bool commit);
@ -452,19 +453,19 @@ private:
int m_writers; // number of active writers, could be less than items allocated
bool m_readDone; // all records was read
Mutex m_mutex;
HalfStaticArray<Item*, 8> m_items;
Firebird::Mutex m_mutex;
Firebird::HalfStaticArray<Item*, 8> m_items;
ISC_STATUS_ARRAY m_status;
volatile bool m_stop;
bool m_error;
Firebird::AtomicCounter m_records; // records restored for the current relation
FB_UINT64 m_verbRecs; // last records count reported
HalfStaticArray<IOBuffer*, 16> m_buffers;
HalfStaticArray<IOBuffer*, 16> m_cleanBuffers;
HalfStaticArray<IOBuffer*, 16> m_dirtyBuffers;
Semaphore m_cleanSem;
Condition m_dirtyCond;
Firebird::HalfStaticArray<IOBuffer*, 16> m_buffers;
Firebird::HalfStaticArray<IOBuffer*, 16> m_cleanBuffers;
Firebird::HalfStaticArray<IOBuffer*, 16> m_dirtyBuffers;
Firebird::Semaphore m_cleanSem;
Firebird::Condition m_dirtyCond;
};
@ -472,27 +473,25 @@ class IOBuffer
{
public:
IOBuffer(void*, FB_SIZE_T size);
~IOBuffer();
UCHAR* getBuffer() const
{
return m_aligned;
}
FB_SIZE_T getSize() const
{
return m_size;
{
return m_size;
}
FB_SIZE_T getRecs() const
{
return m_recs;
{
return m_recs;
}
FB_SIZE_T getUsed() const
{
return m_used;
{
return m_used;
}
void setUsed(FB_SIZE_T used)
@ -562,7 +561,7 @@ public:
private:
void* const m_item;
UCHAR* m_memory;
Firebird::AutoPtr<UCHAR> m_memory;
UCHAR* m_aligned;
const FB_SIZE_T m_size;
FB_SIZE_T m_used;
@ -570,7 +569,7 @@ private:
IOBuffer* m_next;
bool m_linked;
int m_locked;
Mutex m_mutex;
Firebird::Mutex m_mutex;
};
@ -606,6 +605,6 @@ private:
BurpGlobals* m_tdgbl;
};
} // namespace Firebird
} // namespace Burp
#endif // BURP_TASKS_H

View File

@ -64,6 +64,7 @@
using MsgFormat::SafeArg;
using namespace Firebird;
using namespace Burp;
// For service APIs the follow DB handle is a value stored
@ -394,8 +395,8 @@ int BACKUP_backup(const TEXT* dbb_file, const TEXT* file_name)
// Now go back and write all data
{
Jrd::Coordinator coord(getDefaultMemoryPool());
Firebird::BackupRelationTask task(tdgbl);
Coordinator coord(getDefaultMemoryPool());
BackupRelationTask task(tdgbl);
for (burp_rel* relation = tdgbl->relations; relation; relation = relation->rel_next)
{
@ -409,9 +410,9 @@ int BACKUP_backup(const TEXT* dbb_file, const TEXT* file_name)
if (!(tdgbl->gbl_sw_meta || tdgbl->skipRelation(relation->rel_name)))
{
task.SetRelation(relation);
coord.RunSync(&task);
coord.runSync(&task);
if (!task.GetResult(NULL))
if (!task.getResult(NULL))
BURP_exit_local(FINI_ERROR, tdgbl);
}
}
@ -2011,7 +2012,7 @@ void put_relation( burp_rel* relation)
{
FOR(REQUEST_HANDLE tdgbl->handles_put_relation_req_handle3)
FIRST 1 P IN RDB$PAGES WITH P.RDB$RELATION_ID EQ relation->rel_id
AND P.RDB$PAGE_TYPE = 4
AND P.RDB$PAGE_TYPE = pag_pointer
SORTED BY DESCENDING P.RDB$PAGE_SEQUENCE
relation->rel_max_pp = P.RDB$PAGE_SEQUENCE;
END_FOR;
@ -4388,7 +4389,7 @@ void write_user_privileges()
} // namespace
namespace Firebird {
namespace Burp {
/// class ReadRelationMeta
@ -4827,4 +4828,4 @@ bool BackupRelationTask::tableReader(Item& item)
return true;
}
} // namespace Firebird
} // namespace Burp

View File

@ -86,6 +86,7 @@
using namespace Firebird;
using MsgFormat::SafeArg;
using namespace Burp;
const char* fopen_write_type = "w";
const char* fopen_read_type = "r";

View File

@ -70,6 +70,7 @@
using MsgFormat::SafeArg;
using Firebird::FbLocalStatus;
using namespace Burp;
const int open_mask = 0666;
@ -837,7 +838,7 @@ void MVOL_read(BurpGlobals* tdgbl)
if (!tdgbl->master)
{
// hvlad: it will throw ExcReadDone exception when there is nothing to read
Firebird::RestoreRelationTask::renewBuffer(tdgbl);
RestoreRelationTask::renewBuffer(tdgbl);
tdgbl->mvol_io_ptr = tdgbl->mvol_io_buffer;
return;
}
@ -1101,7 +1102,7 @@ void MVOL_write(BurpGlobals* tdgbl)
{
if (!tdgbl->master)
{
Firebird::BackupRelationTask::renewBuffer(tdgbl);
BackupRelationTask::renewBuffer(tdgbl);
return;
}
@ -1123,7 +1124,7 @@ UCHAR mvol_write(const UCHAR c, int* io_cnt, UCHAR** io_ptr)
if (!tdgbl->master)
{
Firebird::BackupRelationTask::renewBuffer(tdgbl);
BackupRelationTask::renewBuffer(tdgbl);
*(*io_ptr)++ = c;
(*io_cnt)--;
return c;
@ -1350,7 +1351,7 @@ const UCHAR* MVOL_write_block(BurpGlobals* tdgbl, const UCHAR* ptr, ULONG count)
{
if (!tdgbl->master)
{
Firebird::BackupRelationTask::renewBuffer(tdgbl);
BackupRelationTask::renewBuffer(tdgbl);
}
else
{

View File

@ -65,6 +65,7 @@
using MsgFormat::SafeArg;
using namespace Firebird;
using namespace Burp;
// For service APIs the follow DB handle is a value stored
@ -147,7 +148,7 @@ bool get_pub_table(BurpGlobals* tdgbl);
bool get_ref_constraint(BurpGlobals* tdgbl);
bool get_rel_constraint(BurpGlobals* tdgbl);
bool get_relation(BurpGlobals* tdgbl);
bool get_relation_data(BurpGlobals* tdgbl, Jrd::Coordinator* coord, RestoreRelationTask* task);
bool get_relation_data(BurpGlobals* tdgbl, Coordinator* coord, RestoreRelationTask* task);
bool get_sql_roles(BurpGlobals* tdgbl);
bool get_mapping(BurpGlobals* tdgbl);
bool get_db_creator(BurpGlobals* tdgbl);
@ -8479,7 +8480,7 @@ bool get_rel_constraint(BurpGlobals* tdgbl)
return true;
}
bool get_relation_data(BurpGlobals* tdgbl, Jrd::Coordinator* coord, RestoreRelationTask* task)
bool get_relation_data(BurpGlobals* tdgbl, Coordinator* coord, RestoreRelationTask* task)
{
/**************************************
*
@ -8544,9 +8545,9 @@ bool get_relation_data(BurpGlobals* tdgbl, Jrd::Coordinator* coord, RestoreRelat
else
{
task->SetRelation(tdgbl, relation);
coord->RunSync(task);
coord->runSync(task);
task->verbRecsFinal();
if (!task->GetResult(NULL))
if (!task->getResult(NULL))
BURP_exit_local(FINI_ERROR, tdgbl);
record = task->getLastRecord();
}
@ -10529,48 +10530,48 @@ rec_type ignore_data(BurpGlobals* tdgbl, burp_rel* relation)
try
{
while (true)
{
if (get(tdgbl) != att_data_length)
BURP_error_redirect(NULL, 39);
// msg 39 expected record length
USHORT len = (USHORT) get_int32(tdgbl);
if (tdgbl->gbl_sw_transportable)
while (true)
{
if (get(tdgbl) != att_xdr_length)
BURP_error_redirect(NULL, 55);
// msg 55 Expected XDR record length
else
len = (USHORT) get_int32(tdgbl);
}
if (get(tdgbl) != att_data_data)
BURP_error_redirect(NULL, 41);
// msg 41 expected data attribute
if (len)
{
if (tdgbl->gbl_sw_compress)
if (get(tdgbl) != att_data_length)
BURP_error_redirect(NULL, 39);
// msg 39 expected record length
USHORT len = (USHORT) get_int32(tdgbl);
if (tdgbl->gbl_sw_transportable)
{
UCHAR* buffer = (UCHAR*) BURP_alloc (len);
decompress (tdgbl, buffer, len);
BURP_free (buffer);
if (get(tdgbl) != att_xdr_length)
BURP_error_redirect(NULL, 55);
// msg 55 Expected XDR record length
else
len = (USHORT) get_int32(tdgbl);
}
else
get_skip(tdgbl, len);
}
++records;
if (get(tdgbl) != att_data_data)
BURP_error_redirect(NULL, 41);
// msg 41 expected data attribute
if (len)
{
if (tdgbl->gbl_sw_compress)
{
UCHAR* buffer = (UCHAR*) BURP_alloc (len);
decompress (tdgbl, buffer, len);
BURP_free (buffer);
}
else
get_skip(tdgbl, len);
}
++records;
while (get_record(&record, tdgbl))
{
if (record == rec_blob)
ignore_blob(tdgbl);
else if (record == rec_array)
ignore_array (tdgbl, relation);
else
while (get_record(&record, tdgbl))
{
if (record == rec_blob)
ignore_blob(tdgbl);
else if (record == rec_array)
ignore_array (tdgbl, relation);
else
break;
}
if (record != rec_data)
break;
}
if (record != rec_data)
break;
}
}
catch (RestoreRelationTask::ExcReadDone&)
{
@ -10940,7 +10941,7 @@ bool restore(BurpGlobals* tdgbl, Firebird::IProvider* provider, const TEXT* file
bool flag = false;
rec_type record;
Jrd::Coordinator coord(getDefaultMemoryPool());
Coordinator coord(getDefaultMemoryPool());
RestoreRelationTask task(tdgbl);
while (get_record(&record, tdgbl) != rec_end)
@ -11923,7 +11924,7 @@ void fix_system_generators(BurpGlobals* tdgbl)
} // namespace
namespace Firebird
namespace Burp
{
/// class WriteRelationMeta
@ -12978,4 +12979,4 @@ bool RestoreRelationTask::tableWriter(BurpGlobals* tdgbl, Item& item)
return true;
}
} // namespace Firebird
} // namespace Burp

View File

@ -27,9 +27,7 @@
#include "../common/Task.h"
using namespace Firebird;
namespace Jrd {
namespace Firebird {
/// class WorkerThread
@ -41,19 +39,11 @@ THREAD_ENTRY_DECLARE WorkerThread::workerThreadRoutine(THREAD_ENTRY_PARAM arg)
WorkerThread* WorkerThread::start(Coordinator* coordinator)
{
WorkerThread* thd = new WorkerThread(coordinator);
AutoPtr<WorkerThread> thd = new WorkerThread(coordinator);
try
{
Thread::start(WorkerThread::workerThreadRoutine, thd, THREAD_medium, &thd->m_thdHandle);
}
catch (const status_exception&)
{
delete thd;
throw;
}
Thread::start(WorkerThread::workerThreadRoutine, thd, THREAD_medium, &thd->m_thdHandle);
return thd;
return thd.release();
}
int WorkerThread::threadRoutine()
@ -67,7 +57,7 @@ int WorkerThread::threadRoutine()
if (m_state == RUNNING && m_worker != NULL)
{
m_worker->Work(this);
m_worker->work(this);
m_worker = NULL;
}
@ -83,7 +73,7 @@ int WorkerThread::threadRoutine()
return 0;
}
void WorkerThread::RunWorker(Worker* worker)
void WorkerThread::runWorker(Worker* worker)
{
fb_assert(m_worker == NULL);
fb_assert(m_state == IDLE);
@ -93,7 +83,7 @@ void WorkerThread::RunWorker(Worker* worker)
m_waitSem.release();
}
bool WorkerThread::WaitForState(STATE state, int timeout)
bool WorkerThread::waitForState(STATE state, int timeout)
{
while (m_state != state) // || m_state == old_state - consume old signals ?
{
@ -109,7 +99,7 @@ bool WorkerThread::WaitForState(STATE state, int timeout)
return (m_state == state);
}
void WorkerThread::Shutdown(bool wait)
void WorkerThread::shutdown(bool wait)
{
if (m_state == SHUTDOWN)
return;
@ -128,7 +118,7 @@ void WorkerThread::Shutdown(bool wait)
/// class Worker
bool Worker::Work(WorkerThread* thd)
bool Worker::work(WorkerThread* thd)
{
fb_assert(m_state == READY);
@ -140,10 +130,10 @@ bool Worker::Work(WorkerThread* thd)
if (m_thread && m_thread->getState() != WorkerThread::RUNNING)
break;
if (!m_task->GetWorkItem(&workItem))
if (!m_task->getWorkItem(&workItem))
break;
if (!m_task->Handler(*workItem))
if (!m_task->handler(*workItem))
break;
}
@ -152,7 +142,7 @@ bool Worker::Work(WorkerThread* thd)
return true;
}
bool Worker::WaitFor(int timeout)
bool Worker::waitFor(int timeout)
{
if (m_state == IDLE)
return true;
@ -160,7 +150,7 @@ bool Worker::WaitFor(int timeout)
if (m_thread == NULL)
return false;
m_thread->WaitForState(WorkerThread::IDLE, timeout);
m_thread->waitForState(WorkerThread::IDLE, timeout);
return (m_state == IDLE);
}
@ -172,14 +162,14 @@ Coordinator::~Coordinator()
MutexLockGuard guard(m_mutex, FB_FUNCTION);
for (WorkerThread** p = m_activeThreads.begin(); p < m_activeThreads.end(); p++)
(*p)->Shutdown(false);
(*p)->shutdown(false);
while (!m_activeThreads.isEmpty())
{
WorkerThread* thd = m_activeThreads.pop();
{
MutexUnlockGuard unlock(m_mutex, FB_FUNCTION);
thd->Shutdown(true);
thd->shutdown(true);
}
delete thd;
}
@ -189,7 +179,7 @@ Coordinator::~Coordinator()
WorkerThread* thd = m_idleThreads.pop();
{
MutexUnlockGuard unlock(m_mutex, FB_FUNCTION);
thd->Shutdown(true);
thd->shutdown(true);
}
delete thd;
}
@ -199,7 +189,7 @@ Coordinator::~Coordinator()
Worker* w = m_activeWorkers.back();
MutexUnlockGuard unlock(m_mutex, FB_FUNCTION);
w->WaitFor(-1);
w->waitFor(-1);
}
while (!m_idleWorkers.isEmpty())
@ -209,9 +199,9 @@ Coordinator::~Coordinator()
}
}
void Coordinator::RunSync(Task* task)
void Coordinator::runSync(Task* task)
{
int cntWorkers = setupWorkers(task->GetMaxWorkers());
int cntWorkers = setupWorkers(task->getMaxWorkers());
if (cntWorkers < 1)
return;
@ -228,14 +218,14 @@ void Coordinator::RunSync(Task* task)
Worker* w = getWorker();
taskWorkers.push(WorkerAndThd(w, thd));
w->SetTask(task);
thd->RunWorker(w);
w->setTask(task);
thd->runWorker(w);
}
}
// run syncronously
syncWorker->SetTask(task);
syncWorker->Work(NULL);
syncWorker->setTask(task);
syncWorker->work(NULL);
// wait for all workes
for (int i = 0; i < cntWorkers; i++)
@ -243,8 +233,8 @@ void Coordinator::RunSync(Task* task)
WorkerAndThd& wt = taskWorkers[i];
if (wt.thread)
{
if (!wt.worker->Idle())
wt.thread->WaitForState(WorkerThread::IDLE, -1);
if (!wt.worker->isIdle())
wt.thread->waitForState(WorkerThread::IDLE, -1);
releaseThread(wt.thread);
}
@ -301,7 +291,7 @@ WorkerThread* Coordinator::getThread()
{
thd = WorkerThread::start(this);
if (thd)
thd->WaitForState(WorkerThread::IDLE, -1);
thd->waitForState(WorkerThread::IDLE, -1);
}
if (thd)

View File

@ -25,8 +25,8 @@
*
*/
#ifndef JRD_TASK_H
#define JRD_TASK_H
#ifndef COMMON_TASK_H
#define COMMON_TASK_H
#include "firebird.h"
#include "../common/classes/alloc.h"
@ -35,10 +35,9 @@
#include "../common/classes/semaphore.h"
#include "../common/ThreadStart.h"
namespace Jrd
namespace Firebird
{
class Task;
class Worker;
class Coordinator;
class WorkerThread;
@ -66,12 +65,12 @@ public:
};
// task item handler
virtual bool Handler(WorkItem&) = 0;
virtual bool GetWorkItem(WorkItem**) = 0;
virtual bool GetResult(Firebird::IStatus* status) = 0;
virtual bool handler(WorkItem&) = 0;
virtual bool getWorkItem(WorkItem**) = 0;
virtual bool getResult(IStatus* status) = 0;
// evaluate task complexity and recommend number of parallel workers
virtual int GetMaxWorkers() { return 1; }
virtual int getMaxWorkers() { return 1; }
};
// Worker: handle work items, optionally uses separate thread
@ -88,17 +87,16 @@ public:
virtual ~Worker() {}
void SetTask(Task* task)
void setTask(Task* task)
{
m_task = task;
m_state = READY;
}
bool Work(WorkerThread* thd);
bool work(WorkerThread* thd);
//void SignalStop();
bool Idle() const { return m_state == IDLE; };
bool WaitFor(int timeout = -1);
bool isIdle() const { return m_state == IDLE; };
bool waitFor(int timeout = -1);
protected:
enum STATE {IDLE, READY, WORKING};
@ -114,7 +112,7 @@ protected:
class Coordinator
{
public:
Coordinator(Firebird::MemoryPool* pool) :
Coordinator(MemoryPool* pool) :
m_pool(pool),
m_workers(*m_pool),
m_idleWorkers(*m_pool),
@ -125,9 +123,7 @@ public:
~Coordinator();
// AddTask(Task)
void RunSync(Task*);
void runSync(Task*);
private:
struct WorkerAndThd
@ -155,14 +151,14 @@ private:
WorkerThread* getThread();
void releaseThread(WorkerThread*);
Firebird::MemoryPool* m_pool;
Firebird::Mutex m_mutex;
Firebird::HalfStaticArray<Worker*, 8> m_workers;
Firebird::HalfStaticArray<Worker*, 8> m_idleWorkers;
Firebird::HalfStaticArray<Worker*, 8> m_activeWorkers;
MemoryPool* m_pool;
Mutex m_mutex;
HalfStaticArray<Worker*, 8> m_workers;
HalfStaticArray<Worker*, 8> m_idleWorkers;
HalfStaticArray<Worker*, 8> m_activeWorkers;
// todo: move to thread pool
Firebird::HalfStaticArray<WorkerThread*, 8> m_idleThreads;
Firebird::HalfStaticArray<WorkerThread*, 8> m_activeThreads;
HalfStaticArray<WorkerThread*, 8> m_idleThreads;
HalfStaticArray<WorkerThread*, 8> m_activeThreads;
};
@ -174,7 +170,7 @@ public:
~WorkerThread()
{
Shutdown(true);
shutdown(true);
#ifdef WIN_NT
if (m_thdHandle != INVALID_HANDLE_VALUE)
@ -184,9 +180,9 @@ public:
static WorkerThread* start(Coordinator*);
void RunWorker(Worker*);
bool WaitForState(STATE state, int timeout);
void Shutdown(bool wait);
void runWorker(Worker*);
bool waitForState(STATE state, int timeout);
void shutdown(bool wait);
STATE getState() const { return m_state; }
@ -202,12 +198,12 @@ private:
Coordinator* const m_coordinator;
Worker* m_worker;
Firebird::Semaphore m_waitSem; // idle thread waits on this semaphore to start work or go out
Firebird::Semaphore m_signalSem; // semaphore is released when thread going idle
Semaphore m_waitSem; // idle thread waits on this semaphore to start work or go out
Semaphore m_signalSem; // semaphore is released when thread going idle
STATE m_state;
Thread::Handle m_thdHandle;
};
} // namespace Jrd
#endif // JRD_TASK_H
#endif // COMMON_TASK_H

View File

@ -45,9 +45,9 @@ using namespace Firebird;
namespace Jrd {
/// WrkStableAttachment
/// class WorkerStableAttachment
WrkStableAttachment::WrkStableAttachment(FbStatusVector* status, Jrd::Attachment* attachment) :
WorkerStableAttachment::WorkerStableAttachment(FbStatusVector* status, Jrd::Attachment* attachment) :
SysStableAttachment(attachment)
{
UserId user;
@ -69,12 +69,12 @@ WrkStableAttachment::WrkStableAttachment(FbStatusVector* status, Jrd::Attachment
initDone();
}
WrkStableAttachment::~WrkStableAttachment()
WorkerStableAttachment::~WorkerStableAttachment()
{
fini();
}
WrkStableAttachment* WrkStableAttachment::create(FbStatusVector* status, Jrd::Database* dbb)
WorkerStableAttachment* WorkerStableAttachment::create(FbStatusVector* status, Jrd::Database* dbb)
{
Attachment* attachment = NULL;
try
@ -83,7 +83,7 @@ WrkStableAttachment* WrkStableAttachment::create(FbStatusVector* status, Jrd::Da
attachment->att_filename = dbb->dbb_filename;
attachment->att_flags |= ATT_worker;
WrkStableAttachment* sAtt = FB_NEW WrkStableAttachment(status, attachment);
WorkerStableAttachment* sAtt = FB_NEW WorkerStableAttachment(status, attachment);
return sAtt;
}
catch (const Exception& ex)
@ -97,7 +97,7 @@ WrkStableAttachment* WrkStableAttachment::create(FbStatusVector* status, Jrd::Da
return NULL;
}
void WrkStableAttachment::fini()
void WorkerStableAttachment::fini()
{
Attachment* attachment = NULL;
{
@ -377,7 +377,7 @@ StableAttachmentPart* WorkerAttachment::doAttach(FbStatusVector* status, Databas
StableAttachmentPart* sAtt = NULL;
if (Config::getServerMode() == MODE_SUPER)
sAtt = WrkStableAttachment::create(status, dbb);
sAtt = WorkerStableAttachment::create(status, dbb);
else
{
ClumpletWriter dpb(ClumpletReader::Tagged, MAX_DPB_SIZE, isc_dpb_version1);
@ -408,7 +408,7 @@ void WorkerAttachment::doDetach(FbStatusVector* status, StableAttachmentPart* sA
// if (att->att_flags & ATT_system)
if (Config::getServerMode() == MODE_SUPER)
{
WrkStableAttachment* wrk = reinterpret_cast<WrkStableAttachment*>(sAtt);
WorkerStableAttachment* wrk = reinterpret_cast<WorkerStableAttachment*>(sAtt);
wrk->fini();
}
else

View File

@ -43,16 +43,16 @@
namespace Jrd
{
class WrkStableAttachment : public SysStableAttachment
class WorkerStableAttachment : public SysStableAttachment
{
public:
static WrkStableAttachment* create(FbStatusVector* status, Jrd::Database* dbb);
static WorkerStableAttachment* create(FbStatusVector* status, Jrd::Database* dbb);
void fini();
private:
explicit WrkStableAttachment(FbStatusVector* status, Jrd::Attachment* att);
virtual ~WrkStableAttachment();
explicit WorkerStableAttachment(FbStatusVector* status, Jrd::Attachment* att);
virtual ~WorkerStableAttachment();
};

View File

@ -4151,9 +4151,6 @@ static ULONG fast_load(thread_db* tdbb,
tdbb->tdbb_flags &= ~TDBB_no_cache_unwind;
// do some final housekeeping
//creation.sort.reset();
// If index flush fails, try to delete the index tree.
// If the index delete fails, just go ahead and punt.
try

View File

@ -276,10 +276,10 @@ public:
delete *p;
}
bool Handler(WorkItem& _item);
bool GetWorkItem(WorkItem** pItem);
bool GetResult(IStatus* status);
int GetMaxWorkers();
bool handler(WorkItem& _item);
bool getWorkItem(WorkItem** pItem);
bool getResult(IStatus* status);
int getMaxWorkers();
class Item : public Task::WorkItem
{
@ -439,7 +439,7 @@ private:
ULONG m_nextPP;
};
bool IndexCreateTask::Handler(WorkItem& _item)
bool IndexCreateTask::handler(WorkItem& _item)
{
Item* item = reinterpret_cast<Item*>(&_item);
@ -739,7 +739,7 @@ bool IndexCreateTask::Handler(WorkItem& _item)
return true;
}
bool IndexCreateTask::GetWorkItem(WorkItem** pItem)
bool IndexCreateTask::getWorkItem(WorkItem** pItem)
{
Item* item = reinterpret_cast<Item*> (*pItem);
@ -775,7 +775,7 @@ bool IndexCreateTask::GetWorkItem(WorkItem** pItem)
return item->m_inuse;
}
bool IndexCreateTask::GetResult(IStatus* status)
bool IndexCreateTask::getResult(IStatus* status)
{
if (status)
{
@ -786,7 +786,7 @@ bool IndexCreateTask::GetResult(IStatus* status)
return m_status.isSuccess();
}
int IndexCreateTask::GetMaxWorkers()
int IndexCreateTask::getMaxWorkers()
{
const int parWorkers = m_items.getCount();
if (parWorkers == 1 || m_countPP == 0)
@ -913,9 +913,9 @@ void IDX_create_index(thread_db* tdbb,
FbLocalStatus local_status;
fb_utils::init_status(&local_status);
coord.RunSync(&task);
coord.runSync(&task);
if (!task.GetResult(&local_status))
if (!task.getResult(&local_status))
local_status.raise();
}

View File

@ -319,10 +319,10 @@ public:
ULONG m_lastPP;
};
bool Handler(WorkItem& _item);
bool handler(WorkItem& _item);
bool GetWorkItem(WorkItem** pItem);
bool GetResult(IStatus* status)
bool getWorkItem(WorkItem** pItem);
bool getResult(IStatus* status)
{
if (status)
{
@ -333,7 +333,7 @@ public:
return m_status.isSuccess();
}
int GetMaxWorkers()
int getMaxWorkers()
{
return m_items.getCount();
}
@ -401,7 +401,7 @@ private:
};
bool SweepTask::Handler(WorkItem& _item)
bool SweepTask::handler(WorkItem& _item)
{
Item* item = reinterpret_cast<Item*>(&_item);
@ -501,7 +501,7 @@ bool SweepTask::Handler(WorkItem& _item)
return false;
}
bool SweepTask::GetWorkItem(WorkItem** pItem)
bool SweepTask::getWorkItem(WorkItem** pItem)
{
MutexLockGuard guard(m_mutex, FB_FUNCTION);
@ -4299,9 +4299,9 @@ bool VIO_sweep(thread_db* tdbb, jrd_tra* transaction, TraceSweepEvent* traceSwee
FbLocalStatus local_status;
local_status->init();
coord.RunSync(&sweep);
coord.runSync(&sweep);
if (!sweep.GetResult(&local_status))
if (!sweep.getResult(&local_status))
local_status.raise();
return true;