1
0
Fork 0

fixed race in synchronizer

This commit is contained in:
Jan Steemann 2014-10-13 15:41:22 +02:00
parent d151088a94
commit 69e9d12955
6 changed files with 49 additions and 17 deletions

View File

@ -66,13 +66,13 @@ namespace triagens {
////////////////////////////////////////////////////////////////////////////////
enum class StatusType : uint32_t {
UNKNOWN,
EMPTY,
OPEN,
SEAL_REQUESTED,
SEALED,
COLLECTION_REQUESTED,
COLLECTED
UNKNOWN = 0,
EMPTY = 1,
OPEN = 2,
SEAL_REQUESTED = 3,
SEALED = 4,
COLLECTION_REQUESTED = 5,
COLLECTED = 6
};
// -----------------------------------------------------------------------------

View File

@ -1182,6 +1182,25 @@ Logfile* LogfileManager::getLogfile (Logfile::IdType id) {
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get a logfile and its status by id
////////////////////////////////////////////////////////////////////////////////
Logfile* LogfileManager::getLogfile (Logfile::IdType id,
Logfile::StatusType& status) {
READ_LOCKER(_logfilesLock);
auto it = _logfiles.find(id);
if (it != _logfiles.end()) {
status = (*it).second->status();
return (*it).second;
}
status = Logfile::StatusType::UNKNOWN;
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get a logfile for writing. this may return nullptr
////////////////////////////////////////////////////////////////////////////////

View File

@ -574,6 +574,13 @@ namespace triagens {
Logfile* getLogfile (Logfile::IdType);
////////////////////////////////////////////////////////////////////////////////
/// @brief get a logfile and its status by id
////////////////////////////////////////////////////////////////////////////////
Logfile* getLogfile (Logfile::IdType,
Logfile::StatusType&);
////////////////////////////////////////////////////////////////////////////////
/// @brief get a logfile for writing. this may return nullptr
////////////////////////////////////////////////////////////////////////////////

View File

@ -421,10 +421,14 @@ SyncRegion Slots::getSyncRegion () {
if (region.logfileId == 0) {
// first member
Logfile::StatusType status;
region.logfileId = slot->logfileId();
region.logfile = _logfileManager->getLogfile(slot->logfileId());
// the following call also updates status
region.logfile = _logfileManager->getLogfile(slot->logfileId(), status);
region.mem = static_cast<char*>(slot->mem());
region.size = slot->size();
region.logfileStatus = status;
region.firstSlotIndex = slotIndex;
region.lastSlotIndex = slotIndex;
region.waitForSync = slot->waitForSync();

View File

@ -43,6 +43,7 @@ namespace triagens {
logfile(nullptr),
mem(nullptr),
size(0),
logfileStatus(Logfile::StatusType::UNKNOWN),
firstSlotIndex(0),
lastSlotIndex(0),
waitForSync(false),
@ -52,14 +53,15 @@ namespace triagens {
~SyncRegion () {
}
Logfile::IdType logfileId;
Logfile* logfile;
char* mem;
uint32_t size;
size_t firstSlotIndex;
size_t lastSlotIndex;
bool waitForSync;
bool checkMore;
Logfile::IdType logfileId;
Logfile* logfile;
char* mem;
uint32_t size;
Logfile::StatusType logfileStatus;
size_t firstSlotIndex;
size_t lastSlotIndex;
bool waitForSync;
bool checkMore;
};
}

View File

@ -191,7 +191,7 @@ int SynchroniserThread::doSync (bool& checkMore) {
}
// now perform the actual syncing
Logfile::StatusType status = _logfileManager->getLogfileStatus(id);
auto status = region.logfileStatus;
TRI_ASSERT(status == Logfile::StatusType::OPEN || status == Logfile::StatusType::SEAL_REQUESTED);
// get the logfile's file descriptor