8000 fix dropping of system collections and retrieving list of user databa… · MohammedDeveloper/arangodb@b4e5132 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit b4e5132

Browse files
jsteemannfceller
authored andcommitted
fix dropping of system collections and retrieving list of user databa… (arangodb#3304)
* fix dropping of system collections and retrieving list of user databases in cluster * fix MSVC compile warnings
1 parent fbfd349 commit b4e5132

File tree

10 files changed

+66
-36
lines changed

10 files changed

+66
-36
lines changed

arangod/MMFiles/MMFilesCompactionFeature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ MMFilesCompactionFeature* MMFilesCompactionFeature::COMPACTOR = nullptr;
3939

4040
MMFilesCompactionFeature::MMFilesCompactionFeature(ApplicationServer* server)
4141
: ApplicationFeature(server, "MMFilesCompaction"),
42-
_compactionSleepTime(1),
42+
_compactionSleepTime(1.0),
4343
_compactionCollectionInterval(10.0),
4444
_maxFiles(3),
4545
_maxSizeFactor(3),
@@ -59,7 +59,7 @@ void MMFilesCompactionFeature::collectOptions(std::shared_ptr<options::ProgramOp
5959
options->addSection("compaction", "Configure the MMFiles compactor thread");
6060

6161
options->addOption("--compaction.db-sleep-time", "sleep interval between two compaction runs (in s)",
62-
new UInt64Parameter(&_compactionSleepTime));
62+
new DoubleParameter(&_compactionSleepTime));
6363

6464
options->addOption("--compaction.min-interval", "minimum sleep time between two compaction runs (in s)",
6565
new DoubleParameter(&_compactionCollectionInterval));

arangod/MMFiles/MMFilesCompactionFeature.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class MMFilesCompactionFeature : public application_features::ApplicationFeature
3636
static MMFilesCompactionFeature* COMPACTOR;
3737
private:
3838
/// @brief wait time between compaction runs when idle
39-
uint64_t _compactionSleepTime;
39+
double _compactionSleepTime;
4040

4141
/// @brief compaction interval in seconds
4242
double _compactionCollectionInterval;
@@ -79,20 +79,20 @@ class MMFilesCompactionFeature : public application_features::ApplicationFeature
7979
~MMFilesCompactionFeature() {}
8080

8181
/// @brief wait time between compaction runs when idle
82-
unsigned compactionSleepTime() const { return _compactionSleepTime * 1000000; }
82+
uint64_t compactionSleepTime() const { return static_cast<uint64_t>(_compactionSleepTime) * 1000000ULL; }
8383

8484
/// @brief compaction interval in seconds
8585
double compactionCollectionInterval() const { return _compactionCollectionInterval; }
8686

8787
/// @brief maximum number of files to compact and concat
88-
unsigned maxFiles() const { return _maxFiles; }
88+
size_t maxFiles() const { return static_cast<size_t>(_maxFiles); }
8989

9090
/// @brief maximum multiple of journal filesize of a compacted file
9191
/// a value of 3 means that the maximum filesize of the compacted file is
9292
/// 3 x (collection->journalSize)
93-
unsigned maxSizeFactor() const { return _maxSizeFactor; }
93+
uint64_t maxSizeFactor() const { return _maxSizeFactor; }
9494

95-
unsigned smallDatafileSize() const { return _smallDatafileSize; }
95+
uint64_t smallDatafileSize() const { return _smallDatafileSize; }
9696

9797
/// @brief maximum filesize of resulting compacted file
9898
uint64_t maxResultFilesize() const { return _maxResultFilesize; }

arangod/RestServer/DatabaseFeature.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,31 @@ std::vector<TRI_voc_tick_t> DatabaseFeature::getDatabaseIds(
827827
return ids;
828828
}
829829

830+
/// @brief return the list of all database names
831+
std::vector<std::string> DatabaseFeature::getDatabaseNamesCoordinator() {
832+
std::vector<std::string> names;
833+
834+
{
835+
auto unuser(_databasesProtector.use());
836+
auto theLists = _databasesLists.load();
837+
838+
for (auto& p : theLists->_coordinatorDatabases) {
839+
TRI_vocbase_t* vocbase = p.second;
840+
TRI_ASSERT(vocbase != nullptr);
841+
if (vocbase->isDropped()) {
842+
continue;
843+
}
844+
names.emplace_back(vocbase->name());
845+
}
846+
}
847+
848+
std::sort(
849+
names.begin(), names.end(),
850+
[](std::string const& l, std::string const& r) -> bool { return l < r; });
851+
852+
return names;
853+
}
854+
830855
/// @brief return the list of all database names
831856
std::vector<std::string> DatabaseFeature::getDatabaseNames() {
832857
std::vector<std::string> names;

arangod/RestServer/DatabaseFeature.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class DatabaseFeature final : public application_features::ApplicationFeature {
8888
std::vector<TRI_voc_tick_t> getDatabaseIdsCoordinator(bool includeSystem);
8989
std::vector<TRI_voc_tick_t> getDatabaseIds(bool includeSystem);
9090
std::vector<std::string> getDatabaseNames();
91+
std::vector<std::string> getDatabaseNamesCoordinator();
9192
std::vector<std::string> getDatabaseNamesForUser(std::string const& user);
9293

9394
int createDatabaseCoordinator(TRI_voc_tick_t id, std::string const& name, TRI_vocbase_t*& result);

arangod/RocksDBEngine/RocksDBPrimaryIndex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void RocksDBPrimaryIndex::load() {
141141
RocksDBCollection* rdb = static_cast<RocksDBCollection*>(_collection->getPhysical());
142142
uint64_t numDocs = rdb->numberDocuments();
143143
if (numDocs > 0) {
144-
_cache->sizeHint(static_cast<double>(0.3 * numDocs));
144+
_cache->sizeHint(static_cast<uint64_t>(0.3 * numDocs));
145145
}
146146
}
147147
}

arangod/RocksDBEngine/RocksDBVPackIndex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ int RocksDBVPackIndex::fillElement(VPackBuilder& leased, TRI_voc_rid_t revId,
363363
buildIndexValues(leased, revId, doc, 0, elements, sliceStack, hashes);
364364
} catch (arangodb::basics::Exception const& ex) {
365365
return ex.code();
366-
} catch (std::bad_alloc const& ex) {
366+
} catch (std::bad_alloc const&) {
367367
return TRI_ERROR_OUT_OF_MEMORY;
368368
} catch (...) {
369369
// unknown error

arangod/V8Server/v8-collection.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -938,11 +938,12 @@ static int ULVocbaseColCoordinator(std::string const& databaseName,
938938

939939
static void DropVocbaseColCoordinator(
940940
v8::FunctionCallbackInfo<v8::Value> const& args,
941-
arangodb::LogicalCollection* collection) {
941+
arangodb::LogicalCollection* collection,
942+
bool allowDropSystem) {
942943
// cppcheck-suppress *
943944
v8::Isolate* isolate = args.GetIsolate();
944945

945-
if (collection->isSystem()) {
946+
if (collection->isSystem() && !allowDropSystem) {
946947
TRI_V8_THROW_EXCEPTION(TRI_ERROR_FORBIDDEN);
947948
}
948949

@@ -995,35 +996,35 @@ static void JS_DropVocbaseCol(v8::FunctionCallbackInfo<v8::Value> const& args) {
995996

996997
std::string const dbname = collection->dbName();
997998
std::string const collName = collection->name();
999+
1000+
bool allowDropSystem = false;
1001+
double timeout = -1.0; // forever, unless specified otherwise
1002+
if (args.Length() > 0) {
1003+
// options
1004+
if (args[0]->IsObject()) {
1005+
TRI_GET_GLOBALS();
1006+
v8::Handle<v8::Object> optionsObject = args[0].As<v8::Object>();
1007+
TRI_GET_GLOBAL_STRING(IsSystemKey);
1008+
if (optionsObject->Has(IsSystemKey)) {
1009+
allowDropSystem = TRI_ObjectToBoolean(optionsObject->Get(IsSystemKey));
1010+
}
1011+
TRI_GET_GLOBAL_STRING(TimeoutKey);
1012+
if (optionsObject->Has(TimeoutKey)) {
1013+
timeout = TRI_ObjectToDouble(optionsObject->Get(TimeoutKey));
1014+
}
1015+
} else {
1016+
allowDropSystem = TRI_ObjectToBoolean(args[0]);
1017+
}
1018+
}
9981019

9991020
// If we are a coordinator in a cluster, we have to behave differently:
10001021
if (ServerState::instance()->isCoordinator()) {
10011022
#ifdef USE_ENTERPRISE
1002-
DropVocbaseColCoordinatorEnterprise(args, collection);
1023+
DropVocbaseColCoordinatorEnterprise(args, collection, allowDropSystem);
10031024
#else
1004-
DropVocbaseColCoordinator(args, collection);
1025+
DropVocbaseColCoordinator(args, collection, allowDropSystem);
10051026
#endif
10061027
} else {
1007-
bool allowDropSystem = false;
1008-
double timeout = -1.0; // forever, unless specified otherwise
1009-
if (args.Length() > 0) {
1010-
// options
1011-
if (args[0]->IsObject()) {
1012-
TRI_GET_GLOBALS();
1013-
v8::Handle<v8::Object> optionsObject = args[0].As<v8::Object>();
1014-
TRI_GET_GLOBAL_STRING(IsSystemKey);
1015-
if (optionsObject->Has(IsSystemKey)) {
1016-
allowDropSystem = TRI_ObjectToBoolean(optionsObject->Get(IsSystemKey));
1017-
}
1018-
TRI_GET_GLOBAL_STRING(TimeoutKey);
1019-
if (optionsObject->Has(TimeoutKey)) {
1020-
timeout = TRI_ObjectToDouble(optionsObject->Get(TimeoutKey));
1021-
}
1022-
} else {
1023-
allowDropSystem = TRI_ObjectToBoolean(args[0]);
1024-
}
1025-
}
1026-
10271028
int res = collection->vocbase()->dropCollection(collection, allowDropSystem, timeout);
10281029
if (res != TRI_ERROR_NO_ERROR) {
10291030
TRI_V8_THROW_EXCEPTION_MESSAGE(res, "cannot drop collection");

arangod/V8Server/v8-collection.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ void TRI_InitV8Collections(v8::Handle<v8::Context> context,
6565
#ifdef USE_ENTERPRISE
6666
void DropVocbaseColCoordinatorEnterprise(
6767
v8::FunctionCallbackInfo<v8::Value> const& args,
68-
arangodb::LogicalCollection* collection);
68+
arangodb::LogicalCollection* collection,
69+
bool allowDropSystem);
6970

7071
int ULVocbaseColCoordinatorEnterprise(std::string const& databaseName,
7172
std::string const& collectionCID,

arangod/VocBase/AuthInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ bool AuthInfo::parseUsers(VPackSlice const& slice) {
109109
// otherwise all following update/replace/remove operations on the
110110
// user will fail
111111

112-
_authInfo.emplace(auth.username(), std::move(auth));
112+
// intentional copy, as we'll be moving out of auth soon
113+
std::string username = auth.username();
114+
_authInfo.emplace(std::move(username), std::move(auth));
113115
}
114116

115117
return true;

arangod/VocBase/Methods/Databases.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ std::vector<std::string> Databases::list(std::string const& user) {
8181
if (ServerState::instance()->isCoordinator()) {
8282
auto auth = FeatureCacheFeature::instance()->authenticationFeature();
8383
std::vector<std::string> names;
84-
std::vector<std::string> dbs = databaseFeature->getDatabaseNames();
84+
std::vector<std::string> dbs = databaseFeature->getDatabaseNamesCoordinator();
8585
for (std::string const& db : dbs) {
8686
if (auth->canUseDatabase(user, db) != AuthLevel::NONE) {
8787
names.push_back(db);

0 commit comments

Comments
 (0)
0