forked from KatanaGraph/katana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tsuba: overlap work on the read side
Signed-off-by: Tyler Hunt <thunt@katanagraph.com>
- Loading branch information
1 parent
05cd1cf
commit 535d9b5
Showing
12 changed files
with
352 additions
and
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef KATANA_LIBTSUBA_TSUBA_ASYNCOPGROUP_H_ | ||
#define KATANA_LIBTSUBA_TSUBA_ASYNCOPGROUP_H_ | ||
|
||
#include <future> | ||
#include <list> | ||
|
||
#include "katana/Result.h" | ||
|
||
namespace tsuba { | ||
|
||
class AsyncOpGroup { | ||
public: | ||
struct AsyncOp { | ||
std::future<katana::Result<void>> result; | ||
std::string location; | ||
std::function<katana::Result<void>()> on_complete; | ||
}; | ||
|
||
/// Add future to the list of futures this descriptor will wait for, note | ||
/// the file name for debugging. | ||
void AddOp( | ||
std::future<katana::Result<void>> future, std::string file, | ||
const std::function<katana::Result<void>()>& on_complete); | ||
|
||
/// Wait until all operations this descriptor knows about have completed | ||
katana::Result<void> Finish(); | ||
/// wait for the op at the head of the list, return true if there was one | ||
bool FinishOne(); | ||
|
||
private: | ||
std::list<AsyncOp> pending_ops_; | ||
uint64_t errors_{0}; | ||
uint64_t total_{0}; | ||
katana::Result<void> last_error_{katana::ResultSuccess()}; | ||
}; | ||
|
||
} // namespace tsuba | ||
|
||
#endif |
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,63 @@ | ||
#ifndef KATANA_LIBTSUBA_TSUBA_READGROUP_H_ | ||
#define KATANA_LIBTSUBA_TSUBA_READGROUP_H_ | ||
|
||
#include <future> | ||
#include <list> | ||
#include <memory> | ||
|
||
#include "katana/Result.h" | ||
#include "tsuba/AsyncOpGroup.h" | ||
|
||
namespace tsuba { | ||
|
||
/// Track multiple, outstanding async writes and provide a mechanism to ensure | ||
/// that they have all completed | ||
class ReadGroup { | ||
public: | ||
static katana::Result<std::unique_ptr<ReadGroup>> Make(); | ||
|
||
/// Wait until all operations this descriptor knows about have completed | ||
katana::Result<void> Finish(); | ||
|
||
/// Add future to the list of futures this ReadGroup will wait for, note | ||
/// the file name for debugging. `on_complete` is guaranteed to be called | ||
/// in FIFO order | ||
void AddOp( | ||
std::future<katana::Result<void>> future, std::string file, | ||
const std::function<katana::Result<void>()>& on_complete); | ||
|
||
/// same as AddOp, but the future may return a data type which can then be | ||
/// consumed by on_complete | ||
template <typename RetType> | ||
void AddReturnsOp( | ||
std::future<katana::Result<RetType>> future, const std::string& file, | ||
const std::function<katana::Result<void>(RetType)>& on_complete) { | ||
// n.b., make shared instead of unique because move capture below prevents | ||
// passing generic_complete_fn as a std::function | ||
auto ret_val = std::make_shared<RetType>(); | ||
auto new_future = std::async( | ||
std::launch::deferred, | ||
[future = std::move(future), | ||
&ret_val_storage = *ret_val]() mutable -> katana::Result<void> { | ||
auto res = future.get(); | ||
if (!res) { | ||
return res.error(); | ||
} | ||
ret_val_storage = res.value(); | ||
return katana::ResultSuccess(); | ||
}); | ||
|
||
std::function<katana::Result<void>()> generic_complete_fn = | ||
[ret_val, on_complete]() -> katana::Result<void> { | ||
return on_complete(std::move(*ret_val)); | ||
}; | ||
AddOp(std::move(new_future), file, generic_complete_fn); | ||
} | ||
|
||
private: | ||
AsyncOpGroup async_op_group_; | ||
}; | ||
|
||
} // namespace tsuba | ||
|
||
#endif |
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
Oops, something went wrong.