mirror of https://gitee.com/bigwinds/arangodb
fixed random issue
This commit is contained in:
parent
85d64d0eae
commit
37dc4ae54e
|
@ -95,16 +95,17 @@ RestServerFeature::RestServerFeature(
|
|||
_jobManager(nullptr) {
|
||||
setOptional(true);
|
||||
requiresElevatedPrivileges(false);
|
||||
startsAfter("Agency");
|
||||
startsAfter("CheckVersion");
|
||||
startsAfter("Database");
|
||||
startsAfter("Dispatcher");
|
||||
startsAfter("Endpoint");
|
||||
startsAfter("FoxxQueues");
|
||||
startsAfter("LogfileManager");
|
||||
startsAfter("Random");
|
||||
startsAfter("Scheduler");
|
||||
startsAfter("Server");
|
||||
startsAfter("Agency");
|
||||
startsAfter("LogfileManager");
|
||||
startsAfter("Database");
|
||||
startsAfter("Upgrade");
|
||||
startsAfter("CheckVersion");
|
||||
startsAfter("FoxxQueues");
|
||||
}
|
||||
|
||||
void RestServerFeature::collectOptions(
|
||||
|
@ -211,8 +212,6 @@ void RestServerFeature::validateOptions(std::shared_ptr<ProgramOptions>) {
|
|||
<< RestServerFeature::_maxSecretLength;
|
||||
FATAL_ERROR_EXIT();
|
||||
}
|
||||
} else {
|
||||
generateNewJwtSecret();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,9 +267,17 @@ void RestServerFeature::generateNewJwtSecret() {
|
|||
for (size_t i = 0; i < RestServerFeature::_maxSecretLength; i++) {
|
||||
_jwtSecret += (1 + RandomGenerator::interval(m));
|
||||
}
|
||||
|
||||
LOG(ERR) << _jwtSecret;
|
||||
}
|
||||
|
||||
void RestServerFeature::prepare() { HttpHandlerFactory::setMaintenance(true); }
|
||||
void RestServerFeature::prepare() {
|
||||
if (_jwtSecret.empty()) {
|
||||
generateNewJwtSecret();
|
||||
}
|
||||
|
||||
HttpHandlerFactory::setMaintenance(true);
|
||||
}
|
||||
|
||||
void RestServerFeature::start() {
|
||||
RESTSERVER = this;
|
||||
|
@ -459,7 +466,7 @@ void RestServerFeature::defineHandlers() {
|
|||
"/_api/aql",
|
||||
RestHandlerCreator<aql::RestAqlHandler>::createData<aql::QueryRegistry*>,
|
||||
queryRegistry);
|
||||
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_api/aql-builtin",
|
||||
RestHandlerCreator<RestAqlFunctionsHandler>::createNoData);
|
||||
|
|
|
@ -57,6 +57,6 @@ void RandomFeature::collectOptions(std::shared_ptr<ProgramOptions> options) {
|
|||
generators));
|
||||
}
|
||||
|
||||
void RandomFeature::start() {
|
||||
void RandomFeature::prepare() {
|
||||
RandomGenerator::initialize((RandomGenerator::RandomType)_randomGenerator);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class RandomFeature final : public application_features::ApplicationFeature {
|
|||
|
||||
public:
|
||||
void collectOptions(std::shared_ptr<options::ProgramOptions>) override final;
|
||||
void start() override final;
|
||||
void prepare() override final;
|
||||
|
||||
public:
|
||||
uint32_t _randomGenerator;
|
||||
|
|
|
@ -23,16 +23,16 @@
|
|||
|
||||
#include "RandomGenerator.h"
|
||||
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Wincrypt.h>
|
||||
#endif
|
||||
|
||||
#include "Logger/Logger.h"
|
||||
#include "Basics/Exceptions.h"
|
||||
#include "Basics/Thread.h"
|
||||
#include "Logger/Logger.h"
|
||||
|
||||
using namespace arangodb;
|
||||
using namespace arangodb::basics;
|
||||
|
@ -471,7 +471,8 @@ void RandomGenerator::initialize(RandomType type) {
|
|||
void RandomGenerator::shutdown() { _device.reset(nullptr); }
|
||||
|
||||
int16_t RandomGenerator::interval(int16_t left, int16_t right) {
|
||||
return static_cast<int16_t>(interval(static_cast<int32_t>(left), static_cast<int32_t>(right)));
|
||||
return static_cast<int16_t>(
|
||||
interval(static_cast<int32_t>(left), static_cast<int32_t>(right)));
|
||||
}
|
||||
|
||||
int32_t RandomGenerator::interval(int32_t left, int32_t right) {
|
||||
|
@ -506,19 +507,17 @@ int64_t RandomGenerator::interval(int64_t left, int64_t right) {
|
|||
|
||||
if (dRandom < low) {
|
||||
return -1 - static_cast<int64_t>(dRandom);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return static_cast<int64_t>(dRandom - low);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
uint64_t d = high - low;
|
||||
return static_cast<int64_t>(interval(d)) + low;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t RandomGenerator::interval(uint16_t right) {
|
||||
return static_cast<uint16_t>(static_cast<uint32_t>(right));
|
||||
return static_cast<uint16_t>(interval(static_cast<uint32_t>(right)));
|
||||
}
|
||||
|
||||
uint32_t RandomGenerator::interval(uint32_t right) {
|
||||
|
@ -552,8 +551,7 @@ uint64_t RandomGenerator::interval(uint64_t right) {
|
|||
uint32_t low = static_cast<uint32_t>(right - highMax);
|
||||
uint64_t lowRandom = static_cast<uint64_t>(interval(low));
|
||||
return highRandom | lowRandom;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
uint64_t lowRandom = static_cast<uint64_t>(interval(UINT32_MAX));
|
||||
return highRandom | lowRandom;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue