diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-10 12:38:35 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-10 12:38:35 +0000 |
commit | edeaf5462997b6623af0203e0fd1098cf8f071ec (patch) | |
tree | 90a0ac75ed1586ec84d50b73341b1b5e13d6ea07 /filedistribution | |
parent | e4df26232d50ea6a95fb61040fdebc09f83de8e3 (diff) |
We should atleast clean up after ourselves.
Diffstat (limited to 'filedistribution')
4 files changed, 31 insertions, 10 deletions
diff --git a/filedistribution/src/apps/filedistributor/filedistributor.cpp b/filedistribution/src/apps/filedistributor/filedistributor.cpp index 18712ac7359..cdcfd220c94 100644 --- a/filedistribution/src/apps/filedistributor/filedistributor.cpp +++ b/filedistribution/src/apps/filedistributor/filedistributor.cpp @@ -404,7 +404,7 @@ main(int argc, char** argv) { initSignals(); std::srand(std::time(0)); - filedistribution::setupZooKeeperLogging(); + filedistribution::ZKLogging loggingGuard; return executeApplication(argc, argv); } diff --git a/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp b/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp index e9147e16cb2..fb75d88e031 100644 --- a/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp +++ b/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp @@ -46,6 +46,8 @@ void deleteField(FIELD& field, jobject self, JNIEnv* env) field.set(self, 0, env); } +std::unique_ptr<ZKLogging> _G_zkLogging; + } //anonymous namespace @@ -55,7 +57,7 @@ void deleteField(FIELD& field, jobject self, JNIEnv* env) /*might fail, therefore also uses stderror message*/ \ throwRuntimeException("Out of memory", env); \ returnStatement; \ - } catch(const filedistribution::ZKException& e) { \ + } catch(const ZKException& e) { \ std::stringstream ss; \ ss << "In" << __FUNCTION__ << ": "; \ ss << diagnosticUserLevelMessage(e); \ @@ -72,7 +74,7 @@ Java_com_yahoo_vespa_filedistribution_FileDistributionManager_setup( JNIEnv *env, jclass self) { try { - filedistribution::setupZooKeeperLogging(); + _G_zkLogging = std::make_unique<ZKLogging>(); nativeFileDistributionManagerField = LongField<NativeFileDistributionManager*>(self, "nativeFileDistributionManager", env); } STANDARDCATCH() } @@ -228,7 +230,7 @@ Java_com_yahoo_vespa_filedistribution_FileDistributionManager_getProgressImpl( JNIString fileReference(fileReferenceArg, env); JNIArray<JNIString> hostNames(hostNamesArg, env); - const filedistribution::FileDBModel::Progress progress = + const FileDBModel::Progress progress = nativeFileDistributionManagerField.get(self, env)->_fileDBModel-> getProgress(fileReference._value, hostNames._value); diff --git a/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp b/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp index 71c93be1b98..ecfb3ca7b44 100644 --- a/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp +++ b/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp @@ -25,6 +25,7 @@ using filedistribution::ZKFacade; using filedistribution::Move; using filedistribution::Buffer; using filedistribution::ZKGenericException; +using filedistribution::ZKLogging; typedef ZKFacade::Path Path; @@ -568,20 +569,30 @@ ZKFacade::disableRetries() { _retriesEnabled = false; } -void -filedistribution::setupZooKeeperLogging() { +ZKLogging::ZKLogging() : + _file(nullptr) +{ std::string filename(vespa::Defaults::vespaHome()); filename.append("/tmp/zookeeper.log"); - FILE* file = std::fopen(filename.c_str(), "w"); - if (file == NULL) { + _file = std::fopen(filename.c_str(), "w"); + if (_file == nullptr) { std::cerr <<"Could not open file " <<filename << std::endl; } else { - zoo_set_log_stream(file); + zoo_set_log_stream(_file); } zoo_set_debug_level(ZOO_LOG_LEVEL_ERROR); } +ZKLogging::~ZKLogging() +{ + zoo_set_log_stream(nullptr); + if (_file != nullptr) { + std::fclose(_file); + _file = nullptr; + } +} + const char* ZKGenericException::what() const throw() { switch(_zkStatus) { diff --git a/filedistribution/src/vespa/filedistribution/model/zkfacade.h b/filedistribution/src/vespa/filedistribution/model/zkfacade.h index 7db6b53cc18..505ff008079 100644 --- a/filedistribution/src/vespa/filedistribution/model/zkfacade.h +++ b/filedistribution/src/vespa/filedistribution/model/zkfacade.h @@ -129,7 +129,15 @@ private: WatchersMap _watchers; }; -void setupZooKeeperLogging(); +class ZKLogging { +public: + ZKLogging(); + ~ZKLogging(); + ZKLogging(const ZKLogging &) = delete; + ZKLogging & operator = (const ZKLogging &) = delete; +private: + FILE * _file; +}; } //namespace filedistribution |