1
0
Fork 0

Merge branch 'aql2' of github.com:triAGENS/ArangoDB into aql2

This commit is contained in:
Willi Goesgens 2014-09-08 15:07:25 +02:00
commit e87e79ea77
13 changed files with 117 additions and 46 deletions

View File

@ -185,12 +185,17 @@ AqlItemBlock* AqlItemBlock::slice (size_t from,
auto it = cache.find(a); auto it = cache.find(a);
if (it == cache.end()) { if (it == cache.end()) {
AqlValue b = a.clone(); AqlValue b = a.clone();
res->_data[(row - from) * _nrRegs + col] = b; try {
// TODO: can we use emplace() here instead of insert()? res->setValue(row - from, col, b);
cache.insert(make_pair(a, b)); }
catch (...) {
b.destroy();
throw;
}
cache.emplace(a, b);
} }
else { else {
res->_data[(row - from) * _nrRegs + col] = it->second; res->setValue(row - from, col, it->second);
} }
} }
} }
@ -232,12 +237,16 @@ AqlItemBlock* AqlItemBlock::slice (std::vector<size_t>& chosen,
auto it = cache.find(a); auto it = cache.find(a);
if (it == cache.end()) { if (it == cache.end()) {
AqlValue b = a.clone(); AqlValue b = a.clone();
res->_data[(row - from) * _nrRegs + col] = b; try {
// TODO: can we use emplace() here instead of insert()? res->setValue(row - from, col, b);
cache.insert(make_pair(a, b)); }
catch (...) {
b.destroy();
}
cache.emplace(a, b);
} }
else { else {
res->_data[(row - from) * _nrRegs + col] = it->second; res->setValue(row - from, col, it->second);
} }
} }
} }

View File

@ -66,7 +66,7 @@ V8PeriodicTask::V8PeriodicTask (string const& id,
_parameters(parameters), _parameters(parameters),
_created(TRI_microtime()) { _created(TRI_microtime()) {
TRI_ASSERT(vocbase != 0); TRI_ASSERT(vocbase != nullptr);
// increase reference counter for the database used // increase reference counter for the database used
TRI_UseVocBase(_vocbase); TRI_UseVocBase(_vocbase);
@ -80,7 +80,7 @@ V8PeriodicTask::~V8PeriodicTask () {
// decrease reference counter for the database used // decrease reference counter for the database used
TRI_ReleaseVocBase(_vocbase); TRI_ReleaseVocBase(_vocbase);
if (_parameters != 0) { if (_parameters != nullptr) {
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, _parameters); TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, _parameters);
} }
} }

View File

@ -117,7 +117,10 @@ bool V8TimerTask::handleTimeout () {
"(function (params) { " + _command + " } )(params);", "(function (params) { " + _command + " } )(params);",
_parameters); _parameters);
_dispatcher->addJob(job); if (_dispatcher->addJob(job) != TRI_ERROR_NO_ERROR) {
// just in case the dispatcher cannot accept the job (e.g. when shutting down)
delete job;
}
// note: this will destroy the task (i.e. ourselves!!) // note: this will destroy the task (i.e. ourselves!!)
_scheduler->destroyTask(this); _scheduler->destroyTask(this);

View File

@ -110,7 +110,7 @@ static DispatcherThread* CreateV8DispatcherThread (DispatcherQueue* queue, void*
static v8::Handle<v8::Value> JS_RegisterTask (v8::Arguments const& argv) { static v8::Handle<v8::Value> JS_RegisterTask (v8::Arguments const& argv) {
v8::HandleScope scope; v8::HandleScope scope;
if (GlobalScheduler == 0 || GlobalDispatcher == 0) { if (GlobalScheduler == nullptr || GlobalDispatcher == nullptr) {
TRI_V8_EXCEPTION_MESSAGE(scope, TRI_ERROR_INTERNAL, "no scheduler found"); TRI_V8_EXCEPTION_MESSAGE(scope, TRI_ERROR_INTERNAL, "no scheduler found");
} }
@ -335,7 +335,7 @@ static v8::Handle<v8::Value> JS_GetTask (v8::Arguments const& argv) {
static v8::Handle<v8::Value> JS_CreateNamedQueue (v8::Arguments const& argv) { static v8::Handle<v8::Value> JS_CreateNamedQueue (v8::Arguments const& argv) {
v8::HandleScope scope; v8::HandleScope scope;
if (GlobalDispatcher == 0) { if (GlobalDispatcher == nullptr) {
TRI_V8_EXCEPTION_MESSAGE(scope, TRI_ERROR_INTERNAL, "no dispatcher found"); TRI_V8_EXCEPTION_MESSAGE(scope, TRI_ERROR_INTERNAL, "no dispatcher found");
} }

View File

@ -172,22 +172,16 @@ static inline uint64_t TRI_DecModU64(uint64_t i, uint64_t len) {
return len-1; return len-1;
} }
// The following two possibilities are equivalent, but seem to produce ////////////////////////////////////////////////////////////////////////////////
// a branch instruction in the assembler code rather than a conditional move: /// @brief fake spinlocks
/// spin locks seem to have issues when used under Valgrind
/// we thus mimic spinlocks using ordinary mutexes when in maintainer mode
////////////////////////////////////////////////////////////////////////////////
#if 0 #ifdef TRI_ENABLE_MAINTAINER_MODE
static inline uint64_t TRI_IncModU64(uint64_t i, uint64_t len) { #define TRI_FAKE_SPIN_LOCKS 1
if ((++i) == len) { #else
return 0; #undef TRI_FAKE_SPIN_LOCKS
}
return i;
}
#endif
#if 0
static inline uint64_t TRI_IncModU64(uint64_t i, uint64_t len) {
return (++i) == len ? 0 : i;
}
#endif #endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -48,8 +48,16 @@ extern "C" {
/// @brief spin-lock type /// @brief spin-lock type
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifdef TRI_FAKE_SPIN_LOCKS
#define TRI_spin_t phread_mutex_t
#else
#define TRI_spin_t OSSpinLock #define TRI_spin_t OSSpinLock
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -114,6 +114,8 @@ void TRI_UnlockMutex (TRI_mutex_t* mutex) {
// --SECTION-- SPIN // --SECTION-- SPIN
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef TRI_FAKE_SPIN_LOCKS
#ifdef TRI_HAVE_POSIX_SPIN #ifdef TRI_HAVE_POSIX_SPIN
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -179,6 +181,8 @@ void TRI_UnlockSpin (TRI_spin_t* spinLock) {
#endif #endif
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- READ-WRITE LOCK // --SECTION-- READ-WRITE LOCK
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -54,10 +54,18 @@ extern "C" {
/// @brief spin-lock type /// @brief spin-lock type
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifdef TRI_FAKE_SPIN_LOCKS
#define TRI_spin_t pthread_mutex_t
#else
#ifdef TRI_HAVE_POSIX_SPIN #ifdef TRI_HAVE_POSIX_SPIN
#define TRI_spin_t pthread_spinlock_t #define TRI_spin_t pthread_spinlock_t
#endif #endif
#endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief read-write-lock type /// @brief read-write-lock type
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -55,8 +55,16 @@ TRI_mutex_t;
/// @brief spin-lock type /// @brief spin-lock type
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifdef TRI_FAKE_SPIN_LOCKS
#define TRI_spin_t phread_mutex_t
#else
#define TRI_spin_t CRITICAL_SECTION #define TRI_spin_t CRITICAL_SECTION
#endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief read-write-lock type /// @brief read-write-lock type
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -121,13 +121,21 @@ void TRI_UnlockMutex (TRI_mutex_t*);
/// @brief initialises a new spin-lock /// @brief initialises a new spin-lock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifdef TRI_FAKE_SPIN_LOCKS
#define TRI_InitSpin TRI_InitMutex
#else
void TRI_InitSpin (TRI_spin_t* spin); void TRI_InitSpin (TRI_spin_t* spin);
#endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief destroyes a spin-lock /// @brief destroyes a spin-lock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifdef TRI_FAKE_SPIN_LOCKS
#define TRI_DestroySpin TRI_DestroyMutex
#else
void TRI_DestroySpin (TRI_spin_t* spin); void TRI_DestroySpin (TRI_spin_t* spin);
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- public functions // --SECTION-- public functions
@ -137,13 +145,21 @@ void TRI_DestroySpin (TRI_spin_t* spin);
/// @brief locks spin-lock /// @brief locks spin-lock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifdef TRI_FAKE_SPIN_LOCKS
#define TRI_LockSpin TRI_LockMutex
#else
void TRI_LockSpin (TRI_spin_t* spin); void TRI_LockSpin (TRI_spin_t* spin);
#endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief unlocks spin-lock /// @brief unlocks spin-lock
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifdef TRI_FAKE_SPIN_LOCKS
#define TRI_UnlockSpin TRI_UnlockMutex
#else
void TRI_UnlockSpin (TRI_spin_t* spin); void TRI_UnlockSpin (TRI_spin_t* spin);
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- READ-WRITE LOCK // --SECTION-- READ-WRITE LOCK

View File

@ -85,9 +85,9 @@ namespace {
ApplicationDispatcher::ApplicationDispatcher () ApplicationDispatcher::ApplicationDispatcher ()
: ApplicationFeature("dispatcher"), : ApplicationFeature("dispatcher"),
_applicationScheduler(0), _applicationScheduler(nullptr),
_dispatcher(0), _dispatcher(nullptr),
_dispatcherReporterTask(0), _dispatcherReporterTask(nullptr),
_reportInterval(0.0) { _reportInterval(0.0) {
} }
@ -96,7 +96,7 @@ ApplicationDispatcher::ApplicationDispatcher ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ApplicationDispatcher::~ApplicationDispatcher () { ApplicationDispatcher::~ApplicationDispatcher () {
if (_dispatcher != 0) { if (_dispatcher != nullptr) {
delete _dispatcher; delete _dispatcher;
} }
} }
@ -127,13 +127,13 @@ Dispatcher* ApplicationDispatcher::dispatcher () const {
void ApplicationDispatcher::buildStandardQueue (size_t nrThreads, void ApplicationDispatcher::buildStandardQueue (size_t nrThreads,
size_t maxSize) { size_t maxSize) {
if (_dispatcher == 0) { if (_dispatcher == nullptr) {
LOG_FATAL_AND_EXIT("no dispatcher is known, cannot create dispatcher queue"); LOG_FATAL_AND_EXIT("no dispatcher is known, cannot create dispatcher queue");
} }
LOG_TRACE("setting up a standard queue with %d threads", (int) nrThreads); LOG_TRACE("setting up a standard queue with %d threads", (int) nrThreads);
TRI_ASSERT(_dispatcher != 0); TRI_ASSERT(_dispatcher != nullptr);
_dispatcher->addStandardQueue(nrThreads, maxSize); _dispatcher->addStandardQueue(nrThreads, maxSize);
} }
@ -200,7 +200,7 @@ bool ApplicationDispatcher::open () {
return true; return true;
} }
if (_dispatcher != 0) { if (_dispatcher != nullptr) {
return _dispatcher->open(); return _dispatcher->open();
} }
@ -216,7 +216,7 @@ void ApplicationDispatcher::close () {
return; return;
} }
if (_dispatcher != 0) { if (_dispatcher != nullptr) {
_dispatcher->beginShutdown(); _dispatcher->beginShutdown();
} }
} }
@ -230,11 +230,11 @@ void ApplicationDispatcher::stop () {
return; return;
} }
if (_dispatcherReporterTask != 0) { if (_dispatcherReporterTask != nullptr) {
_dispatcherReporterTask = 0; _dispatcherReporterTask = nullptr;
} }
if (_dispatcher != 0) { if (_dispatcher != nullptr) {
static size_t const MAX_TRIES = 50; // 10 seconds (50 * 200 ms) static size_t const MAX_TRIES = 50; // 10 seconds (50 * 200 ms)
for (size_t count = 0; count < MAX_TRIES && _dispatcher->isRunning(); ++count) { for (size_t count = 0; count < MAX_TRIES && _dispatcher->isRunning(); ++count) {
@ -245,7 +245,7 @@ void ApplicationDispatcher::stop () {
_dispatcher->shutdown(); _dispatcher->shutdown();
delete _dispatcher; delete _dispatcher;
_dispatcher = 0; _dispatcher = nullptr;
} }
} }
@ -258,7 +258,7 @@ void ApplicationDispatcher::stop () {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ApplicationDispatcher::buildDispatcher (Scheduler* scheduler) { void ApplicationDispatcher::buildDispatcher (Scheduler* scheduler) {
if (_dispatcher != 0) { if (_dispatcher != nullptr) {
LOG_FATAL_AND_EXIT("a dispatcher has already been created"); LOG_FATAL_AND_EXIT("a dispatcher has already been created");
} }
@ -270,7 +270,7 @@ void ApplicationDispatcher::buildDispatcher (Scheduler* scheduler) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ApplicationDispatcher::buildDispatcherReporter () { void ApplicationDispatcher::buildDispatcherReporter () {
if (_dispatcher == 0) { if (_dispatcher == nullptr) {
LOG_FATAL_AND_EXIT("no dispatcher is known, cannot create dispatcher reporter"); LOG_FATAL_AND_EXIT("no dispatcher is known, cannot create dispatcher reporter");
} }

View File

@ -175,10 +175,10 @@ int Dispatcher::addJob (Job* job) {
} }
// try to find a suitable queue // try to find a suitable queue
const string& name = job->queue(); string const& name = job->queue();
DispatcherQueue* queue = lookupQueue(name); DispatcherQueue* queue = lookupQueue(name);
if (queue == 0) { if (queue == nullptr) {
LOG_WARNING("unknown queue '%s'", name.c_str()); LOG_WARNING("unknown queue '%s'", name.c_str());
return TRI_ERROR_QUEUE_UNKNOWN; return TRI_ERROR_QUEUE_UNKNOWN;
} }
@ -201,10 +201,10 @@ int Dispatcher::addJob (Job* job) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Dispatcher::cancelJob (uint64_t jobId) { bool Dispatcher::cancelJob (uint64_t jobId) {
MUTEX_LOCKER(_accessDispatcher);
bool done = false; bool done = false;
MUTEX_LOCKER(_accessDispatcher);
for (map<string, DispatcherQueue*>::iterator i = _queues.begin(); i != _queues.end() && ! done; ++i) { for (map<string, DispatcherQueue*>::iterator i = _queues.begin(); i != _queues.end() && ! done; ++i) {
DispatcherQueue* q = i->second; DispatcherQueue* q = i->second;

View File

@ -225,6 +225,27 @@ void DispatcherQueue::beginShutdown () {
_stopping = 1; _stopping = 1;
// kill all jobs in the queue that were not yet executed
{
CONDITION_LOCKER(guard, _accessQueue);
for (auto it = _readyJobs.begin(); it != _readyJobs.end(); ++it) {
Job* job = *it;
bool canceled = job->cancel(false);
if (canceled) {
try {
job->setDispatcherThread(0);
job->cleanup();
}
catch (...) {
}
}
}
_readyJobs.clear();
}
for (size_t count = 0; count < MAX_TRIES; ++count) { for (size_t count = 0; count < MAX_TRIES; ++count) {
{ {
CONDITION_LOCKER(guard, _accessQueue); CONDITION_LOCKER(guard, _accessQueue);