diff options
5 files changed, 71 insertions, 23 deletions
diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index 9d99a15894a..15a70e742ec 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -833,7 +833,6 @@ public: private: uint32_t _lastLid; BucketId _lastBucketId; - uint32_t _lastUser; vespalib::hash_set<uint32_t> _uniqueUser; vespalib::hash_set<uint64_t> _uniqueBucket; }; @@ -854,6 +853,52 @@ TEST("test that StoreByBucket gives bucket by bucket and ordered within") { sbb.drain(vbo); } +TEST("test that LidInfo has 8 bytes size and that it can represent the numbers correctly.") +{ + EXPECT_EQUAL(8, sizeof(LidInfo)); + LidInfo a(0,0,0); + EXPECT_EQUAL(0u, a.getFileId()); + EXPECT_EQUAL(0u, a.getChunkId()); + EXPECT_EQUAL(0u, a.size()); + EXPECT_TRUE(a.valid()); + EXPECT_TRUE(a.empty()); + a = LidInfo(1,1,1); + EXPECT_EQUAL(1u, a.getFileId()); + EXPECT_EQUAL(1u, a.getChunkId()); + EXPECT_EQUAL(64u, a.size()); + EXPECT_TRUE(a.valid()); + EXPECT_FALSE(a.empty()); + a = LidInfo(1,1,63); + EXPECT_EQUAL(1u, a.getFileId()); + EXPECT_EQUAL(1u, a.getChunkId()); + EXPECT_EQUAL(64u, a.size()); + EXPECT_TRUE(a.valid()); + EXPECT_FALSE(a.empty()); + a = LidInfo(1,1,64); + EXPECT_EQUAL(1u, a.getFileId()); + EXPECT_EQUAL(1u, a.getChunkId()); + EXPECT_EQUAL(64u, a.size()); + EXPECT_TRUE(a.valid()); + EXPECT_FALSE(a.empty()); + a = LidInfo(1,1,65); + EXPECT_EQUAL(1u, a.getFileId()); + EXPECT_EQUAL(1u, a.getChunkId()); + EXPECT_EQUAL(128u, a.size()); + EXPECT_TRUE(a.valid()); + EXPECT_FALSE(a.empty()); + a = LidInfo(0xffff,0x3fffff,0xffffff80u); + EXPECT_EQUAL(0xffff, a.getFileId()); + EXPECT_EQUAL(0x3fffff, a.getChunkId()); + EXPECT_EQUAL(0xffffff80u, a.size()); + EXPECT_TRUE(a.valid()); + EXPECT_FALSE(a.empty()); + EXPECT_EXCEPTION(a = LidInfo(0x10000,0x3fffff,1), std::runtime_error, + "LidInfo(fileId=65536, chunkId=4194303, size=1) has invalid fileId larger than 65535"); + EXPECT_EXCEPTION(a = LidInfo(0xffff,0x400000,1), std::runtime_error, + "LidInfo(fileId=65535, chunkId=4194304, size=1) has invalid chunkId larger than 4194303"); + EXPECT_EXCEPTION(a = LidInfo(0xffff,0x3fffff,0xffffff81u), std::runtime_error, + "LidInfo(fileId=65535, chunkId=4194303, size=4294967169) has too large size larger than 4294967168"); +} TEST_MAIN() { DummyFileHeaderContext::setCreator("logdatastore_test"); TEST_RUN_ALL(); diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp index 5ff8eff2b41..35843bfd67b 100644 --- a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp +++ b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp @@ -39,19 +39,24 @@ FileChunk::ChunkInfo::ChunkInfo(uint64_t offset, uint32_t size, uint64_t lastSer LidInfo::LidInfo(uint32_t fileId, uint32_t chunkId, uint32_t sz) { - _value.v.fileId = fileId; - _value.v.chunkId = chunkId; - _value.v.size = sz; - if (fileId >= (1 << 10)) { + if (fileId >= getMaxFileNum()) { throw std::runtime_error( make_string("LidInfo(fileId=%u, chunkId=%u, size=%u) has invalid fileId larger than %d", - fileId, chunkId, sz, (1 << 10) - 1)); + fileId, chunkId, sz, getMaxFileNum() - 1)); } - if (chunkId >= (1 << 22)) { + if (chunkId >= getMaxChunkNum()) { throw std::runtime_error( make_string("LidInfo(fileId=%u, chunkId=%u, size=%u) has invalid chunkId larger than %d", - fileId, chunkId, sz, (1 << 22) - 1)); + fileId, chunkId, sz, getMaxChunkNum() - 1)); + } + if (sz > (std::numeric_limits<uint32_t>::max() - ((2<<SIZE_SHIFT) - 1))) { + throw std::runtime_error( + make_string("LidInfo(fileId=%u, chunkId=%u, size=%u) has too large size larger than %u", + fileId, chunkId, sz, std::numeric_limits<uint32_t>::max() - ((2<<SIZE_SHIFT)-1))); } + _value.v.fileId = fileId; + _value.v.chunkId = chunkId; + _value.v.size = (sz+((1<<SIZE_SHIFT)-1)) >> SIZE_SHIFT; } vespalib::string diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.h b/searchlib/src/vespa/searchlib/docstore/filechunk.h index c7ba6eac024..4cfd1bce583 100644 --- a/searchlib/src/vespa/searchlib/docstore/filechunk.h +++ b/searchlib/src/vespa/searchlib/docstore/filechunk.h @@ -28,7 +28,7 @@ public: LidInfo(uint32_t fileId, uint32_t chunkId, uint32_t size); uint32_t getFileId() const { return _value.v.fileId; } uint32_t getChunkId() const { return _value.v.chunkId; } - uint32_t size() const { return _value.v.size; } + uint32_t size() const { return _value.v.size << SIZE_SHIFT; } operator uint64_t () const { return _value.r; } bool empty() const { return size() == 0; } bool valid() const { return _value.r != std::numeric_limits<uint64_t>::max(); } @@ -42,13 +42,17 @@ public: ? (getChunkId() < b.getChunkId()) : (getFileId() < b.getFileId()); } - static uint32_t getMaxFileNum() { return 1 << 10; } - static uint32_t getMaxChunkNum() { return 1 << 22; } + static uint32_t getMaxFileNum() { return 1 << NUM_FILE_BITS; } + static uint32_t getMaxChunkNum() { return 1 << NUM_CHUNK_BITS; } private: + static constexpr uint32_t NUM_FILE_BITS = 16; + static constexpr uint32_t NUM_CHUNK_BITS = 22; + static constexpr uint32_t NUM_SIZE_BITS = 26; + static constexpr uint32_t SIZE_SHIFT = 32 - NUM_SIZE_BITS; struct Rep { - uint16_t fileId : 10; - uint32_t chunkId : 22; - uint32_t size; + uint64_t fileId : 16; + uint64_t chunkId : 22; + uint64_t size : 26; }; union Value { Value() : r(std::numeric_limits<uint64_t>::max()) { } diff --git a/slobrok/src/vespa/slobrok/server/managed_rpc_server.cpp b/slobrok/src/vespa/slobrok/server/managed_rpc_server.cpp index 88414e7ab19..0513f30c1dc 100644 --- a/slobrok/src/vespa/slobrok/server/managed_rpc_server.cpp +++ b/slobrok/src/vespa/slobrok/server/managed_rpc_server.cpp @@ -1,11 +1,9 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> - -#include <vespa/log/log.h> -LOG_SETUP(".rpcserver"); #include "managed_rpc_server.h" #include "i_rpc_server_manager.h" +#include <vespa/log/log.h> +LOG_SETUP(".rpcserver"); namespace slobrok { diff --git a/slobrok/src/vespa/slobrok/server/monitor.cpp b/slobrok/src/vespa/slobrok/server/monitor.cpp index 6ff7d7dd422..70df443af86 100644 --- a/slobrok/src/vespa/slobrok/server/monitor.cpp +++ b/slobrok/src/vespa/slobrok/server/monitor.cpp @@ -1,8 +1,4 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> - -#include <vespa/log/log.h> -LOG_SETUP(".monitor"); #include "monitor.h" @@ -29,7 +25,7 @@ Monitor::~Monitor() void Monitor::enable(FRT_Target *monitorTarget) { - LOG_ASSERT(monitorTarget != NULL); + assert(monitorTarget != NULL); Unschedule(); disconnect(); _enabled = true; |