OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SessionInfo.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SESSION_INFO_H
18 #define SESSION_INFO_H
19 
20 #include <atomic>
21 #include <cstdint>
22 #include <ctime>
23 #include <limits>
24 #include <list>
25 #include <map>
26 #include <memory>
27 #include <mutex>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 #include "../QueryEngine/CompilationOptions.h"
33 #include "../SqliteConnector/SqliteConnector.h"
34 #include "LeafHostInfo.h"
35 #include "SysCatalog.h"
36 
37 namespace Importer_NS {
38 class Loader;
39 class TypedImportBuffer;
40 } // namespace Importer_NS
41 
42 namespace Catalog_Namespace {
43 
44 class Catalog;
45 
46 // this class is defined to accommodate both Thrift and non-Thrift builds.
47 class MapDHandler {
48  public:
49  virtual void prepare_columnar_loader(
50  const std::string& session,
51  const std::string& table_name,
52  size_t num_cols,
53  std::unique_ptr<Importer_NS::Loader>* loader,
54  std::vector<std::unique_ptr<Importer_NS::TypedImportBuffer>>* import_buffers);
55  virtual ~MapDHandler() {}
56 };
57 
58 /*
59  * @type SessionInfo
60  * @brief a user session
61  */
62 class SessionInfo {
63  public:
64  SessionInfo(std::shared_ptr<MapDHandler> mapdHandler,
65  std::shared_ptr<Catalog> cat,
66  const UserMetadata& user,
67  const ExecutorDeviceType t,
68  const std::string& sid)
69  : mapdHandler_(mapdHandler)
70  , catalog_(cat)
71  , currentUser_(user)
73  , session_id_(sid)
74  , last_used_time_(time(0))
75  , start_time_(time(0))
77  SessionInfo(std::shared_ptr<Catalog> cat,
78  const UserMetadata& user,
79  const ExecutorDeviceType t,
80  const std::string& sid)
81  : SessionInfo(std::make_shared<MapDHandler>(), cat, user, t, sid) {}
84  , catalog_(s.catalog_)
89  MapDHandler* get_mapdHandler() const { return mapdHandler_.get(); }
90  Catalog& getCatalog() const { return *catalog_; }
91  std::shared_ptr<Catalog> get_catalog_ptr() const { return catalog_; }
92  void set_catalog_ptr(std::shared_ptr<Catalog> c) { catalog_ = c; }
93  const UserMetadata& get_currentUser() const { return currentUser_; }
95  return executor_device_type_;
96  }
98  std::string get_session_id() const { return session_id_; }
99  time_t get_last_used_time() const { return last_used_time_; }
101  bool checkDBAccessPrivileges(const DBObjectType& permissionType,
102  const AccessPrivileges& privs,
103  const std::string& objectName = "") const;
104  time_t get_start_time() const { return start_time_; }
105  std::string const& get_public_session_id() const { return public_session_id_; }
106  operator std::string() const { return public_session_id_; }
107 
108  private:
109  std::shared_ptr<MapDHandler> mapdHandler_;
110  std::shared_ptr<Catalog> catalog_;
112  std::atomic<ExecutorDeviceType> executor_device_type_;
113  const std::string session_id_;
114  std::atomic<time_t> last_used_time_; // for tracking active session duration
115  std::atomic<time_t> start_time_; // for invalidating session after tolerance period
116  const std::string public_session_id_;
117  std::string public_session_id() const;
118 };
119 
120 std::ostream& operator<<(std::ostream& os, const SessionInfo& session_info);
121 
122 } // namespace Catalog_Namespace
123 
124 #endif /* SESSION_INFO_H */
std::shared_ptr< Catalog > catalog_
Definition: SessionInfo.h:110
const std::string session_id_
Definition: SessionInfo.h:113
MapDHandler * get_mapdHandler() const
Definition: SessionInfo.h:89
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:81
std::string const & get_public_session_id() const
Definition: SessionInfo.h:105
DBObjectType
Definition: DBObject.h:42
ExecutorDeviceType
virtual void prepare_columnar_loader(const std::string &session, const std::string &table_name, size_t num_cols, std::unique_ptr< Importer_NS::Loader > *loader, std::vector< std::unique_ptr< Importer_NS::TypedImportBuffer >> *import_buffers)
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:53
const std::string public_session_id_
Definition: SessionInfo.h:116
std::atomic< time_t > last_used_time_
Definition: SessionInfo.h:114
std::shared_ptr< MapDHandler > mapdHandler_
Definition: SessionInfo.h:109
SessionInfo(const SessionInfo &s)
Definition: SessionInfo.h:82
std::string public_session_id() const
Definition: SessionInfo.cpp:43
std::atomic< time_t > start_time_
Definition: SessionInfo.h:115
SessionInfo(std::shared_ptr< MapDHandler > mapdHandler, std::shared_ptr< Catalog > cat, const UserMetadata &user, const ExecutorDeviceType t, const std::string &sid)
Definition: SessionInfo.h:64
std::atomic< ExecutorDeviceType > executor_device_type_
Definition: SessionInfo.h:112
This file contains the class specification and related data structures for SysCatalog.
SessionInfo(std::shared_ptr< Catalog > cat, const UserMetadata &user, const ExecutorDeviceType t, const std::string &sid)
Definition: SessionInfo.h:77
std::shared_ptr< Catalog > get_catalog_ptr() const
Definition: SessionInfo.h:91
std::string get_session_id() const
Definition: SessionInfo.h:98
Catalog & getCatalog() const
Definition: SessionInfo.h:90
time_t get_start_time() const
Definition: SessionInfo.h:104
void set_executor_device_type(ExecutorDeviceType t)
Definition: SessionInfo.h:97
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
void set_catalog_ptr(std::shared_ptr< Catalog > c)
Definition: SessionInfo.h:92
time_t get_last_used_time() const
Definition: SessionInfo.h:99
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
const ExecutorDeviceType get_executor_device_type() const
Definition: SessionInfo.h:94