Scanner C++ API
save_worker.h
1 /* Copyright 2016 Carnegie Mellon University
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include "scanner/api/sink.h"
19 #include "scanner/engine/runtime.h"
20 #include "scanner/engine/sink_factory.h"
21 #include "scanner/util/common.h"
22 #include "scanner/util/queue.h"
23 #include "scanner/util/storehouse.h"
24 #include "scanner/util/thread_pool.h"
25 
26 namespace scanner {
27 namespace internal {
28 
30  // Uniform arguments
31  i32 node_id;
32  const std::vector<std::map<i32, std::vector<u8>>>& sink_args;
33  // job -> op idx -> table id
34  const std::vector<std::map<i32, i64>>& column_sink_to_table_ids;
35 
36  // Per worker arguments
37  int worker_id;
38  storehouse::StorageConfig* storage_config;
39  std::vector<SinkFactory*> sink_factories;
40  std::vector<SinkConfig> sink_configs;
41  std::vector<i32> sink_op_idxs;
42  Profiler& profiler;
43  proto::Result& result;
44 };
45 
46 class SaveWorker {
47  public:
48  SaveWorker(const SaveWorkerArgs& args);
49  ~SaveWorker();
50 
51  void feed(EvalWorkEntry& input_entry);
52 
53  void new_task(i32 job_id, i32 task_id, std::vector<ColumnType> column_types);
54 
55  void finished();
56 
57  private:
58  const i32 node_id_;
59  const i32 worker_id_;
60  Profiler& profiler_;
61  const std::vector<std::map<i32, std::vector<u8>>>& sink_args_;
62  const std::vector<std::map<i32, i64>>& column_sink_to_table_ids_;
63 
64  //
65  std::vector<i32> sink_op_idx_;
66  std::vector<SinkConfig> sink_configs_;
67  std::vector<std::unique_ptr<Sink>> sinks_; // Provides the implementation for
68  // writing data under the
69  // specified data sources
70  ThreadPool thread_pool_;
71 
72  // Continuation state
73  bool first_item_;
74  bool needs_configure_;
75  bool needs_reset_;
76 
77  i64 current_work_item_;
78  i64 current_row_;
79  i64 total_work_items_;
80 
81 };
82 
83 }
84 }
Definition: save_worker.h:46
Definition: save_worker.h:29
Definition: profiler.h:40
Definition: database.cpp:36
Definition: runtime.h:44