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) {
|
_jobManager(nullptr) {
|
||||||
setOptional(true);
|
setOptional(true);
|
||||||
requiresElevatedPrivileges(false);
|
requiresElevatedPrivileges(false);
|
||||||
|
startsAfter("Agency");
|
||||||
|
startsAfter("CheckVersion");
|
||||||
|
startsAfter("Database");
|
||||||
startsAfter("Dispatcher");
|
startsAfter("Dispatcher");
|
||||||
startsAfter("Endpoint");
|
startsAfter("Endpoint");
|
||||||
|
startsAfter("FoxxQueues");
|
||||||
|
startsAfter("LogfileManager");
|
||||||
|
startsAfter("Random");
|
||||||
startsAfter("Scheduler");
|
startsAfter("Scheduler");
|
||||||
startsAfter("Server");
|
startsAfter("Server");
|
||||||
startsAfter("Agency");
|
|
||||||
startsAfter("LogfileManager");
|
|
||||||
startsAfter("Database");
|
|
||||||
startsAfter("Upgrade");
|
startsAfter("Upgrade");
|
||||||
startsAfter("CheckVersion");
|
|
||||||
startsAfter("FoxxQueues");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RestServerFeature::collectOptions(
|
void RestServerFeature::collectOptions(
|
||||||
|
@ -211,8 +212,6 @@ void RestServerFeature::validateOptions(std::shared_ptr<ProgramOptions>) {
|
||||||
<< RestServerFeature::_maxSecretLength;
|
<< RestServerFeature::_maxSecretLength;
|
||||||
FATAL_ERROR_EXIT();
|
FATAL_ERROR_EXIT();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
generateNewJwtSecret();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,9 +267,17 @@ void RestServerFeature::generateNewJwtSecret() {
|
||||||
for (size_t i = 0; i < RestServerFeature::_maxSecretLength; i++) {
|
for (size_t i = 0; i < RestServerFeature::_maxSecretLength; i++) {
|
||||||
_jwtSecret += (1 + RandomGenerator::interval(m));
|
_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() {
|
void RestServerFeature::start() {
|
||||||
RESTSERVER = this;
|
RESTSERVER = this;
|
||||||
|
|
|
@ -57,6 +57,6 @@ void RandomFeature::collectOptions(std::shared_ptr<ProgramOptions> options) {
|
||||||
generators));
|
generators));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RandomFeature::start() {
|
void RandomFeature::prepare() {
|
||||||
RandomGenerator::initialize((RandomGenerator::RandomType)_randomGenerator);
|
RandomGenerator::initialize((RandomGenerator::RandomType)_randomGenerator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ class RandomFeature final : public application_features::ApplicationFeature {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void collectOptions(std::shared_ptr<options::ProgramOptions>) override final;
|
void collectOptions(std::shared_ptr<options::ProgramOptions>) override final;
|
||||||
void start() override final;
|
void prepare() override final;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
uint32_t _randomGenerator;
|
uint32_t _randomGenerator;
|
||||||
|
|
|
@ -23,16 +23,16 @@
|
||||||
|
|
||||||
#include "RandomGenerator.h"
|
#include "RandomGenerator.h"
|
||||||
|
|
||||||
#include <random>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Wincrypt.h>
|
#include <Wincrypt.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Logger/Logger.h"
|
|
||||||
#include "Basics/Exceptions.h"
|
#include "Basics/Exceptions.h"
|
||||||
#include "Basics/Thread.h"
|
#include "Basics/Thread.h"
|
||||||
|
#include "Logger/Logger.h"
|
||||||
|
|
||||||
using namespace arangodb;
|
using namespace arangodb;
|
||||||
using namespace arangodb::basics;
|
using namespace arangodb::basics;
|
||||||
|
@ -471,7 +471,8 @@ void RandomGenerator::initialize(RandomType type) {
|
||||||
void RandomGenerator::shutdown() { _device.reset(nullptr); }
|
void RandomGenerator::shutdown() { _device.reset(nullptr); }
|
||||||
|
|
||||||
int16_t RandomGenerator::interval(int16_t left, int16_t right) {
|
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) {
|
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) {
|
if (dRandom < low) {
|
||||||
return -1 - static_cast<int64_t>(dRandom);
|
return -1 - static_cast<int64_t>(dRandom);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return static_cast<int64_t>(dRandom - low);
|
return static_cast<int64_t>(dRandom - low);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
uint64_t d = high - low;
|
uint64_t d = high - low;
|
||||||
return static_cast<int64_t>(interval(d)) + low;
|
return static_cast<int64_t>(interval(d)) + low;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t RandomGenerator::interval(uint16_t right) {
|
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) {
|
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);
|
uint32_t low = static_cast<uint32_t>(right - highMax);
|
||||||
uint64_t lowRandom = static_cast<uint64_t>(interval(low));
|
uint64_t lowRandom = static_cast<uint64_t>(interval(low));
|
||||||
return highRandom | lowRandom;
|
return highRandom | lowRandom;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
uint64_t lowRandom = static_cast<uint64_t>(interval(UINT32_MAX));
|
uint64_t lowRandom = static_cast<uint64_t>(interval(UINT32_MAX));
|
||||||
return highRandom | lowRandom;
|
return highRandom | lowRandom;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue