1
0
Fork 0

privatized some members

This commit is contained in:
jsteemann 2016-09-02 13:10:17 +02:00
parent 4839d65b36
commit 3909103193
6 changed files with 43 additions and 40 deletions

View File

@ -84,24 +84,20 @@ void MMFilesCleanupThread::run() {
for (auto& collection : collections) {
TRI_ASSERT(collection != nullptr);
{
READ_LOCKER(readLocker, collection->_lock);
if (collection->_collection == nullptr) {
// collection currently not loaded
continue;
auto callback = [this, &collection, &iterations]() -> void {
// we're the only ones that can unload the collection, so using
// the collection pointer outside the lock is ok
// maybe cleanup indexes, unload the collection or some datafiles
// clean indexes?
if (iterations % cleanupIndexIterations() == 0) {
collection->cleanupIndexes();
}
}
// we're the only ones that can unload the collection, so using
// the collection pointer outside the lock is ok
cleanupCollection(collection);
};
// maybe cleanup indexes, unload the collection or some datafiles
// clean indexes?
if (iterations % cleanupIndexIterations() == 0) {
collection->cleanupIndexes();
}
cleanupCollection(collection);
collection->executeWhileStatusLocked(callback);
}
}, false);

View File

@ -847,20 +847,11 @@ void MMFilesCompactorThread::run() {
bool worked;
for (auto& collection : collections) {
// Muss werden eine Lambda Function. () -> bool true wenn getan, False wenn nicht gelocked
{
TRY_READ_LOCKER(readLocker, collection->_lock);
if (!readLocker.isLocked()) {
// if we can't acquire the read lock instantly, we continue directly
// we don't want to stall here for too long
continue;
}
auto callback = [this, &collection, &worked]() -> void {
TRI_collection_t* document = collection->_collection;
if (document == nullptr) {
continue;
return;
}
worked = false;
@ -875,7 +866,7 @@ void MMFilesCompactorThread::run() {
if (!compactionLocker.isLocked()) {
// someone else is holding the compactor lock, we'll not compact
continue;
return;
}
try {
@ -911,8 +902,11 @@ void MMFilesCompactorThread::run() {
LOG_TOPIC(ERR, Logger::COMPACTOR) << "an unknown exception occurred during compaction";
}
}
};
} // end of lock
if (!collection->tryExecuteWhileStatusLocked(callback)) {
continue;
}
if (worked) {
++numCompacted;

View File

@ -2374,11 +2374,7 @@ static void JS_TypeVocbaseCol(v8::FunctionCallbackInfo<v8::Value> const& args) {
}
// fallthru intentional
TRI_col_type_e type;
{
READ_LOCKER(readLocker, collection->_lock);
type = (TRI_col_type_e)collection->type();
}
TRI_col_type_e type = collection->type();
TRI_V8_RETURN(v8::Number::New(isolate, (int)type));
TRI_V8_TRY_CATCH_END

View File

@ -603,6 +603,21 @@ TRI_vocbase_col_status_e LogicalCollection::getStatusLocked() {
READ_LOCKER(readLocker, _lock);
return _status;
}
void LogicalCollection::executeWhileStatusLocked(std::function<void()> const& callback) {
READ_LOCKER(readLocker, _lock);
callback();
}
bool LogicalCollection::tryExecuteWhileStatusLocked(std::function<void()> const& callback) {
TRY_READ_LOCKER(readLocker, _lock);
if (!readLocker.isLocked()) {
return false;
}
callback();
return true;
}
TRI_vocbase_col_status_e LogicalCollection::tryFetchStatus(bool& didFetch) {
TRY_READ_LOCKER(locker, _lock);

View File

@ -63,6 +63,8 @@ class StringRef;
class Transaction;
class LogicalCollection {
friend struct ::TRI_vocbase_t;
public:
LogicalCollection(TRI_vocbase_t*, arangodb::velocypack::Slice);
@ -75,9 +77,7 @@ class LogicalCollection {
LogicalCollection() = delete;
/// @brief hard-coded minimum version number for collections
static constexpr uint32_t minimumVersion() {
return 5;
}
static constexpr uint32_t minimumVersion() { return 5; }
/// @brief determine whether a collection name is a system collection name
static inline bool IsSystemName(std::string const& name) {
@ -136,6 +136,9 @@ class LogicalCollection {
TRI_vocbase_col_status_e status();
TRI_vocbase_col_status_e getStatusLocked();
void executeWhileStatusLocked(std::function<void()> const& callback);
bool tryExecuteWhileStatusLocked(std::function<void()> const& callback);
/// @brief try to fetch the collection status under a lock
/// the boolean value will be set to true if the lock could be acquired
/// if the boolean is false, the return value is always TRI_VOC_COL_STATUS_CORRUPTED
@ -534,10 +537,10 @@ class LogicalCollection {
public:
TRI_collection_t* _collection;
private:
mutable arangodb::basics::ReadWriteLock
_lock; // lock protecting the status and name
private:
mutable arangodb::basics::ReadWriteLock
_idxLock; // lock protecting the indexes

View File

@ -50,10 +50,9 @@ class QueryList;
class CollectionNameResolver;
class CollectionKeysRepository;
class CursorRepository;
class LogicalCollection;
class StorageEngine;
class Thread;
class LogicalCollection;
}
////////////////////////////////////////////////////////////////////////////////
@ -398,5 +397,5 @@ VPackSlice TRI_ExtractRevisionIdAsSlice(VPackSlice const slice);
/// open object which will remain open
void TRI_SanitizeObject(VPackSlice const slice, VPackBuilder& builder);
void TRI_SanitizeObjectWithEdges(VPackSlice const slice, VPackBuilder& builder);
#endif