summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-09-26 14:30:48 +0200
committerGitHub <noreply@github.com>2018-09-26 14:30:48 +0200
commit3a6ec425d48dc06cb6455fb3ae4eac9d10a7c37f (patch)
tree00d42f7635ba261bcfbd064ba7ba3d0a75080e0d
parent545c49acbd52dc1912e3209b78f701285277b6f7 (diff)
parentc5cd5a7cf5ad938c6539294b592fbd6b8a4c0aee (diff)
Merge pull request #7097 from vespa-engine/balder/program-to-drop-files-from-cache
Balder/program to drop files from cache
-rw-r--r--vespalib/CMakeLists.txt2
-rw-r--r--vespalib/src/apps/vespa-drop-file-from-cache/.gitignore1
-rw-r--r--vespalib/src/apps/vespa-drop-file-from-cache/CMakeLists.txt9
-rw-r--r--vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp32
-rw-r--r--vespalib/src/tests/drop-file-from-cache/CMakeLists.txt8
-rw-r--r--vespalib/src/tests/drop-file-from-cache/drop_file_from_cache_test.cpp25
-rw-r--r--vespalib/src/vespa/vespalib/util/slaveproc.h15
7 files changed, 82 insertions, 10 deletions
diff --git a/vespalib/CMakeLists.txt b/vespalib/CMakeLists.txt
index b32c875cb26..c5dafcf789d 100644
--- a/vespalib/CMakeLists.txt
+++ b/vespalib/CMakeLists.txt
@@ -12,6 +12,7 @@ vespa_define_module(
src/apps/make_fixture_macros
src/apps/vespa-detect-hostname
src/apps/vespa-validate-hostname
+ src/apps/vespa-drop-file-from-cache
TESTS
src/tests/alignedmemory
@@ -36,6 +37,7 @@ vespa_define_module(
src/tests/data/smart_buffer
src/tests/delegatelist
src/tests/dotproduct
+ src/tests/drop-file-from-cache
src/tests/dual_merge_director
src/tests/eventbarrier
src/tests/exception_classes
diff --git a/vespalib/src/apps/vespa-drop-file-from-cache/.gitignore b/vespalib/src/apps/vespa-drop-file-from-cache/.gitignore
new file mode 100644
index 00000000000..24dc558b6bc
--- /dev/null
+++ b/vespalib/src/apps/vespa-drop-file-from-cache/.gitignore
@@ -0,0 +1 @@
+vespa-drop-file-from-cache
diff --git a/vespalib/src/apps/vespa-drop-file-from-cache/CMakeLists.txt b/vespalib/src/apps/vespa-drop-file-from-cache/CMakeLists.txt
new file mode 100644
index 00000000000..409fd5bb725
--- /dev/null
+++ b/vespalib/src/apps/vespa-drop-file-from-cache/CMakeLists.txt
@@ -0,0 +1,9 @@
+# Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(vespalib_vespa-drop-file-from-cache_app
+ SOURCES
+ drop_file_from_cache.cpp
+ OUTPUT_NAME vespa-drop-file-from-cache
+ INSTALL bin
+ DEPENDS
+ vespalib
+)
diff --git a/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp b/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp
new file mode 100644
index 00000000000..042681a90fe
--- /dev/null
+++ b/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp
@@ -0,0 +1,32 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <cstdio>
+#include <cerrno>
+#include <cstring>
+#include <fcntl.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ char errorBuf[200];
+ if (argc != 2) {
+ fprintf(stderr, "%s <filename>\n", argv[0]);
+ return 1;
+ }
+ const char *fileName = argv[1];
+ int fh = open(fileName, O_RDONLY);
+ if (fh == -1) {
+ const char *errorString = strerror_r(errno, errorBuf, sizeof(errorBuf));
+ fprintf(stderr, "Failed opening file %s: %s\n", fileName, errorString);
+ return 2;
+ }
+
+ int retval = 0;
+ int err = posix_fadvise(fh, 0, 0, POSIX_FADV_DONTNEED);
+ if (err != 0) {
+ const char *errorString = strerror_r(errno, errorBuf, sizeof(errorBuf));
+ fprintf(stderr, "posix_fadvise failed: %s\n", errorString);
+ retval = 3;
+ }
+ close(fh);
+ return retval;
+}
diff --git a/vespalib/src/tests/drop-file-from-cache/CMakeLists.txt b/vespalib/src/tests/drop-file-from-cache/CMakeLists.txt
new file mode 100644
index 00000000000..d6f4a51a4c5
--- /dev/null
+++ b/vespalib/src/tests/drop-file-from-cache/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(vespalib_drop_file_from_cache_test_app TEST
+ SOURCES
+ drop_file_from_cache_test.cpp
+ DEPENDS
+ vespalib
+)
+vespa_add_test(NAME vespalib_drop_file_from_cache_test_app COMMAND vespalib_drop_file_from_cache_test_app)
diff --git a/vespalib/src/tests/drop-file-from-cache/drop_file_from_cache_test.cpp b/vespalib/src/tests/drop-file-from-cache/drop_file_from_cache_test.cpp
new file mode 100644
index 00000000000..63defa58c41
--- /dev/null
+++ b/vespalib/src/tests/drop-file-from-cache/drop_file_from_cache_test.cpp
@@ -0,0 +1,25 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/vespalib/util/slaveproc.h>
+
+using vespalib::SlaveProc;
+
+TEST("no arguments") {
+ SlaveProc drop("../../apps/vespa-drop-file-from-cache/vespa-drop-file-from-cache");
+ drop.wait();
+ EXPECT_EQUAL(1, drop.getExitCode());
+}
+
+TEST("file does not exist") {
+ SlaveProc drop("../../apps/vespa-drop-file-from-cache/vespa-drop-file-from-cache not_exist");
+ drop.wait();
+ EXPECT_EQUAL(2, drop.getExitCode());
+}
+
+TEST("All is well") {
+ SlaveProc drop("../../apps/vespa-drop-file-from-cache/vespa-drop-file-from-cache vespalib_drop_file_from_cache_test_app");
+ drop.wait();
+ EXPECT_EQUAL(0, drop.getExitCode());
+}
+
+TEST_MAIN_WITH_PROCESS_PROXY() { TEST_RUN_ALL(); }
diff --git a/vespalib/src/vespa/vespalib/util/slaveproc.h b/vespalib/src/vespa/vespalib/util/slaveproc.h
index 72b20cfb069..c08a13f0b1d 100644
--- a/vespalib/src/vespa/vespalib/util/slaveproc.h
+++ b/vespalib/src/vespa/vespalib/util/slaveproc.h
@@ -8,14 +8,9 @@
#include <queue>
#include "sync.h"
-namespace vespalib {
-
-namespace slaveproc {
-
-class Timer;
-
-} // namespace slaveproc
+namespace vespalib::slaveproc { class Timer; }
+namespace vespalib {
/**
* @brief Slave Process utility class for running external programs
*
@@ -56,12 +51,12 @@ private:
bool _failed;
int _exitCode;
- SlaveProc(const SlaveProc &); // no copy
- SlaveProc &operator=(const SlaveProc &); // no assignment
-
void checkProc();
public:
+ SlaveProc(const SlaveProc &) = delete;
+ SlaveProc &operator=(const SlaveProc &) = delete;
+
/**
* @brief Run a slave process
*