mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of github.com:arangodb/arangodb into devel
This commit is contained in:
commit
2212be29c0
|
@ -16,4 +16,8 @@ configuration of an ArangoDB database's replication applier.
|
|||
@startDocuBlock JSF_put_api_replication_applier_stop
|
||||
|
||||
<!-- arangod/RestHandler/RestReplicationHandler.cpp -->
|
||||
@startDocuBlock JSF_get_api_replication_applier_state
|
||||
@startDocuBlock JSF_get_api_replication_applier_state
|
||||
|
||||
<!-- arangod/RestHandler/RestReplicationHandler.cpp -->
|
||||
@startDocuBlock JSF_put_api_replication_makeSlave
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "Basics/JsonHelper.h"
|
||||
#include "Basics/logging.h"
|
||||
#include "Basics/tri-strings.h"
|
||||
#include "Basics/memory-map.h"
|
||||
#include "VocBase/document-collection.h"
|
||||
#include "VocBase/server.h"
|
||||
#include "VocBase/vocbase.h"
|
||||
|
@ -738,6 +739,11 @@ static bool IterateDatafilesVector (const TRI_vector_pointer_t* const files,
|
|||
if (! TRI_IterateDatafile(datafile, iterator, data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (datafile->isPhysical(datafile) && datafile->_isSealed) {
|
||||
TRI_MMFileAdvise(datafile->_data, datafile->_maximalSize,
|
||||
TRI_MADVISE_RANDOM);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "Basics/files.h"
|
||||
#include "Basics/logging.h"
|
||||
#include "Basics/tri-strings.h"
|
||||
#include "Basics/memory-map.h"
|
||||
#include "Utils/transactions.h"
|
||||
#include "VocBase/document-collection.h"
|
||||
#include "VocBase/server.h"
|
||||
|
@ -763,6 +764,12 @@ static compaction_initial_context_t InitCompaction (TRI_document_collection_t* d
|
|||
compaction_info_t* compaction = static_cast<compaction_info_t*>(TRI_AtVector(compactions, i));
|
||||
TRI_datafile_t* df = compaction->_datafile;
|
||||
|
||||
// We will sequentially scan the logfile for collection:
|
||||
if (df->isPhysical(df)) {
|
||||
TRI_MMFileAdvise(df->_data, df->_maximalSize, TRI_MADVISE_SEQUENTIAL);
|
||||
TRI_MMFileAdvise(df->_data, df->_maximalSize, TRI_MADVISE_WILLNEED);
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
// extract and store fid
|
||||
context._fid = compaction->_datafile->_fid;
|
||||
|
@ -772,6 +779,10 @@ static compaction_initial_context_t InitCompaction (TRI_document_collection_t* d
|
|||
|
||||
bool ok = TRI_IterateDatafile(df, CalculateSize, &context);
|
||||
|
||||
if (df->isPhysical(df)) {
|
||||
TRI_MMFileAdvise(df->_data, df->_maximalSize, TRI_MADVISE_RANDOM);
|
||||
}
|
||||
|
||||
if (! ok) {
|
||||
context._failed = true;
|
||||
break;
|
||||
|
|
|
@ -1404,6 +1404,10 @@ TRI_datafile_t* TRI_CreatePhysicalDatafile (char const* filename,
|
|||
fid,
|
||||
static_cast<char*>(data));
|
||||
|
||||
// Advise OS that sequential access is going to happen:
|
||||
TRI_MMFileAdvise(datafile->_data, datafile->_maximalSize,
|
||||
TRI_MADVISE_SEQUENTIAL);
|
||||
|
||||
return datafile;
|
||||
}
|
||||
|
||||
|
@ -1893,6 +1897,12 @@ TRI_datafile_t* TRI_OpenDatafile (char const* filename,
|
|||
TRI_ProtectMMFile(datafile->_data, datafile->_maximalSize, PROT_READ | PROT_WRITE, datafile->_fd, &datafile->_mmHandle);
|
||||
}
|
||||
|
||||
// Advise on sequential use:
|
||||
TRI_MMFileAdvise(datafile->_data, datafile->_maximalSize,
|
||||
TRI_MADVISE_SEQUENTIAL);
|
||||
TRI_MMFileAdvise(datafile->_data, datafile->_maximalSize,
|
||||
TRI_MADVISE_WILLNEED);
|
||||
|
||||
return datafile;
|
||||
}
|
||||
|
||||
|
@ -2061,6 +2071,12 @@ int TRI_SealDatafile (TRI_datafile_t* datafile) {
|
|||
return datafile->_lastError;
|
||||
}
|
||||
|
||||
if (datafile->isPhysical(datafile)) {
|
||||
// From now on we predict random access (until collection or compaction):
|
||||
TRI_MMFileAdvise(datafile->_data, datafile->_maximalSize,
|
||||
TRI_MADVISE_RANDOM);
|
||||
}
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -731,19 +731,19 @@ int TRI_SealDatafile (TRI_datafile_t* datafile) TRI_WARN_UNUSED_RESULT;
|
|||
bool TRI_RenameDatafile (TRI_datafile_t* datafile, char const* filename);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief truncates a datafile and seals it
|
||||
/// @brief truncates a datafile and seals it, only called by arango-dfdd
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_TruncateDatafile (char const* path, TRI_voc_size_t position);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief try to repair a datafile
|
||||
/// @brief try to repair a datafile, only called by arango-dfdd
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TRI_TryRepairDatafile (char const* path);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns information about the datafile
|
||||
/// @brief returns information about the datafile, only called by arango-dfdd
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_df_scan_t TRI_ScanDatafile (char const* path);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "Basics/MutexLocker.h"
|
||||
#include "Basics/hashes.h"
|
||||
#include "Basics/logging.h"
|
||||
#include "Basics/memory-map.h"
|
||||
#include "Basics/ConditionLocker.h"
|
||||
#include "Basics/Exceptions.h"
|
||||
#include "Utils/CollectionGuard.h"
|
||||
|
@ -739,6 +740,12 @@ int CollectorThread::collect (Logfile* logfile) {
|
|||
|
||||
TRI_ASSERT(df != nullptr);
|
||||
|
||||
// We will sequentially scan the logfile for collection:
|
||||
TRI_MMFileAdvise(df->_data, df->_maximalSize, TRI_MADVISE_SEQUENTIAL);
|
||||
TRI_MMFileAdvise(df->_data, df->_maximalSize, TRI_MADVISE_WILLNEED);
|
||||
TRI_DEFER (TRI_MMFileAdvise(df->_data, df->_maximalSize,
|
||||
TRI_MADVISE_RANDOM));
|
||||
|
||||
// create a state for the collector, beginning with the list of failed transactions
|
||||
CollectorState state;
|
||||
state.failedTransactions = _logfileManager->getFailedTransactions();
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "Basics/ReadLocker.h"
|
||||
#include "Basics/StringUtils.h"
|
||||
#include "Basics/WriteLocker.h"
|
||||
#include "Basics/memory-map.h"
|
||||
#include "VocBase/server.h"
|
||||
#include "Wal/AllocatorThread.h"
|
||||
#include "Wal/CollectorThread.h"
|
||||
|
@ -2064,6 +2065,12 @@ int LogfileManager::inspectLogfiles () {
|
|||
(unsigned long long) logfile->df()->_tickMin,
|
||||
(unsigned long long) logfile->df()->_tickMax);
|
||||
|
||||
if (logfile->status() == Logfile::StatusType::SEALED) {
|
||||
// If it is sealed, switch to random access:
|
||||
TRI_datafile_t* df = logfile->df();
|
||||
TRI_MMFileAdvise(df->_data, df->_maximalSize, TRI_MADVISE_RANDOM);
|
||||
}
|
||||
|
||||
{
|
||||
MUTEX_LOCKER(_idLock);
|
||||
if (logfile->status() == Logfile::StatusType::SEALED &&
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "Basics/conversions.h"
|
||||
#include "Basics/files.h"
|
||||
#include "Basics/Exceptions.h"
|
||||
#include "Basics/memory-map.h"
|
||||
#include "VocBase/collection.h"
|
||||
#include "VocBase/replication-applier.h"
|
||||
#include "VocBase/VocShaper.h"
|
||||
|
@ -1355,11 +1356,21 @@ int RecoverState::replayLogfile (Logfile* logfile,
|
|||
LOG_INFO("replaying WAL logfile '%s' (%d of %d)",
|
||||
logfile->filename().c_str(), number + 1, n);
|
||||
|
||||
// Advise on sequential use:
|
||||
TRI_MMFileAdvise(logfile->df()->_data, logfile->df()->_maximalSize,
|
||||
TRI_MADVISE_SEQUENTIAL);
|
||||
TRI_MMFileAdvise(logfile->df()->_data, logfile->df()->_maximalSize,
|
||||
TRI_MADVISE_WILLNEED);
|
||||
|
||||
if (! TRI_IterateDatafile(logfile->df(), &RecoverState::ReplayMarker, static_cast<void*>(this))) {
|
||||
LOG_WARNING("WAL inspection failed when scanning logfile '%s'", logfile->filename().c_str());
|
||||
return TRI_ERROR_ARANGO_RECOVERY;
|
||||
}
|
||||
|
||||
// Advise on random access use:
|
||||
TRI_MMFileAdvise(logfile->df()->_data, logfile->df()->_maximalSize,
|
||||
TRI_MADVISE_RANDOM);
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "Basics/logging.h"
|
||||
#include "Basics/Mutex.h"
|
||||
#include "Basics/MutexLocker.h"
|
||||
#include "Basics/memory-map.h"
|
||||
|
||||
namespace triagens {
|
||||
namespace basics {
|
||||
|
@ -243,6 +244,17 @@ namespace triagens {
|
|||
// may fail...
|
||||
b._table = new EntryType[b._nrAlloc];
|
||||
|
||||
#ifdef __linux__
|
||||
if (b._nrAlloc > 1000000) {
|
||||
uintptr_t mem = reinterpret_cast<uintptr_t>(b._table);
|
||||
uintptr_t pageSize = getpagesize();
|
||||
mem = (mem / pageSize) * pageSize;
|
||||
void* memptr = reinterpret_cast<void*>(mem);
|
||||
TRI_MMFileAdvise(memptr, b._nrAlloc * sizeof(EntryType),
|
||||
TRI_MADVISE_RANDOM);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (IndexType i = 0; i < b._nrAlloc; i++) {
|
||||
invalidateEntry(b, i);
|
||||
}
|
||||
|
@ -1032,8 +1044,8 @@ namespace triagens {
|
|||
/// @brief resize the array
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int resize (IndexType size) throw() {
|
||||
size /= static_cast<IndexType>(_buckets.size());
|
||||
int resize (size_t size) throw() {
|
||||
size /= _buckets.size();
|
||||
for (auto& b : _buckets) {
|
||||
if (2 * (2 * size + 1) < 3 * b._nrUsed) {
|
||||
return TRI_ERROR_BAD_PARAMETER;
|
||||
|
@ -1103,7 +1115,7 @@ namespace triagens {
|
|||
/// @brief resize the array, internal method
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void resizeInternal (Bucket& b, IndexType size) {
|
||||
void resizeInternal (Bucket& b, size_t size) {
|
||||
LOG_ACTION("index-resize %s, target size: %llu",
|
||||
_contextCallback().c_str(),
|
||||
(unsigned long long) size);
|
||||
|
@ -1112,9 +1124,20 @@ namespace triagens {
|
|||
EntryType* oldTable = b._table;
|
||||
IndexType oldAlloc = b._nrAlloc;
|
||||
|
||||
b._nrAlloc = static_cast<IndexType>(TRI_NearPrime(size));
|
||||
b._nrAlloc = static_cast<IndexType>(TRI_NearPrime(static_cast<uint64_t>(size)));
|
||||
try {
|
||||
b._table = new EntryType[b._nrAlloc];
|
||||
#ifdef __linux__
|
||||
if (b._nrAlloc > 1000000) {
|
||||
uintptr_t mem = reinterpret_cast<uintptr_t>(b._table);
|
||||
uintptr_t pageSize = getpagesize();
|
||||
mem = (mem / pageSize) * pageSize;
|
||||
void* memptr = reinterpret_cast<void*>(mem);
|
||||
TRI_MMFileAdvise(memptr, b._nrAlloc * sizeof(EntryType),
|
||||
TRI_MADVISE_RANDOM);
|
||||
}
|
||||
#endif
|
||||
|
||||
IndexType i;
|
||||
for (i = 0; i < b._nrAlloc; i++) {
|
||||
invalidateEntry(b, i);
|
||||
|
|
|
@ -47,14 +47,20 @@ namespace triagens {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct AttributeName {
|
||||
std::string const name;
|
||||
bool const shouldExpand;
|
||||
std::string name;
|
||||
bool shouldExpand;
|
||||
|
||||
AttributeName (std::string const& pName)
|
||||
: name(pName), shouldExpand(false) { };
|
||||
: name(pName), shouldExpand(false) {
|
||||
}
|
||||
|
||||
AttributeName (std::string const& pName, bool pExpand)
|
||||
: name(pName), shouldExpand(pExpand) { };
|
||||
: name(pName), shouldExpand(pExpand) {
|
||||
}
|
||||
|
||||
AttributeName (const AttributeName& b)
|
||||
: name(b.name), shouldExpand(b.shouldExpand) {
|
||||
}
|
||||
|
||||
bool operator== (const AttributeName& b) const {
|
||||
return name == b.name && shouldExpand == b.shouldExpand;
|
||||
|
|
|
@ -151,6 +151,30 @@ int TRI_ProtectMMFile (void* memoryAddress,
|
|||
return TRI_ERROR_SYS_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief gives hints about upcoming sequential memory usage
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_MMFileAdvise (void* memoryAddress, size_t numOfBytes, int advice) {
|
||||
#ifdef __linux__
|
||||
LOG_DEBUG("Doing madvise %d for %lu length %lu", advice,
|
||||
(uint64_t) memoryAddress, numOfBytes);
|
||||
char buffer[256];
|
||||
int res = madvise(memoryAddress, numOfBytes, advice);
|
||||
if (res == 0) {
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
else {
|
||||
char* p = strerror_r(errno, buffer, 256);
|
||||
LOG_INFO("madvise %d for %lu length %lu failed with: %s ",
|
||||
advice, (uint64_t) memoryAddress, numOfBytes, p);
|
||||
return TRI_ERROR_INTERNAL;
|
||||
}
|
||||
#else
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -49,6 +49,22 @@
|
|||
#define TRI_MMAP_ANONYMOUS MAP_ANON
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constants for TRI_MMFileAdvise
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __linux__
|
||||
#define TRI_MADVISE_SEQUENTIAL MADV_SEQUENTIAL
|
||||
#define TRI_MADVISE_RANDOM MADV_RANDOM
|
||||
#define TRI_MADVISE_WILLNEED MADV_WILLNEED
|
||||
#define TRI_MADVISE_DONTNEED MADV_DONTNEED
|
||||
#else
|
||||
#define TRI_MADVISE_SEQUENTIAL 0
|
||||
#define TRI_MADVISE_RANDOM 0
|
||||
#define TRI_MADVISE_WILLNEED 0
|
||||
#define TRI_MADVISE_DONTNEED 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -335,6 +335,15 @@ int TRI_ProtectMMFile (void* memoryAddress,
|
|||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief gives hints about upcoming sequential memory usage
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_MMFileAdvise (void*, size_t, int) {
|
||||
// Not on Windows
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -77,6 +77,15 @@
|
|||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constants for TRI_MMFileAdvise, not on Windows
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TRI_MADVISE_SEQUENTIAL 0
|
||||
#define TRI_MADVISE_RANDOM 0
|
||||
#define TRI_MADVISE_WILLNEED 0
|
||||
#define TRI_MADVISE_DONTNEED 0
|
||||
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -103,6 +103,12 @@ int TRI_ProtectMMFile (void* memoryAddress,
|
|||
int fileDescriptor,
|
||||
void** mmHandle);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief gives hints about upcoming memory usage
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_MMFileAdvise (void* memoryAddress, size_t numOfBytes, int advice);
|
||||
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue