-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked S3 GetObject by moving it to a helper application
Added a notes section to Contributing.md Added the s3iomain.cpp and entries to the CMakefile to compile the GetObject helper binary. Starter is not a Singleton anymore. Added IOHelper::getApplicationPath() to get the absolute path of the running application. This is used to run the helper binary. Added the S3GetObjectProcessWrapper, which is used to run the helper binary in a separate process and thread. Moved the async GetObject code from S3Source to the helper binary and made it a bit more readable. Added unsigned (U) suffixes to some numbers in tests.
- Loading branch information
heinold
committed
Aug 12, 2019
1 parent
4f21d94
commit 1c078fd
Showing
22 changed files
with
435 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
using namespace std; | ||
|
||
|
||
#ifndef __MAIN_H__ | ||
#define __MAIN_H__ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) 2019 DKFZ - ODCF | ||
* | ||
* Distributed under the MIT License (license terms are at https://github.com/dkfz-odcf/FastqIndEx/blob/master/LICENSE.txt). | ||
*/ | ||
|
||
#include "common/CommonStructsAndConstants.h" | ||
#include "S3GetObjectProcessWrapper.h" | ||
|
||
void S3GetObjectProcessWrapper::processThreadFunc(S3GetObjectProcessWrapper *wrapper) { | ||
stringstream cmd; | ||
// We need to pass double ticks with a whitespace in it (" ") if you have an empty argument. | ||
// "" and '' were not regarded as parameters in our tests. | ||
cmd << "\"" << S3HELPER_BINARY << "\" \"" | ||
<< wrapper->fifo.string() << "\" \"" | ||
<< wrapper->s3Object << "\" \"" | ||
<< wrapper->serviceOptions.configSection << "\" \"" | ||
<< wrapper->serviceOptions.configFile.string() << " \" \"" | ||
<< wrapper->serviceOptions.credentialsFile.string() << " \" \"" | ||
<< wrapper->readStart << "\""; // Single ticks will be regarded as two parameters with a space inside... | ||
ErrorAccumulator::debug("Async call: ", cmd.str()); | ||
int result = system(cmd.str().c_str()); | ||
ErrorAccumulator::debug("Async call to S3 started with result of: ", to_string(result)); | ||
} | ||
|
||
void S3GetObjectProcessWrapper::start() { | ||
lock_guard<mutex> lock(mtx); | ||
if (!processThread) { | ||
processThread = make_shared<thread>(processThreadFunc, this); | ||
} | ||
} | ||
|
||
void S3GetObjectProcessWrapper::waitForFinish() { | ||
lock_guard<mutex> lock(mtx); // Prevent a new process from being started | ||
if (processThread) { | ||
processThread->join(); | ||
processThread.reset(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright (c) 2019 DKFZ - ODCF | ||
* | ||
* Distributed under the MIT License (license terms are at https://github.com/dkfz-odcf/FastqIndEx/blob/master/LICENSE.txt). | ||
*/ | ||
|
||
#ifndef FASTQINDEX_S3GETOBJECTPROCESSWRAPPER_H | ||
#define FASTQINDEX_S3GETOBJECTPROCESSWRAPPER_H | ||
|
||
#include "common/ErrorAccumulator.h" | ||
#include "S3ServiceOptions.h" | ||
#include <thread> | ||
#include <mutex> | ||
|
||
using namespace std; | ||
|
||
/** | ||
* The class is a wrapper for the tool binary "fastqindexs3iohelper". | ||
* The whole purpose of this is to get a better user experience by swallowing error messages like: | ||
* - SIGABRT | ||
* - SIGSEV | ||
* - SIGPIP | ||
* all coming up because I did not find (and I searched for it!) a good way to abort a get object request for S3. | ||
*/ | ||
class S3GetObjectProcessWrapper : public ErrorAccumulator { | ||
private: | ||
|
||
/** | ||
* The options for S3. | ||
*/ | ||
S3ServiceOptions serviceOptions; | ||
|
||
/** | ||
* The fifo (or file) to write to. | ||
*/ | ||
path fifo; | ||
|
||
/** | ||
* The object which shall be downloaded. | ||
*/ | ||
string s3Object; | ||
|
||
/** | ||
* Where to start reading. | ||
*/ | ||
int64_t readStart; | ||
|
||
/** | ||
* Mutex to perform thread-safe operations in this class | ||
*/ | ||
mutex mtx; | ||
|
||
/** | ||
* The Thread which is used to run the child S3 process. | ||
*/ | ||
shared_ptr<thread> processThread; | ||
|
||
static void processThreadFunc(S3GetObjectProcessWrapper *wrapper); | ||
|
||
public: | ||
|
||
explicit S3GetObjectProcessWrapper(const S3ServiceOptions &serviceOptions, | ||
const path &fifo, | ||
const string &s3Object, | ||
int64_t readStart) { | ||
this->serviceOptions = serviceOptions; | ||
this->fifo = fifo; | ||
this->s3Object = s3Object; | ||
this->readStart = readStart; | ||
} | ||
|
||
virtual ~S3GetObjectProcessWrapper() { | ||
waitForFinish(); | ||
ErrorAccumulator::debug("Abort Thread!"); | ||
} | ||
|
||
/** | ||
* Start a download process, if no process is already active. Will not stop an active process. | ||
*/ | ||
void start(); | ||
|
||
/** | ||
* Will call join on the underlying thread and thus wait until the download process ends. | ||
* To really end | ||
*/ | ||
void waitForFinish(); | ||
}; | ||
|
||
#endif //FASTQINDEX_S3GETOBJECTPROCESSWRAPPER_H |
Oops, something went wrong.