aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-09-15 18:29:54 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-09-15 18:29:54 +0000
commitfbc9f364526587b0f312ef186e619a1f53c00617 (patch)
tree140d6237d7de933da0b5ea4011742b2276dea58b /searchcore
parent7ecd25a81bb636174954da2caa8255cc1f7b3515 (diff)
Avoid a lookup and copying a shared_ptr by looking up and using the domain directly.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt1
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/documentdb.cpp4
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/documentdb.h4
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp59
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/feedhandler.h23
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/tlcproxy.cpp33
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/tlcproxy.h27
7 files changed, 53 insertions, 98 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt
index 0a3c1015d3a..e81bb3c0037 100644
--- a/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt
+++ b/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt
@@ -100,7 +100,6 @@ vespa_add_library(searchcore_server STATIC
storeonlyfeedview.cpp
summaryadapter.cpp
threading_service_config.cpp
- tlcproxy.cpp
tlssyncer.cpp
transactionlogmanager.cpp
transactionlogmanagerbase.cpp
diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp
index 3e09dd48858..46bcb0e49bb 100644
--- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp
@@ -120,7 +120,7 @@ DocumentDB::DocumentDB(const vespalib::string &baseDir,
IDocumentDBOwner &owner,
vespalib::SyncableThreadExecutor &warmupExecutor,
vespalib::ThreadStackExecutorBase &sharedExecutor,
- search::transactionlog::Writer &tlsDirectWriter,
+ const search::transactionlog::WriterFactory &tlsWriterFactory,
MetricsWireService &metricsWireService,
const FileHeaderContext &fileHeaderContext,
ConfigStore::UP config_store,
@@ -167,7 +167,7 @@ DocumentDB::DocumentDB(const vespalib::string &baseDir,
_dmUsageForwarder(_writeService.master()),
_writeFilter(),
_transient_memory_usage_provider(std::make_shared<TransientMemoryUsageProvider>()),
- _feedHandler(std::make_unique<FeedHandler>(_writeService, tlsSpec, docTypeName, *this, _writeFilter, *this, tlsDirectWriter)),
+ _feedHandler(std::make_unique<FeedHandler>(_writeService, tlsSpec, docTypeName, *this, _writeFilter, *this, tlsWriterFactory)),
_visibility(*_feedHandler, _writeService, _feedView),
_subDBs(*this, *this, *_feedHandler, _docTypeName, _writeService, warmupExecutor, fileHeaderContext,
metricsWireService, getMetrics(), queryLimiter, clock, _configMutex, _baseDir,
diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.h b/searchcore/src/vespa/searchcore/proton/server/documentdb.h
index 5df9a633676..b0a928bb87d 100644
--- a/searchcore/src/vespa/searchcore/proton/server/documentdb.h
+++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.h
@@ -39,7 +39,7 @@ namespace search {
namespace common { class FileHeaderContext; }
namespace transactionlog {
class TransLogClient;
- class Writer;
+ class WriterFactory;
}
}
@@ -253,7 +253,7 @@ public:
IDocumentDBOwner &owner,
vespalib::SyncableThreadExecutor &warmupExecutor,
vespalib::ThreadStackExecutorBase &sharedExecutor,
- search::transactionlog::Writer &tlsDirectWriter,
+ const search::transactionlog::WriterFactory &tlsWriterFactory,
MetricsWireService &metricsWireService,
const search::common::FileHeaderContext &fileHeaderContext,
ConfigStore::UP config_store,
diff --git a/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp b/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp
index 8a117f112b4..3ab5d1ca065 100644
--- a/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp
@@ -5,7 +5,6 @@
#include "feedstates.h"
#include "i_feed_handler_owner.h"
#include "ifeedview.h"
-#include "tlcproxy.h"
#include "configstore.h"
#include <vespa/document/base/exceptions.h>
#include <vespa/document/datatype/documenttype.h>
@@ -47,22 +46,45 @@ namespace proton {
namespace {
+using search::SerialNum;
+
bool
ignoreOperation(const DocumentOperation &op) {
return (op.getPrevTimestamp() != 0) && (op.getTimestamp() < op.getPrevTimestamp());
}
-} // namespace
-
-void FeedHandler::TlsMgrWriter::storeOperation(const FeedOperation &op, DoneCallback onDone) {
- TlcProxy(_tls_mgr.getDomainName(), *_tlsDirectWriter).storeOperation(op, std::move(onDone));
-}
-bool FeedHandler::TlsMgrWriter::erase(SerialNum oldest_to_keep) {
+class TlsMgrWriter : public TlsWriter {
+ TransactionLogManager &_tls_mgr;
+ std::shared_ptr<search::transactionlog::Writer> _writer;
+public:
+ TlsMgrWriter(TransactionLogManager &tls_mgr,
+ const search::transactionlog::WriterFactory & factory) :
+ _tls_mgr(tls_mgr),
+ _writer(factory.getWriter(tls_mgr.getDomainName()))
+ { }
+ void storeOperation(const FeedOperation &op, DoneCallback onDone) override;
+ bool erase(SerialNum oldest_to_keep) override;
+ SerialNum sync(SerialNum syncTo) override;
+};
+
+
+void TlsMgrWriter::storeOperation(const FeedOperation &op, DoneCallback onDone) {
+ using Packet = search::transactionlog::Packet;
+ vespalib::nbostream stream;
+ op.serialize(stream);
+ LOG(debug, "storeOperation(): serialNum(%" PRIu64 "), type(%u), size(%zu)",
+ op.getSerialNum(), (uint32_t)op.getType(), stream.size());
+ Packet::Entry entry(op.getSerialNum(), op.getType(), vespalib::ConstBufferRef(stream.data(), stream.size()));
+ Packet packet(entry.serializedSize());
+ packet.add(entry);
+ _writer->commit(packet, std::move(onDone));
+}
+bool TlsMgrWriter::erase(SerialNum oldest_to_keep) {
return _tls_mgr.getSession()->erase(oldest_to_keep);
}
-search::SerialNum
-FeedHandler::TlsMgrWriter::sync(SerialNum syncTo)
+SerialNum
+TlsMgrWriter::sync(SerialNum syncTo)
{
for (int retryCount = 0; retryCount < 10; ++retryCount) {
SerialNum syncedTo(0);
@@ -82,6 +104,8 @@ FeedHandler::TlsMgrWriter::sync(SerialNum syncTo)
throw IllegalStateException(make_string("Failed to sync TLS to token %" PRIu64 ".", syncTo));
}
+} // namespace
+
void
FeedHandler::doHandleOperation(FeedToken token, FeedOperation::UP op)
{
@@ -330,7 +354,7 @@ FeedHandler::FeedHandler(IThreadingService &writeService,
IFeedHandlerOwner &owner,
const IResourceWriteFilter &writeFilter,
IReplayConfig &replayConfig,
- search::transactionlog::Writer & tlsDirectWriter,
+ const TlsWriterFactory & tlsWriterFactory,
TlsWriter * tlsWriter)
: search::transactionlog::client::Callback(),
IDocumentMoveHandler(),
@@ -344,8 +368,9 @@ FeedHandler::FeedHandler(IThreadingService &writeService,
_writeFilter(writeFilter),
_replayConfig(replayConfig),
_tlsMgr(tlsSpec, docTypeName.getName()),
- _tlsMgrWriter(_tlsMgr, &tlsDirectWriter),
- _tlsWriter(tlsWriter ? *tlsWriter : _tlsMgrWriter),
+ _tlsWriterfactory(tlsWriterFactory),
+ _tlsMgrWriter(),
+ _tlsWriter(tlsWriter),
_tlsReplayProgress(),
_serialNum(0),
_prunedSerialNum(0),
@@ -369,6 +394,10 @@ void
FeedHandler::init(SerialNum oldestConfigSerial)
{
_tlsMgr.init(oldestConfigSerial, _prunedSerialNum, _serialNum);
+ if (_tlsWriter == nullptr) {
+ _tlsMgrWriter = std::make_unique<TlsMgrWriter>(_tlsMgr, _tlsWriterfactory);
+ _tlsWriter = _tlsMgrWriter.get();
+ }
_allowSync = true;
syncTls(_serialNum);
}
@@ -442,7 +471,7 @@ FeedHandler::storeOperation(const FeedOperation &op, TlsWriter::DoneCallback onD
if (!op.getSerialNum()) {
const_cast<FeedOperation &>(op).setSerialNum(incSerialNum());
}
- _tlsWriter.storeOperation(op, std::move(onDone));
+ _tlsWriter->storeOperation(op, std::move(onDone));
}
void
@@ -454,7 +483,7 @@ FeedHandler::storeOperationSync(const FeedOperation &op) {
void
FeedHandler::tlsPrune(SerialNum oldest_to_keep) {
- if (!_tlsWriter.erase(oldest_to_keep)) {
+ if (!_tlsWriter->erase(oldest_to_keep)) {
throw IllegalStateException(make_string("Failed to prune TLS to token %" PRIu64 ".", oldest_to_keep));
}
_prunedSerialNum = oldest_to_keep;
@@ -666,7 +695,7 @@ FeedHandler::syncTls(SerialNum syncTo)
if (!_allowSync) {
throw IllegalStateException(make_string("Attempted to sync TLS to token %" PRIu64 " at wrong time.", syncTo));
}
- SerialNum syncedTo(_tlsWriter.sync(syncTo));
+ SerialNum syncedTo(_tlsWriter->sync(syncTo));
{
std::lock_guard<std::mutex> guard(_syncLock);
if (_syncedSerialNum < syncedTo)
diff --git a/searchcore/src/vespa/searchcore/proton/server/feedhandler.h b/searchcore/src/vespa/searchcore/proton/server/feedhandler.h
index d70cefb288b..823361f8737 100644
--- a/searchcore/src/vespa/searchcore/proton/server/feedhandler.h
+++ b/searchcore/src/vespa/searchcore/proton/server/feedhandler.h
@@ -61,21 +61,7 @@ private:
using ReadGuard = std::shared_lock<std::shared_mutex>;
using WriteGuard = std::unique_lock<std::shared_mutex>;
using IThreadingService = searchcorespi::index::IThreadingService;
-
-
- class TlsMgrWriter : public TlsWriter {
- TransactionLogManager &_tls_mgr;
- search::transactionlog::Writer *_tlsDirectWriter;
- public:
- TlsMgrWriter(TransactionLogManager &tls_mgr,
- search::transactionlog::Writer * tlsDirectWriter) :
- _tls_mgr(tls_mgr),
- _tlsDirectWriter(tlsDirectWriter)
- { }
- void storeOperation(const FeedOperation &op, DoneCallback onDone) override;
- bool erase(SerialNum oldest_to_keep) override;
- SerialNum sync(SerialNum syncTo) override;
- };
+ using TlsWriterFactory = search::transactionlog::WriterFactory;
IThreadingService &_writeService;
DocTypeName _docTypeName;
@@ -83,8 +69,9 @@ private:
const IResourceWriteFilter &_writeFilter;
IReplayConfig &_replayConfig;
TransactionLogManager _tlsMgr;
- TlsMgrWriter _tlsMgrWriter;
- TlsWriter &_tlsWriter;
+ const TlsWriterFactory &_tlsWriterfactory;
+ std::unique_ptr<TlsWriter> _tlsMgrWriter;
+ TlsWriter *_tlsWriter;
TlsReplayProgress::UP _tlsReplayProgress;
// the serial num of the last message in the transaction log
SerialNum _serialNum;
@@ -157,7 +144,7 @@ public:
IFeedHandlerOwner &owner,
const IResourceWriteFilter &writerFilter,
IReplayConfig &replayConfig,
- search::transactionlog::Writer & writer,
+ const TlsWriterFactory & writer,
TlsWriter * tlsWriter = nullptr);
~FeedHandler() override;
diff --git a/searchcore/src/vespa/searchcore/proton/server/tlcproxy.cpp b/searchcore/src/vespa/searchcore/proton/server/tlcproxy.cpp
deleted file mode 100644
index baba74c482c..00000000000
--- a/searchcore/src/vespa/searchcore/proton/server/tlcproxy.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "tlcproxy.h"
-#include <vespa/searchcore/proton/feedoperation/feedoperation.h>
-
-#include <vespa/log/log.h>
-LOG_SETUP(".proton.server.tlcproxy");
-
-using vespalib::nbostream;
-using search::transactionlog::Packet;
-
-namespace proton {
-
-void TlcProxy::commit(search::SerialNum serialNum, search::transactionlog::Type type,
- const vespalib::nbostream &buf, DoneCallback onDone)
-{
- Packet::Entry entry(serialNum, type, vespalib::ConstBufferRef(buf.data(), buf.size()));
- Packet packet(entry.serializedSize());
- packet.add(entry);
- _tlsDirectWriter.commit(_domain, packet, std::move(onDone));
-}
-
-void
-TlcProxy::storeOperation(const FeedOperation &op, DoneCallback onDone)
-{
- nbostream stream;
- op.serialize(stream);
- LOG(debug, "storeOperation(): serialNum(%" PRIu64 "), type(%u), size(%zu)",
- op.getSerialNum(), (uint32_t)op.getType(), stream.size());
- commit(op.getSerialNum(), (uint32_t)op.getType(), stream, std::move(onDone));
-}
-
-} // namespace proton
diff --git a/searchcore/src/vespa/searchcore/proton/server/tlcproxy.h b/searchcore/src/vespa/searchcore/proton/server/tlcproxy.h
deleted file mode 100644
index 2dc6501731e..00000000000
--- a/searchcore/src/vespa/searchcore/proton/server/tlcproxy.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include <vespa/searchlib/transactionlog/common.h>
-
-namespace proton {
-
-class FeedOperation;
-
-class TlcProxy {
- using DoneCallback = search::transactionlog::Writer::DoneCallback;
- using Writer = search::transactionlog::Writer;
- vespalib::string _domain;
- Writer & _tlsDirectWriter;
-
- void commit(search::SerialNum serialNum, search::transactionlog::Type type,
- const vespalib::nbostream &buf, DoneCallback onDone);
-public:
- typedef std::unique_ptr<TlcProxy> UP;
-
- TlcProxy(const vespalib::string & domain, Writer & writer)
- : _domain(domain), _tlsDirectWriter(writer) {}
-
- void storeOperation(const FeedOperation &op, DoneCallback onDone);
-};
-
-} // namespace proton