1
0
Fork 0

fix assertion

This commit is contained in:
Jan Steemann 2016-09-13 17:00:56 +02:00
parent 55ae5b4bb6
commit b5ccbd1cb6
2 changed files with 25 additions and 4 deletions

View File

@ -135,7 +135,7 @@ SlotInfo Slots::nextUnused(TRI_voc_tick_t databaseId, TRI_voc_cid_t collectionId
uint32_t alignedSize = DatafileHelper::AlignedSize<uint32_t>(size); uint32_t alignedSize = DatafileHelper::AlignedSize<uint32_t>(size);
int iterations = 0; int iterations = 0;
bool hasWaited = false; bool hasWaited = false;
bool mustWritePrologue = false; bool mustWritePrologue = false;
TRI_ASSERT(size > 0); TRI_ASSERT(size > 0);
@ -146,7 +146,13 @@ SlotInfo Slots::nextUnused(TRI_voc_tick_t databaseId, TRI_voc_cid_t collectionId
Slot* slot = &_slots[_handoutIndex]; Slot* slot = &_slots[_handoutIndex];
TRI_ASSERT(slot != nullptr); TRI_ASSERT(slot != nullptr);
if (slot->isUnused()) { // check if next slot is free for writing
// and also is the slot following it is also free for writing
// this is required because in some cases we need two free slots
// to write a WAL entry: the first slot for the prologue marker
// and the second slot for the actual marker
if (slot->isUnused() &&
_slots[nextHandoutIndex()].isUnused()) {
if (hasWaited) { if (hasWaited) {
CONDITION_LOCKER(guard, _condition); CONDITION_LOCKER(guard, _condition);
TRI_ASSERT(_waiting > 0); TRI_ASSERT(_waiting > 0);
@ -275,13 +281,14 @@ SlotInfo Slots::nextUnused(TRI_voc_tick_t databaseId, TRI_voc_cid_t collectionId
CONDITION_LOCKER(guard, _condition); CONDITION_LOCKER(guard, _condition);
if (!hasWaited) { if (!hasWaited) {
++_waiting; ++_waiting;
_logfileManager->signalSync(true);
hasWaited = true; hasWaited = true;
} }
bool mustWait; bool mustWait;
{ {
MUTEX_LOCKER(mutexLocker, _lock); MUTEX_LOCKER(mutexLocker, _lock);
mustWait = (_freeSlots == 0); mustWait = (_freeSlots < 2);
} }
if (mustWait) { if (mustWait) {
@ -581,7 +588,7 @@ int Slots::closeLogfile(Slot::TickType& lastCommittedTick, bool& worked) {
bool mustWait; bool mustWait;
{ {
MUTEX_LOCKER(mutexLocker, _lock); MUTEX_LOCKER(mutexLocker, _lock);
mustWait = (_freeSlots == 0); mustWait = (_freeSlots < 2);
} }
if (mustWait) { if (mustWait) {
@ -667,6 +674,16 @@ Slot::TickType Slots::handout() {
return _lastAssignedTick; return _lastAssignedTick;
} }
/// @brief return the next slots that would be handed out, without
/// actually handing it out
size_t Slots::nextHandoutIndex() const {
size_t handoutIndex = _handoutIndex;
if (++handoutIndex == _numberOfSlots) {
handoutIndex = 0;
}
return handoutIndex;
}
/// @brief wait until all data has been synced up to a certain marker /// @brief wait until all data has been synced up to a certain marker
bool Slots::waitForTick(Slot::TickType tick) { bool Slots::waitForTick(Slot::TickType tick) {
static uint64_t const SleepTime = 10000; static uint64_t const SleepTime = 10000;

View File

@ -137,6 +137,10 @@ class Slots {
/// @brief handout a region and advance the handout index /// @brief handout a region and advance the handout index
Slot::TickType handout(); Slot::TickType handout();
/// @brief return the next slots that would be handed out, without
/// actually handing it out
size_t nextHandoutIndex() const;
/// @brief wait until all data has been synced up to a certain marker /// @brief wait until all data has been synced up to a certain marker
bool waitForTick(Slot::TickType); bool waitForTick(Slot::TickType);