OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SessionsStore.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 #pragma once
18 
19 #include "Catalog/SessionInfo.h"
20 
21 #include <functional>
22 #include <memory>
23 #include <thread>
24 
25 namespace Catalog_Namespace {
26 
27 using SessionInfoPtr = std::shared_ptr<SessionInfo>;
28 
29 using DisconnectCallback = std::function<void(SessionInfoPtr& session)>;
30 
32  public:
33  virtual SessionInfoPtr add(const Catalog_Namespace::UserMetadata& user_meta,
34  std::shared_ptr<Catalog> cat,
35  ExecutorDeviceType device) = 0;
36  virtual SessionInfoPtr get(const std::string& session_id) = 0;
37  void erase(const std::string& session_id);
38  void eraseByUser(const std::string& user_name);
39  void eraseByDB(const std::string& db_name);
40 
41  std::vector<SessionInfoPtr> getAllSessions();
42  std::vector<SessionInfoPtr> getUserSessions(const std::string& user_name);
43  SessionInfoPtr getByPublicID(const std::string& public_id);
44 
45  virtual ~SessionsStore() = default;
46 
47  SessionInfo getSessionCopy(const std::string& session_id);
48  void disconnect(const std::string session_id);
49 
50  static std::unique_ptr<SessionsStore> create(const std::string& base_path,
51  size_t n_workers,
52  int idle_session_duration,
53  int max_session_duration,
54  int capacity,
55  DisconnectCallback disconnect_callback);
56 
57  protected:
58  bool isSessionExpired(const SessionInfoPtr& session_ptr,
59  int idle_session_duration,
60  int max_session_duration);
61  virtual bool isSessionInUse(const SessionInfoPtr& session_ptr) = 0;
62  virtual SessionInfoPtr getUnlocked(const std::string& session_id) = 0;
63  virtual void eraseUnlocked(const std::string& session_id) = 0;
65  virtual std::vector<SessionInfoPtr> getIf(
66  std::function<bool(const SessionInfoPtr&)> predicate) = 0;
67  virtual void eraseIf(std::function<bool(const SessionInfoPtr&)> predicate) = 0;
68  virtual heavyai::shared_mutex& getLock() = 0;
69 };
70 
71 } // namespace Catalog_Namespace
virtual ~SessionsStore()=default
void erase(const std::string &session_id)
virtual SessionInfoPtr getUnlocked(const std::string &session_id)=0
std::string cat(Ts &&...args)
std::function< void(SessionInfoPtr &session)> DisconnectCallback
Definition: SessionsStore.h:29
virtual void eraseUnlocked(const std::string &session_id)=0
virtual DisconnectCallback getDisconnectCallback()=0
ExecutorDeviceType
SessionInfo getSessionCopy(const std::string &session_id)
virtual heavyai::shared_mutex & getLock()=0
bool isSessionExpired(const SessionInfoPtr &session_ptr, int idle_session_duration, int max_session_duration)
virtual bool isSessionInUse(const SessionInfoPtr &session_ptr)=0
virtual void eraseIf(std::function< bool(const SessionInfoPtr &)> predicate)=0
virtual SessionInfoPtr add(const Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog > cat, ExecutorDeviceType device)=0
static std::unique_ptr< SessionsStore > create(const std::string &base_path, size_t n_workers, int idle_session_duration, int max_session_duration, int capacity, DisconnectCallback disconnect_callback)
virtual std::vector< SessionInfoPtr > getIf(std::function< bool(const SessionInfoPtr &)> predicate)=0
void eraseByUser(const std::string &user_name)
void disconnect(const std::string session_id)
SessionInfoPtr getByPublicID(const std::string &public_id)
std::shared_timed_mutex shared_mutex
std::vector< SessionInfoPtr > getAllSessions()
void eraseByDB(const std::string &db_name)
std::vector< SessionInfoPtr > getUserSessions(const std::string &user_name)
std::shared_ptr< SessionInfo > SessionInfoPtr
Definition: SessionsStore.h:27