local_runner.h
1 // Copyright 2019, Beeri 15. All rights reserved.
2 // Author: Roman Gershman (romange@gmail.com)
3 //
4 #pragma once
5 
6 #include "mr/runner.h"
7 
8 namespace util {
9 class IoContextPool;
10 } // namespace util
11 
12 namespace file {
13 class ReadonlyFile;
14 } // namespace file
15 
16 namespace mr3 {
17 
18 class LocalRunner : public Runner {
19  public:
20  LocalRunner(util::IoContextPool* pool, const std::string& data_dir);
21  ~LocalRunner();
22 
23  void Init() final;
24 
25  void Shutdown() final;
26 
27  void OperatorStart(const pb::Operator* op) final;
28 
29  // Must be thread-safe. Called from multiple threads in pipeline_executor.
30  RawContext* CreateContext() final;
31 
32  void OperatorEnd(ShardFileMap* out_files) final;
33 
34  // For GCS, if glob ends with "**", expands it recursively.
35  void ExpandGlob(const std::string& glob, ExpandCb cb) final;
36 
37  // Read file and fill queue. This function must be fiber-friendly.
38  size_t ProcessInputFile(const std::string& filename, pb::WireFormat::Type type,
39  RawSinkCb cb) final;
40 
41  void SaveFile(absl::string_view fn, absl::string_view data);
42 
43  void Stop();
44 
45  private:
46  struct Impl;
47  std::unique_ptr<Impl> impl_;
48 };
49 
50 } // namespace mr3
A pool of IoContext objects, representing and managing CPU resources of the system.