diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-08-23 22:12:04 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-08-23 22:12:04 +0200 |
commit | 6de25379358e678731be30195c876dd99d14ec20 (patch) | |
tree | 5f648046ed8f678fa6223905893b57bb97b25f5f | |
parent | efa813a34dc4decad2b145002798b9207e9753b8 (diff) |
Use nested namespace for search::transactionlog
16 files changed, 63 insertions, 105 deletions
diff --git a/searchlib/src/vespa/searchlib/transactionlog/common.cpp b/searchlib/src/vespa/searchlib/transactionlog/common.cpp index 8dd4d7abbcc..a84e27b2e53 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/common.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/common.cpp @@ -3,9 +3,7 @@ #include "common.h" #include <vespa/fastos/file.h> -namespace search { - -namespace transactionlog { +namespace search::transactionlog { using vespalib::nbostream; using vespalib::nbostream_longlivedbuf; @@ -104,4 +102,3 @@ bool Packet::add(const Packet::Entry & e) } } -} diff --git a/searchlib/src/vespa/searchlib/transactionlog/domain.cpp b/searchlib/src/vespa/searchlib/transactionlog/domain.cpp index 8477098ccc8..a324e42ab24 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/domain.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/domain.cpp @@ -3,6 +3,7 @@ #include "domain.h" #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/closuretask.h> +#include <vespa/fastos/file.h> #include <vespa/log/log.h> LOG_SETUP(".transactionlog.domain"); diff --git a/searchlib/src/vespa/searchlib/transactionlog/domain.h b/searchlib/src/vespa/searchlib/transactionlog/domain.h index 8b64232b000..f70ce7654c1 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/domain.h +++ b/searchlib/src/vespa/searchlib/transactionlog/domain.h @@ -5,8 +5,7 @@ #include <vespa/searchlib/transactionlog/session.h> #include <vespa/vespalib/util/threadstackexecutor.h> -namespace search { -namespace transactionlog { +namespace search::transactionlog { struct PartInfo { SerialNumRange range; @@ -122,5 +121,3 @@ private: }; } -} - diff --git a/searchlib/src/vespa/searchlib/transactionlog/domainpart.cpp b/searchlib/src/vespa/searchlib/transactionlog/domainpart.cpp index bd09371181b..ebe3c07c1df 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/domainpart.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/domainpart.cpp @@ -7,8 +7,8 @@ #include <vespa/vespalib/data/fileheader.h> #include <vespa/searchlib/common/fileheadercontext.h> #include <vespa/fastlib/io/bufferedfile.h> -#include <vespa/log/log.h> +#include <vespa/log/log.h> LOG_SETUP(".transactionlog.domainpart"); using vespalib::make_string; @@ -23,13 +23,10 @@ using vespalib::alloc::Alloc; using search::common::FileHeaderContext; using std::runtime_error; -namespace search { - -namespace transactionlog { +namespace search::transactionlog { namespace { - void handleSync(FastOS_FileInterface &file) __attribute__ ((noinline)); @@ -186,7 +183,7 @@ DomainPart::buildPacketMapping(bool allowTruncate) { Fast_BufferedFile transLog; transLog.EnableDirectIO(); - if ( ! transLog.OpenReadOnly(_transLog.GetFileName())) { + if ( ! transLog.OpenReadOnly(_transLog->GetFileName())) { throw runtime_error(make_string("Failed opening '%s' for buffered readinf with direct io.", transLog.GetFileName())); } int64_t fSize(transLog.GetSize()); @@ -284,20 +281,20 @@ DomainPart::DomainPart(const string & name, _byteSize(0), _packets(), _fileName(make_string("%s/%s-%016" PRIu64, baseDir.c_str(), name.c_str(), s)), - _transLog(_fileName.c_str()), + _transLog(std::make_unique<FastOS_File>(_fileName.c_str())), _skipList(), _headerLen(0), _writeLock(), _writtenSerial(0), _syncedSerial(0) { - if (_transLog.OpenReadOnly()) { + if (_transLog->OpenReadOnly()) { int64_t currPos = buildPacketMapping(allowTruncate); - if ( ! _transLog.Close() ) { - throw runtime_error(make_string("Failed closing file '%s' after reading.", _transLog.GetFileName())); + if ( ! _transLog->Close() ) { + throw runtime_error(make_string("Failed closing file '%s' after reading.", _transLog->GetFileName())); } - if ( ! _transLog.OpenWriteOnlyExisting() ) { - string e(make_string("Failed opening existing file '%s' for writing: %s", _transLog.GetFileName(), getLastErrorString().c_str())); + if ( ! _transLog->OpenWriteOnlyExisting() ) { + string e(make_string("Failed opening existing file '%s' for writing: %s", _transLog->GetFileName(), getLastErrorString().c_str())); LOG(error, "%s", e.c_str()); throw runtime_error(e); } @@ -308,8 +305,8 @@ DomainPart::DomainPart(const string & name, } _byteSize = currPos; } else { - if ( ! _transLog.OpenWriteOnly()) { - string e(make_string("Failed opening new file '%s' for writing: '%s'", _transLog.GetFileName(), getLastErrorString().c_str())); + if ( ! _transLog->OpenWriteOnly()) { + string e(make_string("Failed opening new file '%s' for writing: '%s'", _transLog->GetFileName(), getLastErrorString().c_str())); LOG(error, "%s", e.c_str()); throw runtime_error(e); @@ -317,11 +314,11 @@ DomainPart::DomainPart(const string & name, writeHeader(fileHeaderContext); _byteSize = _headerLen; } - if ( ! _transLog.SetPosition(_transLog.GetSize()) ) { + if ( ! _transLog->SetPosition(_transLog->GetSize()) ) { throw runtime_error(make_string("Failed moving write pointer to the end of the file %s(%" PRIu64 ").", - _transLog.GetFileName(), _transLog.GetSize())); + _transLog->GetFileName(), _transLog->GetSize())); } - handleSync(_transLog); + handleSync(*_transLog); _writtenSerial = _range.to(); _syncedSerial = _writtenSerial; } @@ -336,12 +333,12 @@ DomainPart::writeHeader(const FileHeaderContext &fileHeaderContext) { typedef vespalib::GenericHeader::Tag Tag; FileHeader header; - assert(_transLog.IsOpened()); - assert(_transLog.IsWriteMode()); - assert(_transLog.GetPosition() == 0); - fileHeaderContext.addTags(header, _transLog.GetFileName()); + assert(_transLog->IsOpened()); + assert(_transLog->IsWriteMode()); + assert(_transLog->GetPosition() == 0); + fileHeaderContext.addTags(header, _transLog->GetFileName()); header.putTag(Tag("desc", "Transaction log domain part file")); - _headerLen = header.writeFile(_transLog); + _headerLen = header.writeFile(*_transLog); } bool @@ -355,15 +352,15 @@ DomainPart::close() * hole. XXX: Feed latency spike due to lack of delayed open * for new domainpart. */ - handleSync(_transLog); - _transLog.dropFromCache(); - retval = _transLog.Close(); + handleSync(*_transLog); + _transLog->dropFromCache(); + retval = _transLog->Close(); LockGuard wguard(_writeLock); _syncedSerial = _writtenSerial; } if ( ! retval ) { throw runtime_error(make_string("Failed closing file '%s' of size %" PRId64 ".", - _transLog.GetFileName(), _transLog.GetSize())); + _transLog->GetFileName(), _transLog->GetSize())); } { LockGuard guard(_lock); @@ -373,9 +370,14 @@ DomainPart::close() } bool +DomainPart::isClosed() const { + return ! _transLog->IsOpened(); +} + +bool DomainPart::openAndFind(FastOS_FileInterface &file, const SerialNum &from) { - bool retval(file.OpenReadOnly(_transLog.GetFileName())); + bool retval(file.OpenReadOnly(_transLog->GetFileName())); if (retval) { int64_t pos(_headerLen); LockGuard guard(_lock); @@ -396,7 +398,7 @@ DomainPart::erase(SerialNum to) bool retval(true); if (to > _range.to()) { close(); - _transLog.Delete(); + _transLog->Delete(); } else { _range.from(std::max(to, _range.from())); } @@ -406,7 +408,7 @@ DomainPart::erase(SerialNum to) void DomainPart::commit(SerialNum firstSerial, const Packet &packet) { - int64_t firstPos(_transLog.GetPosition()); + int64_t firstPos(_transLog->GetPosition()); nbostream_longlivedbuf h(packet.getHandle().c_str(), packet.getHandle().size()); if (_range.from() == 0) { _range.from(firstSerial); @@ -418,7 +420,7 @@ DomainPart::commit(SerialNum firstSerial, const Packet &packet) Packet::Entry entry; entry.deserialize(h); if (_range.to() < entry.serial()) { - write(_transLog, entry); + write(*_transLog, entry); _sz++; _range.to(entry.serial()); } else { @@ -456,7 +458,7 @@ void DomainPart::sync() syncSerial = _writtenSerial; } LockGuard guard(_fileLock); - handleSync(_transLog); + handleSync(*_transLog); LockGuard wguard(_writeLock); if (_syncedSerial < syncSerial) { _syncedSerial = syncSerial; @@ -674,4 +676,3 @@ int32_t DomainPart::calcCrc(Crc version, const void * buf, size_t sz) } } -} diff --git a/searchlib/src/vespa/searchlib/transactionlog/domainpart.h b/searchlib/src/vespa/searchlib/transactionlog/domainpart.h index 03d0ad2120f..2af0a43d03c 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/domainpart.h +++ b/searchlib/src/vespa/searchlib/transactionlog/domainpart.h @@ -2,18 +2,16 @@ #pragma once #include "common.h" +#include <vespa/vespalib/util/sync.h> +#include <vespa/vespalib/util/memory.h> #include <map> #include <vector> #include <atomic> -#include <vespa/vespalib/util/sync.h> -#include <vespa/vespalib/util/memory.h> -#include <vespa/fastos/file.h> -namespace search { +class FastOS_FileInterface; -namespace common { class FileHeaderContext; } - -namespace transactionlog { +namespace search::common { class FileHeaderContext; } +namespace search::transactionlog { class DomainPart { private: @@ -54,7 +52,7 @@ public: size_t byteSize() const { return _byteSize.load(std::memory_order_acquire); } - bool isClosed() const { return ! _transLog.IsOpened(); } + bool isClosed() const; private: bool openAndFind(FastOS_FileInterface &file, const SerialNum &from); int64_t buildPacketMapping(bool allowTruncate); @@ -101,7 +99,7 @@ private: std::atomic<uint64_t> _byteSize; PacketList _packets; vespalib::string _fileName; - FastOS_File _transLog; + std::unique_ptr<FastOS_FileInterface> _transLog; SkipList _skipList; uint32_t _headerLen; vespalib::Lock _writeLock; @@ -111,5 +109,3 @@ private: }; } -} - diff --git a/searchlib/src/vespa/searchlib/transactionlog/nosyncproxy.h b/searchlib/src/vespa/searchlib/transactionlog/nosyncproxy.h index 5d7d7ca3f64..d890495bb1b 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/nosyncproxy.h +++ b/searchlib/src/vespa/searchlib/transactionlog/nosyncproxy.h @@ -4,8 +4,7 @@ #include "syncproxy.h" -namespace search { -namespace transactionlog { +namespace search::transactionlog { class NoSyncProxy : public SyncProxy { @@ -16,4 +15,3 @@ public: }; } -} diff --git a/searchlib/src/vespa/searchlib/transactionlog/session.cpp b/searchlib/src/vespa/searchlib/transactionlog/session.cpp index f17b3cba6ad..302e0c12dda 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/session.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/session.cpp @@ -10,8 +10,7 @@ LOG_SETUP(".transactionlog.session"); using vespalib::LockGuard; -namespace search { -namespace transactionlog { +namespace search::transactionlog { namespace { const double NEVER(-1.0); @@ -281,4 +280,3 @@ Session::sendDone() } } -} diff --git a/searchlib/src/vespa/searchlib/transactionlog/session.h b/searchlib/src/vespa/searchlib/transactionlog/session.h index 1f5f1af9623..26e448540c3 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/session.h +++ b/searchlib/src/vespa/searchlib/transactionlog/session.h @@ -9,8 +9,7 @@ class FastOS_FileInterface; -namespace search { -namespace transactionlog { +namespace search::transactionlog { class Domain; class DomainPart; @@ -94,5 +93,3 @@ private: }; } -} - diff --git a/searchlib/src/vespa/searchlib/transactionlog/syncproxy.h b/searchlib/src/vespa/searchlib/transactionlog/syncproxy.h index 009e4d9de8e..a2623ea3236 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/syncproxy.h +++ b/searchlib/src/vespa/searchlib/transactionlog/syncproxy.h @@ -4,10 +4,7 @@ #include <vespa/searchlib/common/serialnum.h> -namespace search -{ -namespace transactionlog -{ +namespace search::transactionlog { class SyncProxy { @@ -17,6 +14,3 @@ public: }; } - -} - diff --git a/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp b/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp index 60efcf485d8..fe708f52a93 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp @@ -1,14 +1,14 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "trans_log_server_explorer.h" -#include "domain.h" #include <vespa/vespalib/data/slime/slime.h> +#include <vespa/fastos/file.h> + using vespalib::slime::Inserter; using vespalib::slime::Cursor; -namespace search { -namespace transactionlog { +namespace search::transactionlog { namespace { @@ -66,5 +66,4 @@ TransLogServerExplorer::get_child(vespalib::stringref name) const return std::unique_ptr<vespalib::StateExplorer>(new DomainExplorer(std::move(domain))); } -} // namespace search::transactionlog -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.h b/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.h index 9e125b2142e..65d3a687bc9 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.h +++ b/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.h @@ -5,8 +5,7 @@ #include "translogserver.h" #include <vespa/vespalib/net/state_explorer.h> -namespace search { -namespace transactionlog { +namespace search::transactionlog { /** * Class used to explore the state of a transaction log server. @@ -23,5 +22,4 @@ public: virtual std::unique_ptr<StateExplorer> get_child(vespalib::stringref name) const override; }; -} // namespace search::transactionlog -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/transactionlog/translogclient.cpp b/searchlib/src/vespa/searchlib/transactionlog/translogclient.cpp index 5af7c293916..af2e8ad47a1 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/translogclient.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/translogclient.cpp @@ -11,8 +11,7 @@ LOG_SETUP(".translogclient"); using namespace std::chrono_literals; -namespace search { -namespace transactionlog { +namespace search::transactionlog { namespace { const double NEVER(-1.0); @@ -408,4 +407,3 @@ TransLogClient::Visitor::~Visitor() } } -} diff --git a/searchlib/src/vespa/searchlib/transactionlog/translogserver.h b/searchlib/src/vespa/searchlib/transactionlog/translogserver.h index 6ae48cdfff6..e7aca212b07 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/translogserver.h +++ b/searchlib/src/vespa/searchlib/transactionlog/translogserver.h @@ -7,11 +7,9 @@ #include <vespa/fnet/frt/invokable.h> #include <mutex> -namespace search { +namespace search::common { class FileHeaderContext; } -namespace common { class FileHeaderContext; } - -namespace transactionlog { +namespace search::transactionlog { class TransLogServerExplorer; @@ -100,5 +98,3 @@ private: }; } -} - diff --git a/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.cpp b/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.cpp index fbc1694a8a0..b84d7854457 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.cpp @@ -8,8 +8,7 @@ LOG_SETUP(".translogserverapp"); using search::common::FileHeaderContext; -namespace search { -namespace transactionlog { +namespace search::transactionlog { TransLogServerApp::TransLogServerApp(const config::ConfigUri & tlsConfigUri, const FileHeaderContext & fileHeaderContext) @@ -40,14 +39,8 @@ DomainPart::Crc getCrc(searchlib::TranslogserverConfig::Crcmethod crcType) void TransLogServerApp::start() { std::shared_ptr<searchlib::TranslogserverConfig> c = _tlsConfig.get(); - _tls.reset(new TransLogServer(c->servername, - c->listenport, - c->basedir, - _fileHeaderContext, - c->filesizemax, - c->usefsync, - c->maxthreads, - getCrc(c->crcmethod))); + _tls.reset(new TransLogServer(c->servername, c->listenport, c->basedir, _fileHeaderContext, + c->filesizemax, c->usefsync, c->maxthreads, getCrc(c->crcmethod))); } TransLogServerApp::~TransLogServerApp() @@ -63,4 +56,3 @@ void TransLogServerApp::configure(std::unique_ptr<searchlib::TranslogserverConfi } } -} diff --git a/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.h b/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.h index c36b58b4696..35fa994d1e4 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.h +++ b/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.h @@ -7,12 +7,9 @@ #include <vespa/vespalib/util/ptrholder.h> namespace config { class ConfigUri; } +namespace search::common { class FileHeaderContext; } -namespace search { - -namespace common { class FileHeaderContext; } - -namespace transactionlog { +namespace search::transactionlog { class TransLogServerApp : public config::IFetcherCallback<searchlib::TranslogserverConfig> { @@ -36,5 +33,4 @@ public: void start(); }; -} // namespace transactionlog -} // namespace search +} diff --git a/vespalib/src/vespa/vespalib/util/stringfmt.h b/vespalib/src/vespa/vespalib/util/stringfmt.h index f806368adf5..df23ad7c20a 100644 --- a/vespalib/src/vespa/vespalib/util/stringfmt.h +++ b/vespalib/src/vespa/vespalib/util/stringfmt.h @@ -1,8 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <cstdarg> #include <vespa/vespalib/stllike/string.h> +#include <cstdarg> #ifndef PRId64 #define PRId64 "ld" |