Scanner C++ API
database.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/op.h"
19 #include "scanner/util/memory.h"
20 #include "storehouse/storage_backend.h"
21 
22 #include <grpc++/server.h>
23 #include "scanner/engine/rpc.grpc.pb.h"
24 
25 #include <string>
26 #include <thread>
27 
28 namespace scanner {
29 namespace internal {
30 class MasterServerImpl;
31 }
32 
35  i32 num_cpus;
36  i32 num_load_workers;
37  i32 num_save_workers;
38  std::vector<i32>
40 };
41 
43 MachineParameters default_machine_params();
44 
46 struct FailedVideo {
47  std::string path;
48  std::string message;
49 };
50 
52 class Database {
53  public:
54  Database(storehouse::StorageConfig* storage_config,
55  const std::string& db_path, const std::string& master_address);
56 
57  ~Database();
58 
59  Result start_master(const MachineParameters& params, const std::string& port,
60  const std::string& python_dir,
61  bool watchdog = true,
62  i64 no_workers_timeout = 30,
63  i32 new_job_retries_limit = 5);
64 
65  Result start_worker(const MachineParameters& params, const std::string& port,
66  const std::string& python_dir,
67  bool watchdog = true);
68 
69  Result ingest_videos(const std::vector<std::string>& table_names,
70  const std::vector<std::string>& paths,
71  bool inplace,
72  std::vector<FailedVideo>& failed_videos);
73 
74  Result delete_table(const std::string& table_name);
75 
76  Result shutdown_master();
77 
78  Result shutdown_worker();
79 
80  Result wait_for_server_shutdown();
81 
82  Result destroy_database();
83 
84  protected:
85  bool database_exists();
86 
87  struct ServerState {
88  std::unique_ptr<grpc::Server> server;
89  std::shared_ptr<grpc::Service> service;
90  };
91 
92  private:
93  storehouse::StorageConfig* storage_config_;
94  std::unique_ptr<storehouse::StorageBackend> storage_;
95  std::string db_path_;
96  std::string master_address_;
97 
98  std::unique_ptr<internal::MasterServerImpl> master_server_;
99  std::thread master_thread_;
100  std::vector<std::unique_ptr<ServerState>> worker_states_;
101 };
102 }
Info about a video that fails to ingest.
Definition: database.h:46
Definition: database.h:87
Definition: database.cpp:36
Description of resources for a given machine.
Definition: database.h:34
Main entry point into Scanner.
Definition: database.h:52
std::vector< i32 > gpu_ids
List of CUDA device IDs that Scanner should use.
Definition: database.h:39