aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--searchcore/src/apps/proton/proton.cpp3
-rw-r--r--searchlib/CMakeLists.txt1
-rw-r--r--searchlib/src/tests/util/ioerrorhandler/.gitignore1
-rw-r--r--searchlib/src/tests/util/ioerrorhandler/CMakeLists.txt11
-rw-r--r--searchlib/src/tests/util/ioerrorhandler/ioerrorhandler_test.cpp327
-rw-r--r--searchlib/src/vespa/searchlib/util/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/util/ioerrorhandler.cpp93
-rw-r--r--searchlib/src/vespa/searchlib/util/ioerrorhandler.h42
8 files changed, 0 insertions, 479 deletions
diff --git a/searchcore/src/apps/proton/proton.cpp b/searchcore/src/apps/proton/proton.cpp
index 05e0ea71443..c2067f744a8 100644
--- a/searchcore/src/apps/proton/proton.cpp
+++ b/searchcore/src/apps/proton/proton.cpp
@@ -3,7 +3,6 @@
#include <vespa/searchcore/proton/server/proton.h>
#include <vespa/storage/storageserver/storagenode.h>
#include <vespa/searchlib/util/statefile.h>
-#include <vespa/searchlib/util/ioerrorhandler.h>
#include <vespa/metrics/metricmanager.h>
#include <vespa/vespalib/util/signalhandler.h>
#include <vespa/vespalib/util/programoptions.h>
@@ -166,7 +165,6 @@ App::Main()
LOG(debug, "serviceidentity: '%s'", params.serviceidentity.c_str());
LOG(debug, "subscribeTimeout: '%" PRIu64 "'", params.subscribeTimeout);
std::unique_ptr<search::StateFile> stateFile;
- std::unique_ptr<search::IOErrorHandler> ioErrorHandler;
protonUP = std::make_unique<proton::Proton>(params.identity, _argc > 0 ? _argv[0] : "proton", std::chrono::milliseconds(params.subscribeTimeout));
proton::Proton & proton = *protonUP;
proton::BootstrapConfig::SP configSnapshot = proton.init();
@@ -183,7 +181,6 @@ App::Main()
if (stateIsDown(stateString)) {
LOG(error, "proton state string is %s", stateString.c_str());
}
- ioErrorHandler = std::make_unique<search::IOErrorHandler>(stateFile.get());
if ( ! params.serviceidentity.empty()) {
proton.getMetricManager().init(params.serviceidentity, proton.getThreadPool());
} else {
diff --git a/searchlib/CMakeLists.txt b/searchlib/CMakeLists.txt
index 10aa5825f3f..bc2c59d448b 100644
--- a/searchlib/CMakeLists.txt
+++ b/searchlib/CMakeLists.txt
@@ -227,7 +227,6 @@ vespa_define_module(
src/tests/url
src/tests/util
src/tests/util/bufferwriter
- src/tests/util/ioerrorhandler
src/tests/util/searchable_stats
src/tests/util/slime_output_raw_buf_adapter
src/tests/util/statebuf
diff --git a/searchlib/src/tests/util/ioerrorhandler/.gitignore b/searchlib/src/tests/util/ioerrorhandler/.gitignore
deleted file mode 100644
index 2f5c2e77191..00000000000
--- a/searchlib/src/tests/util/ioerrorhandler/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-searchlib_ioerrorhandler_test_app
diff --git a/searchlib/src/tests/util/ioerrorhandler/CMakeLists.txt b/searchlib/src/tests/util/ioerrorhandler/CMakeLists.txt
deleted file mode 100644
index 5397a453023..00000000000
--- a/searchlib/src/tests/util/ioerrorhandler/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_executable(searchlib_ioerrorhandler_test_app TEST
- SOURCES
- ioerrorhandler_test.cpp
- DEPENDS
- searchlib_test
- searchlib
- EXTERNAL_DEPENDS
- dl
-)
-vespa_add_test(NAME searchlib_ioerrorhandler_test_app COMMAND searchlib_ioerrorhandler_test_app)
diff --git a/searchlib/src/tests/util/ioerrorhandler/ioerrorhandler_test.cpp b/searchlib/src/tests/util/ioerrorhandler/ioerrorhandler_test.cpp
deleted file mode 100644
index ec2831360c5..00000000000
--- a/searchlib/src/tests/util/ioerrorhandler/ioerrorhandler_test.cpp
+++ /dev/null
@@ -1,327 +0,0 @@
-// 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/util/statefile.h>
-#include <vespa/searchlib/util/ioerrorhandler.h>
-#include <vespa/searchlib/test/statefile.h>
-#include <vespa/searchlib/test/statestring.h>
-#include <vespa/fastos/file.h>
-#include <atomic>
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <unistd.h>
-#include <vespa/fastos/file_rw_ops.h>
-
-#include <vespa/log/log.h>
-LOG_SETUP("ioerrorhandler_test");
-
-using namespace search::test::statefile;
-using namespace search::test::statestring;
-
-int injectErrno;
-std::atomic<int> injectreadErrnoTrigger;
-std::atomic<int> injectpreadErrnoTrigger;
-std::atomic<int> injectwriteErrnoTrigger;
-std::atomic<int> injectpwriteErrnoTrigger;
-
-ssize_t error_injecting_read(int fd, void* buf, size_t count)
-{
- if (--injectreadErrnoTrigger == 0) {
- errno = injectErrno;
- return -1;
- }
- return read(fd, buf, count);
-}
-
-ssize_t error_injecting_write(int fd, const void* buf, size_t count)
-{
- if (--injectwriteErrnoTrigger == 0) {
- errno = injectErrno;
- return -1;
- }
- return write(fd, buf, count);
-}
-
-ssize_t error_injecting_pread(int fd, void* buf, size_t count, off_t offset)
-{
- if (--injectpreadErrnoTrigger == 0) {
- errno = injectErrno;
- return -1;
- }
- return pread(fd, buf, count, offset);
-}
-
-
-ssize_t error_injecting_pwrite(int fd, const void* buf, size_t count, off_t offset)
-{
- if (--injectpwriteErrnoTrigger == 0) {
- errno = injectErrno;
- return -1;
- }
- return pwrite(fd, buf, count, offset);
-}
-
-void setup_error_injections()
-{
- using Ops = fastos::File_RW_Ops;
- Ops::_read = error_injecting_read;
- Ops::_write = error_injecting_write;
- Ops::_pread = error_injecting_pread;
- Ops::_pwrite = error_injecting_pwrite;
-}
-
-namespace search
-{
-
-const char *testStringBase = "This is a test\n";
-
-using strvec = std::vector<vespalib::string>;
-
-namespace
-{
-
-bool
-assertHistory(std::vector<vespalib::string> &exp,
- std::vector<vespalib::string> &act)
-{
- if (!EXPECT_EQUAL(exp.size(), act.size())) {
- return false;
- }
- for (size_t i = 0; i < exp.size(); ++i) {
- if (!EXPECT_EQUAL(exp[i], act[i])) {
- return false;
- }
- }
- return true;
-}
-
-
-class Fixture
-{
-public:
-
- std::unique_ptr<StateFile> sf;
- std::unique_ptr<FastOS_File> file;
- char buf[8192];
- char *testString;
-
- Fixture();
-
- void openFile();
-
- void openFileDIO();
-
- void writeTestString();
-};
-
-
-Fixture::Fixture()
- : sf(),
- file()
-{
- unlink("testfile");
- StateFile::erase("state");
- sf.reset(new StateFile("state"));
- testString = &buf[0];
- int off = reinterpret_cast<unsigned long>(testString) & 4095;
- if (off != 0) {
- testString += 4096 - off;
- }
- assert(testString + strlen(testStringBase) < &buf[0] + sizeof(buf));
- strcpy(testString, testStringBase);
-}
-
-
-void
-Fixture::openFile()
-{
- file.reset(new FastOS_File);
- file->OpenReadWrite("testfile");
-}
-
-void
-Fixture::writeTestString()
-{
- file->WriteBuf(testString, strlen(testString));
- file->SetPosition(0);
-}
-
-
-}
-
-
-TEST("Test that ioerror handler can be instantated")
-{
- StateFile::erase("state");
- StateFile sf("state");
- IOErrorHandler ioeh(&sf);
- EXPECT_FALSE(ioeh.fired());
-}
-
-
-TEST_F("Test that ioerror handler can process read error", Fixture)
-{
- IOErrorHandler ioeh(f.sf.get());
- EXPECT_FALSE(ioeh.fired());
- f.openFile();
- f.writeTestString();
- uint64_t fileSize = f.file->GetSize();
- EXPECT_EQUAL(strlen(f.testString), fileSize);
- char buf[1024];
- assert(fileSize <= sizeof(buf));
- try {
- f.file->SetPosition(0);
- injectErrno = EIO;
- injectreadErrnoTrigger = 1;
- f.file->ReadBuf(buf, fileSize);
- LOG_ABORT("Should never get here");
- } catch (std::runtime_error &e) {
- LOG(info, "Caught std::runtime_error exception: %s", e.what());
- EXPECT_TRUE(strstr(e.what(), "Input/output error") != nullptr);
- }
- EXPECT_TRUE(ioeh.fired());
- {
- vespalib::string act = readState(*f.sf);
- normalizeTimestamp(act);
- vespalib::string exp = "state=down ts=0.0 operation=read "
- "file=testfile error=5 offset=0 len=15 "
- "rlen=-1\n";
- EXPECT_EQUAL(exp, act);
- }
- {
- strvec exp({ "state=down ts=0.0 operation=read "
- "file=testfile error=5 offset=0 len=15 "
- "rlen=-1\n"});
- std::vector<vespalib::string> act(readHistory("state.history"));
- normalizeTimestamps(act);
- TEST_DO(assertHistory(exp, act));
- }
-}
-
-TEST_F("Test that ioerror handler can process pread error", Fixture)
-{
- IOErrorHandler ioeh(f.sf.get());
- EXPECT_FALSE(ioeh.fired());
- f.openFile();
- f.writeTestString();
- uint64_t fileSize = f.file->GetSize();
- EXPECT_EQUAL(strlen(f.testString), fileSize);
- char buf[1024];
- assert(fileSize <= sizeof(buf));
- try {
- f.file->SetPosition(0);
- injectErrno = EIO;
- injectpreadErrnoTrigger = 1;
- f.file->ReadBuf(buf, fileSize, 0);
- LOG_ABORT("Should never get here");
- } catch (std::runtime_error &e) {
- LOG(info, "Caught std::runtime_error exception: %s", e.what());
- EXPECT_TRUE(strstr(e.what(), "Input/output error") != nullptr);
- }
- EXPECT_TRUE(ioeh.fired());
- {
- vespalib::string act = readState(*f.sf);
- normalizeTimestamp(act);
- vespalib::string exp = "state=down ts=0.0 operation=read "
- "file=testfile error=5 offset=0 len=15 "
- "rlen=-1\n";
- EXPECT_EQUAL(exp, act);
- }
- {
- strvec exp({ "state=down ts=0.0 operation=read "
- "file=testfile error=5 offset=0 len=15 "
- "rlen=-1\n"});
- std::vector<vespalib::string> act(readHistory("state.history"));
- normalizeTimestamps(act);
- TEST_DO(assertHistory(exp, act));
- }
-}
-
-TEST_F("Test that ioerror handler can process write error", Fixture)
-{
- IOErrorHandler ioeh(f.sf.get());
- EXPECT_FALSE(ioeh.fired());
- f.openFile();
- try {
- injectErrno = EIO;
- injectwriteErrnoTrigger = 1;
- f.writeTestString();
- LOG_ABORT("Should never get here");
- } catch (std::runtime_error &e) {
- LOG(info, "Caught std::runtime_error exception: %s", e.what());
- EXPECT_TRUE(strstr(e.what(), "Input/output error") != nullptr);
- }
- EXPECT_TRUE(ioeh.fired());
- {
- vespalib::string act = readState(*f.sf);
- normalizeTimestamp(act);
- vespalib::string exp = "state=down ts=0.0 operation=write "
- "file=testfile error=5 offset=0 len=15 "
- "rlen=-1\n";
- EXPECT_EQUAL(exp, act);
- }
- {
- strvec exp({ "state=down ts=0.0 operation=write "
- "file=testfile error=5 offset=0 len=15 "
- "rlen=-1\n"});
- std::vector<vespalib::string> act(readHistory("state.history"));
- normalizeTimestamps(act);
- TEST_DO(assertHistory(exp, act));
- }
-}
-
-
-#ifdef __linux__
-void
-Fixture::openFileDIO()
-{
- file.reset(new FastOS_File);
- file->EnableDirectIO();
- file->OpenReadWrite("testfile");
-}
-
-TEST_F("Test that ioerror handler can process pwrite error", Fixture)
-{
- IOErrorHandler ioeh(f.sf.get());
- EXPECT_FALSE(ioeh.fired());
- f.openFileDIO();
- try {
- injectErrno = EIO;
- injectpwriteErrnoTrigger = 1;
- f.writeTestString();
- LOG_ABORT("Should never get here");
- } catch (std::runtime_error &e) {
- LOG(info, "Caught std::runtime_error exception: %s", e.what());
- EXPECT_TRUE(strstr(e.what(), "Input/output error") != nullptr);
- }
- EXPECT_TRUE(ioeh.fired());
- {
- vespalib::string act = readState(*f.sf);
- normalizeTimestamp(act);
- vespalib::string exp = "state=down ts=0.0 operation=write "
- "file=testfile error=5 offset=0 len=15 "
- "rlen=-1\n";
- EXPECT_EQUAL(exp, act);
- }
- {
- strvec exp({ "state=down ts=0.0 operation=write "
- "file=testfile error=5 offset=0 len=15 "
- "rlen=-1\n"});
- std::vector<vespalib::string> act(readHistory("state.history"));
- normalizeTimestamps(act);
- TEST_DO(assertHistory(exp, act));
- }
-}
-#endif
-
-}
-
-TEST_MAIN()
-{
- setup_error_injections();
- TEST_RUN_ALL();
- search::StateFile::erase("state");
- unlink("testfile");
-}
diff --git a/searchlib/src/vespa/searchlib/util/CMakeLists.txt b/searchlib/src/vespa/searchlib/util/CMakeLists.txt
index c28aed83971..26fa8f6c041 100644
--- a/searchlib/src/vespa/searchlib/util/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/util/CMakeLists.txt
@@ -12,7 +12,6 @@ vespa_add_library(searchlib_util OBJECT
filesizecalculator.cpp
fileutil.cpp
foldedstringcompare.cpp
- ioerrorhandler.cpp
logutil.cpp
rawbuf.cpp
slime_output_raw_buf_adapter.cpp
diff --git a/searchlib/src/vespa/searchlib/util/ioerrorhandler.cpp b/searchlib/src/vespa/searchlib/util/ioerrorhandler.cpp
deleted file mode 100644
index f044c2782b5..00000000000
--- a/searchlib/src/vespa/searchlib/util/ioerrorhandler.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "ioerrorhandler.h"
-#include "statebuf.h"
-#include "statefile.h"
-#include <vespa/fastos/file.h>
-#include <unistd.h>
-
-namespace search {
-
-IOErrorHandler *IOErrorHandler::_instance = nullptr;
-
-namespace {
-
-std::atomic<int> nesting;
-
-}
-
-void
-IOErrorHandler::trap()
-{
- _instance = this;
- FastOS_File::SetFailedHandler(forward);
- _trapped = true;
-}
-
-
-void
-IOErrorHandler::untrap()
-{
-#ifdef notyet
- FastOS_File::SetFailedHandler(nullptr);
-#endif
- _trapped = false;
- _instance = nullptr;
-}
-
-
-void
-IOErrorHandler::forward(const char *op, const char *file,
- int error, int64_t offset, size_t len, ssize_t rlen)
-{
- nesting++;
- IOErrorHandler *instance = _instance;
- if (instance) {
- instance->handle(op, file, error, offset, len, rlen);
- }
- nesting--;
-}
-
-
-void
-IOErrorHandler::handle(const char *op, const char *file,
- int error, int64_t offset, size_t len, ssize_t rlen)
-{
- std::vector<char> buf(4096);
- StateBuf sb(&buf[0], buf.size());
- sb.appendKey("state") << "down";
- sb.appendTimestamp();
- sb.appendKey("operation") << op;
- sb.appendKey("file") << file;
- sb.appendKey("error") << error;
- sb.appendKey("offset") << offset;
- sb.appendKey("len") << len;
- sb.appendKey("rlen") << rlen;
- sb << '\n';
- if (_stateFile != nullptr) {
- _stateFile->addState(sb.base(), sb.size(), false);
- }
- _fired = true;
- sleep(3);
-}
-
-
-IOErrorHandler::IOErrorHandler(StateFile *stateFile)
- : _stateFile(stateFile),
- _trapped(false),
- _fired(false)
-{
- trap();
-}
-
-
-IOErrorHandler::~IOErrorHandler()
-{
- untrap();
- // Drain callbacks
- while (nesting != 0) {
- sleep(1);
- }
-}
-
-}
diff --git a/searchlib/src/vespa/searchlib/util/ioerrorhandler.h b/searchlib/src/vespa/searchlib/util/ioerrorhandler.h
deleted file mode 100644
index 04bfb0d23a8..00000000000
--- a/searchlib/src/vespa/searchlib/util/ioerrorhandler.h
+++ /dev/null
@@ -1,42 +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 <cstdint>
-#include <cstddef>
-#include <sys/types.h>
-
-namespace search {
-
-class StateFile;
-
-/*
- * Class used to handle io error callsbacks from fastos.
- */
-class IOErrorHandler
-{
- static IOErrorHandler *_instance;
- StateFile *_stateFile;
- bool _trapped;
- bool _fired;
-
- using FailedHandler = void (*)(const char *op, const char *file, int error,
- int64_t offset, size_t len, ssize_t rlen);
- void trap();
- void untrap();
-
- static void forward(const char *op, const char *file, int error,
- int64_t offset, size_t len, ssize_t rlen);
-
- void handle(const char *op, const char *file, int error,
- int64_t offset, size_t len, ssize_t rlen);
-
-public:
- IOErrorHandler(StateFile *stateFile);
- ~IOErrorHandler();
-
- bool fired() const { return _fired; }
-};
-
-
-}