Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/DataTypes/Serializations/SerializationString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void SerializationString::serializeBinaryBulk(const IColumn & column, WriteBuffe

template <int UNROLL_TIMES>
static NO_INLINE void deserializeBinarySSE2(ColumnString::Chars & data, ColumnString::Offsets & offsets, ReadBuffer & istr, size_t limit)
try
{
size_t offset = data.size();
/// Avoiding calling resize in a loop improves the performance.
Expand All @@ -171,8 +172,6 @@ static NO_INLINE void deserializeBinarySSE2(ColumnString::Chars & data, ColumnSt
max_string_size);

offset += size + 1;
offsets.push_back(offset);

if (unlikely(offset > data.size()))
data.resize_exact(roundUpToPowerOfTwoOrZero(std::max(offset, data.size() * 2)));

Expand Down Expand Up @@ -205,10 +204,18 @@ static NO_INLINE void deserializeBinarySSE2(ColumnString::Chars & data, ColumnSt
}

data[offset - 1] = 0;

offsets.push_back(offset);
}

data.resize_exact(offset);
}
catch (...)
{
/// We are doing resize_exact() of bigger values than we have, let's make sure that it will be correct (even in case of exceptions)
data.resize_exact(offsets.back());
throw;
}


void SerializationString::deserializeBinaryBulk(IColumn & column, ReadBuffer & istr, size_t limit, double avg_value_size_hint) const
Expand Down
13 changes: 12 additions & 1 deletion src/Interpreters/tests/gtest_filecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <thread>

#include <Core/ServerUUID.h>
#include <Common/ThreadStatus.h>
#include <Common/iota.h>
#include <Common/randomSeed.h>
#include <DataTypes/DataTypesNumber.h>
Expand Down Expand Up @@ -286,7 +287,11 @@ void increasePriority(const HolderPtr & holder, size_t pos)
class FileCacheTest : public ::testing::Test
{
public:
FileCacheTest() {
FileCacheTest()
{
/// Reset current_thread to avoid conflicts of ThreadStatus with MainThreadStatus
current_thread = nullptr;

/// Context has to be created before calling cache.initialize();
/// Otherwise the tests which run before FileCacheTest.get are failed
/// It is logical to call destroyContext() at destructor.
Expand All @@ -295,6 +300,12 @@ class FileCacheTest : public ::testing::Test
getContext();
}

~FileCacheTest() override
{
/// Reset current_thread back
current_thread = MainThreadStatus::get();
}

static void setupLogs(const std::string & level)
{
Poco::AutoPtr<Poco::ConsoleChannel> channel(new Poco::ConsoleChannel(std::cerr));
Expand Down
Loading