aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-09-26 18:38:58 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-09-26 18:38:58 +0000
commit4ada4ab6551d15432749b4b06d838194297f687d (patch)
treef583b018daae2b566ef39d08c4539693ec60c2d7
parent69655b7a638e3588b46cbed18d9a644d8b82d9ed (diff)
Replace the dangerous stealBuffer method with a static one that requires std::move to make destruction more visible.
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcsendv2.cpp10
-rw-r--r--searchcore/src/apps/vespa-feed-bm/storage_api_rpc_bm_feed_handler.cpp8
-rw-r--r--searchlib/src/tests/attribute/attributefilewriter/attributefilewriter_test.cpp2
-rw-r--r--searchlib/src/tests/attribute/enumeratedsave/enumeratedsave_test.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributefilebufferwriter.cpp1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributefilewriter.cpp1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributememoryfilebufferwriter.cpp5
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributememoryfilewriter.cpp5
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attrvector.cpp1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/iattributefilewriter.h3
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlenumericattributesaver.cpp1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp1
-rw-r--r--searchlib/src/vespa/searchlib/docstore/chunkformat.cpp3
-rw-r--r--searchlib/src/vespa/searchlib/docstore/value.cpp7
-rw-r--r--searchlib/src/vespa/searchlib/docstore/visitcache.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/transactionlog/chunks.cpp2
-rw-r--r--storage/src/tests/storageserver/rpc/cluster_controller_rpc_api_service_test.cpp3
-rw-r--r--storage/src/vespa/storage/storageserver/rpc/storage_api_rpc_service.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/data/databuffer.h5
20 files changed, 39 insertions, 26 deletions
diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp b/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp
index 6afa1528092..4c5b93048bf 100644
--- a/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp
+++ b/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp
@@ -4,7 +4,6 @@
#include "rpcnetwork.h"
#include "rpcserviceaddress.h"
#include <vespa/messagebus/emptyreply.h>
-#include <vespa/messagebus/tracelevel.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/data/slime/slime.h>
#include <vespa/vespalib/data/databuffer.h>
@@ -49,7 +48,8 @@ Memory SERVICE_F("service");
}
-bool RPCSendV2::isCompatible(stringref method, stringref request, stringref response)
+bool
+RPCSendV2::isCompatible(stringref method, stringref request, stringref response)
{
return (method == METHOD_NAME) &&
(request == METHOD_PARAMS) &&
@@ -133,7 +133,7 @@ RPCSendV2::encodeRequest(FRT_RPCRequest &req, const Version &version, const Rout
args.AddInt32(toCompress.size());
const auto bufferLength = buf.getDataLen();
assert(bufferLength <= INT32_MAX);
- args.AddData(buf.stealBuffer(), bufferLength);
+ args.AddData(DataBuffer::stealBuffer(std::move(buf)), bufferLength);
}
namespace {
@@ -141,7 +141,7 @@ namespace {
class ParamsV2 : public RPCSend::Params
{
public:
- ParamsV2(const FRT_Values &arg)
+ explicit ParamsV2(const FRT_Values &arg)
: _slime()
{
uint8_t encoding = arg[3]._intval8;
@@ -263,7 +263,7 @@ RPCSendV2::createResponse(FRT_Values & ret, const string & version, Reply & repl
ret.AddInt32(toCompress.size());
const auto bufferLength = buf.getDataLen();
assert(bufferLength <= INT32_MAX);
- ret.AddData(buf.stealBuffer(), bufferLength);
+ ret.AddData(DataBuffer::stealBuffer(std::move(buf)), bufferLength);
}
diff --git a/searchcore/src/apps/vespa-feed-bm/storage_api_rpc_bm_feed_handler.cpp b/searchcore/src/apps/vespa-feed-bm/storage_api_rpc_bm_feed_handler.cpp
index e2f3a951b99..f8952363509 100644
--- a/searchcore/src/apps/vespa-feed-bm/storage_api_rpc_bm_feed_handler.cpp
+++ b/searchcore/src/apps/vespa-feed-bm/storage_api_rpc_bm_feed_handler.cpp
@@ -32,7 +32,8 @@ namespace feedbm {
namespace {
-FRT_RPCRequest *make_set_cluster_state_request() {
+FRT_RPCRequest *
+make_set_cluster_state_request() {
storage::lib::ClusterStateBundle bundle(storage::lib::ClusterState("version:2 distributor:1 storage:1"));
storage::rpc::SlimeClusterStateBundleCodec codec;
auto encoded_bundle = codec.encode(bundle);
@@ -41,12 +42,13 @@ FRT_RPCRequest *make_set_cluster_state_request() {
params->AddInt8(static_cast<uint8_t>(encoded_bundle._compression_type));
params->AddInt32(encoded_bundle._uncompressed_length);
const auto buf_len = encoded_bundle._buffer->getDataLen();
- params->AddData(encoded_bundle._buffer->stealBuffer(), buf_len);
+ params->AddData(vespalib::DataBuffer::stealBuffer(std::move(*encoded_bundle._buffer)), buf_len);
req->SetMethodName("setdistributionstates");
return req;
}
-void set_cluster_up(SharedRpcResources &shared_rpc_resources, storage::api::StorageMessageAddress &storage_address) {
+void
+set_cluster_up(SharedRpcResources &shared_rpc_resources, storage::api::StorageMessageAddress &storage_address) {
auto req = make_set_cluster_state_request();
auto target_resolver = std::make_unique<storage::rpc::CachingRpcTargetResolver>(shared_rpc_resources.slobrok_mirror(), shared_rpc_resources.target_factory());
auto target = target_resolver->resolve_rpc_target(storage_address);
diff --git a/searchlib/src/tests/attribute/attributefilewriter/attributefilewriter_test.cpp b/searchlib/src/tests/attribute/attributefilewriter/attributefilewriter_test.cpp
index eeabbf23c27..1e3531dc78e 100644
--- a/searchlib/src/tests/attribute/attributefilewriter/attributefilewriter_test.cpp
+++ b/searchlib/src/tests/attribute/attributefilewriter/attributefilewriter_test.cpp
@@ -1,7 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/testapp.h>
-#include <vespa/vespalib/stllike/string.h>
#include <vespa/searchlib/attribute/attributefilewriter.h>
#include <vespa/searchlib/attribute/attributefilebufferwriter.h>
#include <vespa/searchlib/attribute/attribute_header.h>
@@ -10,6 +9,7 @@
#include <vespa/searchlib/common/tunefileinfo.h>
#include <vespa/searchlib/common/fileheadercontext.h>
#include <vespa/searchlib/index/dummyfileheadercontext.h>
+#include <vespa/vespalib/data/databuffer.h>
#include <vespa/fastos/file.h>
#include <vespa/log/log.h>
diff --git a/searchlib/src/tests/attribute/enumeratedsave/enumeratedsave_test.cpp b/searchlib/src/tests/attribute/enumeratedsave/enumeratedsave_test.cpp
index d8761f69d71..2a5b8014299 100644
--- a/searchlib/src/tests/attribute/enumeratedsave/enumeratedsave_test.cpp
+++ b/searchlib/src/tests/attribute/enumeratedsave/enumeratedsave_test.cpp
@@ -10,7 +10,6 @@
#include <vespa/searchlib/attribute/attributememorysavetarget.h>
#include <vespa/searchlib/attribute/attributesaver.h>
#include <vespa/searchlib/attribute/multinumericattribute.h>
-#include <vespa/searchlib/attribute/multistringattribute.h>
#include <vespa/searchlib/attribute/singlenumericattribute.h>
#include <vespa/searchlib/attribute/singlestringattribute.h>
#include <vespa/searchlib/queryeval/executeinfo.h>
@@ -21,6 +20,7 @@
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/searchlib/util/bufferwriter.h>
#include <vespa/vespalib/util/compress.h>
+#include <vespa/vespalib/data/databuffer.h>
#include <vespa/searchlib/attribute/attributevector.hpp>
diff --git a/searchlib/src/vespa/searchlib/attribute/attributefilebufferwriter.cpp b/searchlib/src/vespa/searchlib/attribute/attributefilebufferwriter.cpp
index 341112f9b22..4efd64f72dd 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributefilebufferwriter.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributefilebufferwriter.cpp
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "attributefilebufferwriter.h"
+#include <vespa/vespalib/data/databuffer.h>
namespace search {
diff --git a/searchlib/src/vespa/searchlib/attribute/attributefilewriter.cpp b/searchlib/src/vespa/searchlib/attribute/attributefilewriter.cpp
index 415c00cb8fd..829720e9c3e 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributefilewriter.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributefilewriter.cpp
@@ -6,6 +6,7 @@
#include <vespa/vespalib/data/fileheader.h>
#include <vespa/searchlib/common/fileheadercontext.h>
#include <vespa/searchlib/common/tunefileinfo.h>
+#include <vespa/vespalib/data/databuffer.h>
#include <vespa/fastos/file.h>
#include <vespa/log/log.h>
diff --git a/searchlib/src/vespa/searchlib/attribute/attributememoryfilebufferwriter.cpp b/searchlib/src/vespa/searchlib/attribute/attributememoryfilebufferwriter.cpp
index b354566616b..454cc486f70 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributememoryfilebufferwriter.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributememoryfilebufferwriter.cpp
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "attributememoryfilebufferwriter.h"
+#include <vespa/vespalib/data/databuffer.h>
namespace search {
@@ -11,9 +12,7 @@ AttributeMemoryFileBufferWriter(IAttributeFileWriter &memoryFileWriter)
}
-AttributeMemoryFileBufferWriter::~AttributeMemoryFileBufferWriter()
-{
-}
+AttributeMemoryFileBufferWriter::~AttributeMemoryFileBufferWriter() = default;
void
diff --git a/searchlib/src/vespa/searchlib/attribute/attributememoryfilewriter.cpp b/searchlib/src/vespa/searchlib/attribute/attributememoryfilewriter.cpp
index c28b7e9d20b..8d412364815 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributememoryfilewriter.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributememoryfilewriter.cpp
@@ -2,6 +2,7 @@
#include "attributememoryfilewriter.h"
#include "attributememoryfilebufferwriter.h"
+#include <vespa/vespalib/data/databuffer.h>
namespace search {
@@ -18,9 +19,7 @@ AttributeMemoryFileWriter::AttributeMemoryFileWriter()
}
-AttributeMemoryFileWriter::~AttributeMemoryFileWriter()
-{
-}
+AttributeMemoryFileWriter::~AttributeMemoryFileWriter() = default;
AttributeMemoryFileWriter::Buffer
diff --git a/searchlib/src/vespa/searchlib/attribute/attrvector.cpp b/searchlib/src/vespa/searchlib/attribute/attrvector.cpp
index 59771d7ffae..80f72aaea25 100644
--- a/searchlib/src/vespa/searchlib/attribute/attrvector.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attrvector.cpp
@@ -4,6 +4,7 @@
#include "attrvector.hpp"
#include "iattributesavetarget.h"
#include "load_utils.h"
+#include <vespa/vespalib/data/databuffer.h>
#include <vespa/log/log.h>
LOG_SETUP(".searchlib.attribute.attr_vector");
diff --git a/searchlib/src/vespa/searchlib/attribute/iattributefilewriter.h b/searchlib/src/vespa/searchlib/attribute/iattributefilewriter.h
index bb00124c9fc..94e16b37e9d 100644
--- a/searchlib/src/vespa/searchlib/attribute/iattributefilewriter.h
+++ b/searchlib/src/vespa/searchlib/attribute/iattributefilewriter.h
@@ -2,8 +2,9 @@
#pragma once
-#include <vespa/vespalib/data/databuffer.h>
+#include <memory>
+namespace vespalib { class DataBuffer; }
namespace search {
class BufferWriter;
diff --git a/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp b/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp
index e1ab47ed434..bbe8c9c8327 100644
--- a/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp
@@ -8,6 +8,7 @@
#include <vespa/searchlib/query/query_term_simple.h>
#include <vespa/searchlib/queryeval/emptysearch.h>
#include <vespa/searchlib/common/bitvectoriterator.h>
+#include <vespa/vespalib/data/databuffer.h>
namespace search {
diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericattributesaver.cpp b/searchlib/src/vespa/searchlib/attribute/singlenumericattributesaver.cpp
index db8636f47c3..3c26e960a06 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlenumericattributesaver.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlenumericattributesaver.cpp
@@ -2,6 +2,7 @@
#include "singlenumericattributesaver.h"
#include "iattributesavetarget.h"
+#include <vespa/vespalib/data/databuffer.h>
using vespalib::GenerationHandler;
diff --git a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp
index 6eff0da06e8..fd2631ac63d 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp
@@ -7,6 +7,7 @@
#include "iattributesavetarget.h"
#include <vespa/searchlib/query/query_term_simple.h>
#include <vespa/searchlib/queryeval/emptysearch.h>
+#include <vespa/vespalib/data/databuffer.h>
namespace search {
diff --git a/searchlib/src/vespa/searchlib/docstore/chunkformat.cpp b/searchlib/src/vespa/searchlib/docstore/chunkformat.cpp
index fbbdcff3c5d..e9689e36180 100644
--- a/searchlib/src/vespa/searchlib/docstore/chunkformat.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/chunkformat.cpp
@@ -12,6 +12,7 @@ using vespalib::compression::compress;
using vespalib::compression::decompress;
using vespalib::compression::computeMaxCompressedsize;
using vespalib::compression::CompressionConfig;
+using vespalib::DataBuffer;
ChunkException::ChunkException(const vespalib::string & msg, vespalib::stringref location) :
Exception(make_string("Illegal chunk: %s", msg.c_str()), location)
@@ -140,7 +141,7 @@ ChunkFormat::deserializeBody(vespalib::nbostream & is)
assert(uncompressed.getData() == uncompressed.getDead());
if (uncompressed.getData() != data.c_str()) {
const size_t sz(uncompressed.getDataLen());
- vespalib::nbostream(uncompressed.stealBuffer(), sz).swap(_dataBuf);
+ vespalib::nbostream(DataBuffer::stealBuffer(std::move(uncompressed)), sz).swap(_dataBuf);
} else {
_dataBuf = vespalib::nbostream(uncompressed.getData(), uncompressed.getDataLen());
}
diff --git a/searchlib/src/vespa/searchlib/docstore/value.cpp b/searchlib/src/vespa/searchlib/docstore/value.cpp
index 09725b447cd..40d04b3d7fb 100644
--- a/searchlib/src/vespa/searchlib/docstore/value.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/value.cpp
@@ -1,12 +1,12 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "value.h"
-#include <vespa/vespalib/data/databuffer.h>
#include <vespa/vespalib/util/compressor.h>
#include <xxhash.h>
using vespalib::compression::compress;
using vespalib::compression::decompress;
+using vespalib::DataBuffer;
namespace search::docstore {
@@ -66,8 +66,9 @@ Value::set(vespalib::DataBuffer &&buf, ssize_t len, const CompressionConfig &com
_compression = type;
_uncompressedSize = len;
_uncompressedCrc = XXH64(input.c_str(), input.size(), 0);
- _buf = std::make_shared<Alloc>(compact(_compressedSize,
- (buf.getData() == compressed.getData()) ? buf.stealBuffer() : compressed.stealBuffer()));
+ _buf = std::make_shared<Alloc>(compact(_compressedSize,(buf.getData() == compressed.getData())
+ ? DataBuffer::stealBuffer(std::move(buf))
+ : DataBuffer::stealBuffer(std::move(compressed))));
assert(((type == CompressionConfig::NONE) &&
(len == ssize_t(_compressedSize))) ||
diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
index e8504480b7d..dada57c15b9 100644
--- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
@@ -109,7 +109,7 @@ CompressedBlobSet::getBlobSet() const
decompress(_compression, getBufferSize(_positions),
ConstBufferRef(_buffer->c_str(), _buffer->size()), uncompressed, false);
}
- return BlobSet(_positions, uncompressed.stealBuffer());
+ return BlobSet(_positions, DataBuffer::stealBuffer(std::move(uncompressed)));
}
size_t CompressedBlobSet::size() const {
diff --git a/searchlib/src/vespa/searchlib/transactionlog/chunks.cpp b/searchlib/src/vespa/searchlib/transactionlog/chunks.cpp
index a78db61429d..b06ff9397c4 100644
--- a/searchlib/src/vespa/searchlib/transactionlog/chunks.cpp
+++ b/searchlib/src/vespa/searchlib/transactionlog/chunks.cpp
@@ -94,7 +94,7 @@ XXH64CompressedChunk::decompress(nbostream & is, uint32_t uncompressedLen) {
::decompress(_type, uncompressedLen, compressed, uncompressed, false);
nbostream data(uncompressed.getData(), uncompressed.getDataLen());
deserializeEntries(data);
- _backing = uncompressed.stealBuffer();
+ _backing = DataBuffer::stealBuffer(std::move(uncompressed));
is.adjustReadPos(is.size());
}
diff --git a/storage/src/tests/storageserver/rpc/cluster_controller_rpc_api_service_test.cpp b/storage/src/tests/storageserver/rpc/cluster_controller_rpc_api_service_test.cpp
index 09c9ddb1f72..a65e8678a72 100644
--- a/storage/src/tests/storageserver/rpc/cluster_controller_rpc_api_service_test.cpp
+++ b/storage/src/tests/storageserver/rpc/cluster_controller_rpc_api_service_test.cpp
@@ -15,6 +15,7 @@
#include <vespa/vespalib/gtest/gtest.h>
#include <vector>
+using vespalib::DataBuffer;
namespace storage::rpc {
using document::FixedBucketSpaces;
@@ -83,7 +84,7 @@ struct SetStateFixture : FixtureBase {
params->AddInt8(static_cast<uint8_t>(encoded_bundle._compression_type));
params->AddInt32(uncompressed_length);
const auto buf_len = encoded_bundle._buffer->getDataLen();
- params->AddData(encoded_bundle._buffer->stealBuffer(), buf_len);
+ params->AddData(DataBuffer::stealBuffer(std::move(*encoded_bundle._buffer)), buf_len);
bound_request->SetDetachedPT(&request_is_detached);
bound_request->SetReturnHandler(&return_handler);
diff --git a/storage/src/vespa/storage/storageserver/rpc/storage_api_rpc_service.cpp b/storage/src/vespa/storage/storageserver/rpc/storage_api_rpc_service.cpp
index ac6cae9be6b..42af872da9b 100644
--- a/storage/src/vespa/storage/storageserver/rpc/storage_api_rpc_service.cpp
+++ b/storage/src/vespa/storage/storageserver/rpc/storage_api_rpc_service.cpp
@@ -118,7 +118,7 @@ void compress_and_add_payload_to_rpc_params(mbus::BlobRef payload,
params.AddInt8(comp_type);
params.AddInt32(static_cast<uint32_t>(to_compress.size()));
auto buffer_len = buf.getDataLen();
- params.AddData(buf.stealBuffer(), buffer_len);
+ params.AddData(vespalib::DataBuffer::stealBuffer(std::move(buf)), buffer_len);
}
} // anon ns
diff --git a/vespalib/src/vespa/vespalib/data/databuffer.h b/vespalib/src/vespa/vespalib/data/databuffer.h
index a520ecd58bd..e1c21661716 100644
--- a/vespalib/src/vespa/vespalib/data/databuffer.h
+++ b/vespalib/src/vespa/vespalib/data/databuffer.h
@@ -40,6 +40,7 @@ private:
char *_freept;
Alloc _buffer;
+ Alloc stealBuffer();
public:
typedef std::unique_ptr<DataBuffer> UP;
DataBuffer(const DataBuffer &) = delete;
@@ -606,7 +607,9 @@ public:
**/
void swap(DataBuffer &other);
- Alloc stealBuffer();
+ static Alloc stealBuffer(DataBuffer buf) {
+ return buf.stealBuffer();
+ }
};
} // namespace vespalib