diff options
Diffstat (limited to 'src/mongo/base')
| -rw-r--r-- | src/mongo/base/error_codes.tpl.cpp | 2 | ||||
| -rw-r--r-- | src/mongo/base/error_codes.yml | 20 | ||||
| -rw-r--r-- | src/mongo/base/murmurhash3_test.cpp | 142 | ||||
| -rw-r--r-- | src/mongo/base/secure_allocator.cpp | 15 | ||||
| -rw-r--r-- | src/mongo/base/simple_string_data_comparator.cpp | 26 |
5 files changed, 116 insertions, 89 deletions
diff --git a/src/mongo/base/error_codes.tpl.cpp b/src/mongo/base/error_codes.tpl.cpp index a51621590c5..bd2071c2627 100644 --- a/src/mongo/base/error_codes.tpl.cpp +++ b/src/mongo/base/error_codes.tpl.cpp @@ -32,6 +32,8 @@ #include "mongo/base/error_codes.h" #include "mongo/base/static_assert.h" +#include "mongo/db/concurrency/temporarily_unavailable_exception.h" +#include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/util/assert_util.h" #include "mongo/util/str.h" diff --git a/src/mongo/base/error_codes.yml b/src/mongo/base/error_codes.yml index 0b3150042bd..d98c6adf60d 100644 --- a/src/mongo/base/error_codes.yml +++ b/src/mongo/base/error_codes.yml @@ -174,7 +174,7 @@ error_codes: #- {code: 131,name: RLPInitializationFailed} # Removed in 4.2 - {code: 132,name: OBSOLETE_ConfigServersInconsistent} - {code: 133,name: FailedToSatisfyReadPreference} - - {code: 134,name: ReadConcernMajorityNotAvailableYet} + - {code: 134,name: ReadConcernMajorityNotAvailableYet, categories: [RetriableError]} - {code: 135,name: StaleTerm} - {code: 136,name: CappedPositionLost} - {code: 137,name: IncompatibleShardingConfigVersion} @@ -301,9 +301,9 @@ error_codes: - {code: 250,name: StaleChunkHistory,categories: [SnapshotError]} - {code: 251,name: NoSuchTransaction,categories: [VoteAbortError]} - {code: 252,name: ReentrancyNotAllowed} - - {code: 253,name: FreeMonHttpInFlight} - - {code: 254,name: FreeMonHttpTemporaryFailure} - - {code: 255,name: FreeMonHttpPermanentFailure} + # - {code: 253,name: FreeMonHttpInFlight} # Removed in 7.1 + # - {code: 254,name: FreeMonHttpTemporaryFailure} # Removed in 7.1 + # - {code: 255,name: FreeMonHttpPermanentFailure} # Removed in 7.1 - {code: 256,name: TransactionCommitted} - {code: 257,name: TransactionTooLarge} - {code: 258,name: UnknownFeatureCompatibilityVersion} @@ -492,6 +492,18 @@ error_codes: - {code: 375, name: TransactionAPIMustRetryCommit, categories: [InternalOnly]} - {code: 377, name: FLEMaxTagLimitExceeded } + - {code: 379, name: DatabaseMetadataRefreshCanceled, categories: [InternalOnly]} + + - {code: 388, name: TransactionTooLargeForCache} + + # This error code is not generated internally in mongod/s servers, but must be parsed and + # reserve an error code. It can be returned by a remote search index management server. + - {code: 396, name: IndexInformationTooLarge} + + - {code: 398, name: StreamTerminated, categories: [CloseConnectionError]} + + - {code: 384, name: ConnectionError, categories: [NetworkError,RetriableError,InternalOnly]} + # Error codes 4000-8999 are reserved. # Non-sequential error codes for compatibility only) diff --git a/src/mongo/base/murmurhash3_test.cpp b/src/mongo/base/murmurhash3_test.cpp index a2f4219b856..fd780ce6217 100644 --- a/src/mongo/base/murmurhash3_test.cpp +++ b/src/mongo/base/murmurhash3_test.cpp @@ -30,35 +30,32 @@ #include <array> #include <string> -#include <third_party/murmurhash3/MurmurHash3.h> - -#include "mongo/unittest/unittest.h" - #include "mongo/base/data_type_endian.h" #include "mongo/base/data_view.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/murmur3.h" + +#define TEST_STRING32(str, seed, expected) \ + ASSERT_EQUALS(murmur3<sizeof(uint32_t)>(StringData{str}, seed), expected) + +#define TEST_STRING64(str, seed, expected) \ + ASSERT_EQUALS(murmur3<sizeof(uint64_t)>(StringData{str}, seed), expected) -#define TEST_STRING32(str, seed, expected) ASSERT_EQUALS(compute32(str, seed), expected) -#define TEST_STRING64(str, seed, a, b) \ - do { \ - auto pair = compute128(str, seed); \ - ASSERT_EQUALS(pair.first, a); \ - ASSERT_EQUALS(pair.second, b); \ +#define TEST_STRING128(str, seed, a, b) \ + do { \ + auto pair = compute128(StringData{str}, seed); \ + ASSERT_EQUALS(pair.first, a); \ + ASSERT_EQUALS(pair.second, b); \ } while (0) namespace mongo { namespace { -uint32_t compute32(StringData input, uint32_t seed) { - char hash[4]; - MurmurHash3_x86_32(input.rawData(), input.size(), seed, &hash); - return ConstDataView(hash).read<LittleEndian<uint32_t>>(); -} - std::pair<uint64_t, uint64_t> compute128(StringData input, uint32_t seed) { - char hash[16]; - MurmurHash3_x64_128(input.rawData(), input.size(), seed, &hash); - return {ConstDataView(hash).read<LittleEndian<uint64_t>>(), - ConstDataView(hash).read<LittleEndian<uint64_t>>(8)}; + std::array<char, 16> hash; + murmur3(input, seed, hash); + return {ConstDataView(hash.data()).read<LittleEndian<uint64_t>>(), + ConstDataView(hash.data()).read<LittleEndian<uint64_t>>(8)}; } TEST(MurmurHash3, TestVectors32) { @@ -92,52 +89,79 @@ TEST(MurmurHash3, TestVectors32) { } -TEST(MurmurHash3, TestVectors64) { - TEST_STRING64("", 0, 0ULL, 0ULL); - - TEST_STRING64("", 1ULL, 5048724184180415669ULL, 5864299874987029891ULL); - TEST_STRING64("", - 0xffffffffULL, - 7706185961851046380ULL, - 9616347466054386795ULL); // make sure seed value is handled unsigned - TEST_STRING64("\0\0\0\0"_sd, - 0ULL, - 14961230494313510588ULL, - 6383328099726337777ULL); // make sure we handle embedded nulls - - - TEST_STRING64( - "aaaa", 0x9747b28cULL, 13033599803469372400ULL, 11949150323828610719ULL); // one full chunk - TEST_STRING64("aaa", - 0x9747b28cULL, - 10278871841506805355ULL, - 17952965428487426844ULL); // three characters - TEST_STRING64( - "aa", 0x9747b28cULL, 1343929393636293407ULL, 16804672932933964801ULL); // two characters - TEST_STRING64( - "a", 0x9747b28cULL, 6694838689256856093ULL, 11415968713816993796ULL); // one character +TEST(MurmurHash3, TestVectors128) { + TEST_STRING128("", 0, 0ULL, 0ULL); + + TEST_STRING128("", 1ULL, 5048724184180415669ULL, 5864299874987029891ULL); + // Make sure seed value is handled unsigned. + TEST_STRING128("", 0xffffffffULL, 7706185961851046380ULL, 9616347466054386795ULL); + // Make sure we handle embedded nulls. + TEST_STRING128("\0\0\0\0"_sd, 0ULL, 14961230494313510588ULL, 6383328099726337777ULL); + + // One full chunk. + TEST_STRING128("aaaa", 0x9747b28cULL, 13033599803469372400ULL, 11949150323828610719ULL); + // Three characters. + TEST_STRING128("aaa", 0x9747b28cULL, 10278871841506805355ULL, 17952965428487426844ULL); + // Two characters. + TEST_STRING128("aa", 0x9747b28cULL, 1343929393636293407ULL, 16804672932933964801ULL); + // One character. + TEST_STRING128("a", 0x9747b28cULL, 6694838689256856093ULL, 11415968713816993796ULL); // Endian order within the chunks - TEST_STRING64( - "abcd", 0x9747b28cULL, 5310993687375067025ULL, 9979528070057666491ULL); // one full chunk - TEST_STRING64("abc", 0x9747b28cULL, 3982135406228655836ULL, 14835035517329147071ULL); - TEST_STRING64("ab", 0x9747b28cULL, 9526501539032868875ULL, 9131386788375312171ULL); - TEST_STRING64("a", 0x9747b28cULL, 6694838689256856093ULL, 11415968713816993796ULL); + TEST_STRING128("abcd", 0x9747b28cULL, 5310993687375067025ULL, 9979528070057666491ULL); + TEST_STRING128("abc", 0x9747b28cULL, 3982135406228655836ULL, 14835035517329147071ULL); + TEST_STRING128("ab", 0x9747b28cULL, 9526501539032868875ULL, 9131386788375312171ULL); + TEST_STRING128("a", 0x9747b28cULL, 6694838689256856093ULL, 11415968713816993796ULL); - TEST_STRING64("Hello, world!", 0x9747b28cULL, 17132966038248896814ULL, 17896881015324243642ULL); + TEST_STRING128( + "Hello, world!", 0x9747b28cULL, 17132966038248896814ULL, 17896881015324243642ULL); - // Make sure you handle UTF-8 high characters. A bcrypt implementation messed this up - TEST_STRING64("ππππππππ", - 0x9747b28cULL, - 10874605236735318559ULL, - 17921841414653337979ULL); // U+03C0: Greek Small Letter Pi + // Make sure to handle UTF-8 high characters. A bcrypt implementation messed this up. Here we + // use U+03C0: Greek Small Letter Pi. + TEST_STRING128("ππππππππ", 0x9747b28cULL, 10874605236735318559ULL, 17921841414653337979ULL); - // String of 256 characters. - // Make sure you don't store string lengths in a char, and overflow at 255 bytes (as OpenBSD's - // canonical BCrypt implementation did) - TEST_STRING64( + // String of 256 characters. Make sure you don't store string lengths in a char, and overflow at + // 255 bytes (as OpenBSD's canonical BCrypt implementation did). + TEST_STRING128( std::string(256, 'a'), 0x9747b28cULL, 557766291455132100ULL, 14184293241195392597ULL); } +// Output of the 64-bit version of murmur3() should be the same as the first 8 bytes of the 128-bit +// version. +TEST(MurmurHash3, TestVectors64) { + TEST_STRING64("", 0, 0ULL); + + TEST_STRING64("", 1ULL, 5048724184180415669ULL); + // Make sure seed value is handled unsigned. + TEST_STRING64("", 0xffffffffULL, 7706185961851046380ULL); + // Make sure we handle embedded nulls. + TEST_STRING64("\0\0\0\0"_sd, 0ULL, 14961230494313510588ULL); + + // One full chunk. + TEST_STRING64("aaaa", 0x9747b28cULL, 13033599803469372400ULL); + // Three characters. + TEST_STRING64("aaa", 0x9747b28cULL, 10278871841506805355ULL); + // Two characters. + TEST_STRING64("aa", 0x9747b28cULL, 1343929393636293407ULL); + // One character. + TEST_STRING64("a", 0x9747b28cULL, 6694838689256856093ULL); + + // Endian order within the chunks + TEST_STRING64("abcd", 0x9747b28cULL, 5310993687375067025ULL); + TEST_STRING64("abc", 0x9747b28cULL, 3982135406228655836ULL); + TEST_STRING64("ab", 0x9747b28cULL, 9526501539032868875ULL); + TEST_STRING64("a", 0x9747b28cULL, 6694838689256856093ULL); + + TEST_STRING64("Hello, world!", 0x9747b28cULL, 17132966038248896814ULL); + + // Make sure to handle UTF-8 high characters. A bcrypt implementation messed this up. Here we + // use U+03C0: Greek Small Letter Pi. + TEST_STRING64("ππππππππ", 0x9747b28cULL, 10874605236735318559ULL); + + // String of 256 characters. Make sure you don't store string lengths in a char, and overflow at + // 255 bytes (as OpenBSD's canonical BCrypt implementation did). + TEST_STRING64(std::string(256, 'a'), 0x9747b28cULL, 557766291455132100ULL); +} + } // namespace } // namespace mongo diff --git a/src/mongo/base/secure_allocator.cpp b/src/mongo/base/secure_allocator.cpp index 47837cb5c7d..0062005ae85 100644 --- a/src/mongo/base/secure_allocator.cpp +++ b/src/mongo/base/secure_allocator.cpp @@ -37,6 +37,7 @@ #include <memory> #ifdef _WIN32 +#include <psapi.h> #include <windows.h> #else #include <sys/mman.h> @@ -145,7 +146,19 @@ void growWorkingSize(std::size_t bytes) { // Since allocation request is aligned to page size, we can just add it to the current working // set size. - maxWorkingSetSize = std::max(minWorkingSetSize + bytes + minGap, maxWorkingSetSize); + // Note: The default dwMaximumWorkingSetSize for a process is 345 pages on a system with 4k + // pages (i.e x64). This is not the same as the current working set of the process. It usually + // far lower. The min value is ignored by Windows until the machine is starved for memory or + // MongoDB wants to lock pages. The max value is treated as a target working set goal for a + // process that Windows should meet. This means that if MongoDB sets the number too low, Windows + // will flush the process out to the page file which will cause the process to freeze while this + // occurs. MongoDB will set the dwMaximumWorkingSetSize to 90% of physical RAM. On high memory + // systems (> 128GB0), this may be too conservative so use 5GB as a threshold. + uint64_t physicalRamSize = ProcessInfo::getMemSizeMB() * 1024ULL * 1024ULL; + + maxWorkingSetSize = physicalRamSize - + std::min(0.10 * physicalRamSize, + static_cast<double>(5ULL * 1024ULL * 1024ULL * 1024ULL) /* 5 GB */); // Increase the working set size minimum to the new lower bound. if (!SetProcessWorkingSetSizeEx(GetCurrentProcess(), diff --git a/src/mongo/base/simple_string_data_comparator.cpp b/src/mongo/base/simple_string_data_comparator.cpp index eaeb67ac829..c03fddf4316 100644 --- a/src/mongo/base/simple_string_data_comparator.cpp +++ b/src/mongo/base/simple_string_data_comparator.cpp @@ -31,34 +31,10 @@ #include "mongo/base/simple_string_data_comparator.h" -#include <third_party/murmurhash3/MurmurHash3.h> - -#include "mongo/base/data_type_endian.h" -#include "mongo/base/data_view.h" +#include "mongo/util/murmur3.h" namespace mongo { -namespace { - -template <int SizeofSizeT> -size_t murmur3(StringData str, size_t seed); - -template <> -size_t murmur3<4>(StringData str, size_t seed) { - char hash[4]; - MurmurHash3_x86_32(str.rawData(), str.size(), seed, &hash); - return ConstDataView(hash).read<LittleEndian<std::uint32_t>>(); -} - -template <> -size_t murmur3<8>(StringData str, size_t seed) { - char hash[16]; - MurmurHash3_x64_128(str.rawData(), str.size(), seed, hash); - return static_cast<size_t>(ConstDataView(hash).read<LittleEndian<std::uint64_t>>()); -} - -} // namespace - const SimpleStringDataComparator SimpleStringDataComparator::kInstance{}; int SimpleStringDataComparator::compare(StringData left, StringData right) const { |
