OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Catalog_Namespace::SessionsStore Class Referenceabstract

#include <SessionsStore.h>

+ Inheritance diagram for Catalog_Namespace::SessionsStore:

Public Member Functions

virtual SessionInfoPtr add (const Catalog_Namespace::UserMetadata &user_meta, std::shared_ptr< Catalog > cat, ExecutorDeviceType device)=0
 
virtual SessionInfoPtr get (const std::string &session_id)=0
 
void erase (const std::string &session_id)
 
void eraseByUser (const std::string &user_name)
 
void eraseByDB (const std::string &db_name)
 
std::vector< SessionInfoPtrgetAllSessions ()
 
std::vector< SessionInfoPtrgetUserSessions (const std::string &user_name)
 
SessionInfoPtr getByPublicID (const std::string &public_id)
 
virtual ~SessionsStore ()=default
 
SessionInfo getSessionCopy (const std::string &session_id)
 
void disconnect (const std::string session_id)
 

Static Public Member Functions

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)
 

Protected Member Functions

bool isSessionExpired (const SessionInfoPtr &session_ptr, int idle_session_duration, int max_session_duration)
 
virtual bool isSessionInUse (const SessionInfoPtr &session_ptr)=0
 
virtual SessionInfoPtr getUnlocked (const std::string &session_id)=0
 
virtual void eraseUnlocked (const std::string &session_id)=0
 
virtual DisconnectCallback getDisconnectCallback ()=0
 
virtual std::vector
< SessionInfoPtr
getIf (std::function< bool(const SessionInfoPtr &)> predicate)=0
 
virtual void eraseIf (std::function< bool(const SessionInfoPtr &)> predicate)=0
 
virtual heavyai::shared_mutexgetLock ()=0
 

Detailed Description

Definition at line 31 of file SessionsStore.h.

Constructor & Destructor Documentation

virtual Catalog_Namespace::SessionsStore::~SessionsStore ( )
virtualdefault

Member Function Documentation

virtual SessionInfoPtr Catalog_Namespace::SessionsStore::add ( const Catalog_Namespace::UserMetadata user_meta,
std::shared_ptr< Catalog cat,
ExecutorDeviceType  device 
)
pure virtual

Implemented in CachedSessionStore.

std::unique_ptr< SessionsStore > SessionsStore::create ( const std::string &  base_path,
size_t  n_workers,
int  idle_session_duration,
int  max_session_duration,
int  capacity,
DisconnectCallback  disconnect_callback 
)
static

Definition at line 241 of file SessionsStore.cpp.

Referenced by DBHandler::resetSessionsStore().

247  {
248  return std::make_unique<CachedSessionStore>(
249  idle_session_duration, max_session_duration, capacity, disconnect_callback);
250 }

+ Here is the caller graph for this function:

void SessionsStore::disconnect ( const std::string  session_id)

Definition at line 54 of file SessionsStore.cpp.

References eraseUnlocked(), getDisconnectCallback(), getLock(), getUnlocked(), logger::INFO, and LOG.

54  {
56  auto session_ptr = getUnlocked(session_id);
57  if (session_ptr) {
58  const auto dbname = session_ptr->getCatalog().getCurrentDB().dbName;
59  LOG(INFO) << "User " << session_ptr->get_currentUser().userLoggable()
60  << " disconnected from database " << dbname
61  << " with public_session_id: " << session_ptr->get_public_session_id();
62  getDisconnectCallback()(session_ptr);
63  eraseUnlocked(session_ptr->get_session_id());
64  }
65 }
std::lock_guard< T > lock_guard
virtual SessionInfoPtr getUnlocked(const std::string &session_id)=0
#define LOG(tag)
Definition: Logger.h:285
virtual void eraseUnlocked(const std::string &session_id)=0
virtual DisconnectCallback getDisconnectCallback()=0
virtual heavyai::shared_mutex & getLock()=0

+ Here is the call graph for this function:

void SessionsStore::erase ( const std::string &  session_id)

Definition at line 37 of file SessionsStore.cpp.

References eraseUnlocked(), and getLock().

37  {
39  eraseUnlocked(session_id);
40 }
std::lock_guard< T > lock_guard
virtual void eraseUnlocked(const std::string &session_id)=0
virtual heavyai::shared_mutex & getLock()=0

+ Here is the call graph for this function:

void SessionsStore::eraseByDB ( const std::string &  db_name)

Definition at line 48 of file SessionsStore.cpp.

References eraseIf().

48  {
49  eraseIf([&db_name](const SessionInfoPtr& session_ptr) {
50  return boost::iequals(db_name, session_ptr->getCatalog().getCurrentDB().dbName);
51  });
52 }
virtual void eraseIf(std::function< bool(const SessionInfoPtr &)> predicate)=0
std::shared_ptr< SessionInfo > SessionInfoPtr
Definition: SessionsStore.h:27

+ Here is the call graph for this function:

void SessionsStore::eraseByUser ( const std::string &  user_name)

Definition at line 42 of file SessionsStore.cpp.

References eraseIf().

42  {
43  eraseIf([&user_name](const SessionInfoPtr& session_ptr) {
44  return boost::iequals(user_name, session_ptr->get_currentUser().userName);
45  });
46 }
virtual void eraseIf(std::function< bool(const SessionInfoPtr &)> predicate)=0
std::shared_ptr< SessionInfo > SessionInfoPtr
Definition: SessionsStore.h:27

+ Here is the call graph for this function:

virtual void Catalog_Namespace::SessionsStore::eraseIf ( std::function< bool(const SessionInfoPtr &)>  predicate)
protectedpure virtual

Implemented in CachedSessionStore.

Referenced by eraseByDB(), and eraseByUser().

+ Here is the caller graph for this function:

virtual void Catalog_Namespace::SessionsStore::eraseUnlocked ( const std::string &  session_id)
protectedpure virtual

Implemented in CachedSessionStore.

Referenced by disconnect(), and erase().

+ Here is the caller graph for this function:

virtual SessionInfoPtr Catalog_Namespace::SessionsStore::get ( const std::string &  session_id)
pure virtual

Implemented in CachedSessionStore.

std::vector< SessionInfoPtr > SessionsStore::getAllSessions ( )

Definition at line 93 of file SessionsStore.cpp.

References getIf().

93  {
94  return getIf([](const SessionInfoPtr&) { return true; });
95 }
virtual std::vector< SessionInfoPtr > getIf(std::function< bool(const SessionInfoPtr &)> predicate)=0
std::shared_ptr< SessionInfo > SessionInfoPtr
Definition: SessionsStore.h:27

+ Here is the call graph for this function:

SessionInfoPtr SessionsStore::getByPublicID ( const std::string &  public_id)

Definition at line 103 of file SessionsStore.cpp.

References CHECK_EQ, and getIf().

103  {
104  auto sessions = getIf([&public_id](const SessionInfoPtr& session_ptr) {
105  return session_ptr->get_public_session_id() == public_id;
106  });
107  if (sessions.empty()) {
108  return nullptr;
109  }
110  CHECK_EQ(sessions.size(), 1ul);
111  return sessions[0];
112 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
virtual std::vector< SessionInfoPtr > getIf(std::function< bool(const SessionInfoPtr &)> predicate)=0
std::shared_ptr< SessionInfo > SessionInfoPtr
Definition: SessionsStore.h:27

+ Here is the call graph for this function:

virtual DisconnectCallback Catalog_Namespace::SessionsStore::getDisconnectCallback ( )
protectedpure virtual

Implemented in CachedSessionStore.

Referenced by disconnect().

+ Here is the caller graph for this function:

virtual std::vector<SessionInfoPtr> Catalog_Namespace::SessionsStore::getIf ( std::function< bool(const SessionInfoPtr &)>  predicate)
protectedpure virtual

Implemented in CachedSessionStore.

Referenced by getAllSessions(), getByPublicID(), and getUserSessions().

+ Here is the caller graph for this function:

virtual heavyai::shared_mutex& Catalog_Namespace::SessionsStore::getLock ( )
protectedpure virtual

Implemented in CachedSessionStore.

Referenced by disconnect(), and erase().

+ Here is the caller graph for this function:

SessionInfo SessionsStore::getSessionCopy ( const std::string &  session_id)

Definition at line 28 of file SessionsStore.cpp.

28  {
29  auto origin = get(session_id);
30  if (origin) {
31  heavyai::shared_lock<heavyai::shared_mutex> lock(origin->getLock());
32  return *origin;
33  }
34  throw std::runtime_error("No session with id " + session_id);
35 }
std::shared_lock< T > shared_lock
virtual SessionInfoPtr Catalog_Namespace::SessionsStore::getUnlocked ( const std::string &  session_id)
protectedpure virtual

Implemented in CachedSessionStore.

Referenced by disconnect().

+ Here is the caller graph for this function:

std::vector< SessionInfoPtr > SessionsStore::getUserSessions ( const std::string &  user_name)

Definition at line 97 of file SessionsStore.cpp.

References getIf().

97  {
98  return getIf([&user_name](const SessionInfoPtr& session_ptr) {
99  return session_ptr->get_currentUser().userName == user_name;
100  });
101 }
virtual std::vector< SessionInfoPtr > getIf(std::function< bool(const SessionInfoPtr &)> predicate)=0
std::shared_ptr< SessionInfo > SessionInfoPtr
Definition: SessionsStore.h:27

+ Here is the call graph for this function:

bool SessionsStore::isSessionExpired ( const SessionInfoPtr session_ptr,
int  idle_session_duration,
int  max_session_duration 
)
protected

Definition at line 67 of file SessionsStore.cpp.

References logger::INFO, isSessionInUse(), LOG, and run_benchmark_import::start_time.

Referenced by CachedSessionStore::get().

69  {
70  if (isSessionInUse(session_ptr)) {
71  return false;
72  }
73  time_t last_used_time = session_ptr->get_last_used_time();
74  time_t start_time = session_ptr->get_start_time();
75  const auto current_session_duration = time(0) - last_used_time;
76  if (current_session_duration > idle_session_duration) {
77  LOG(INFO) << "Session " << session_ptr->get_public_session_id() << " idle duration "
78  << current_session_duration << " seconds exceeds maximum idle duration "
79  << idle_session_duration << " seconds. Invalidating session.";
80  return true;
81  }
82  const auto total_session_duration = time(0) - start_time;
83  if (total_session_duration > max_session_duration) {
84  LOG(INFO) << "Session " << session_ptr->get_public_session_id() << " total duration "
85  << total_session_duration
86  << " seconds exceeds maximum total session duration "
87  << max_session_duration << " seconds. Invalidating session.";
88  return true;
89  }
90  return false;
91 }
#define LOG(tag)
Definition: Logger.h:285
virtual bool isSessionInUse(const SessionInfoPtr &session_ptr)=0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual bool Catalog_Namespace::SessionsStore::isSessionInUse ( const SessionInfoPtr session_ptr)
protectedpure virtual

Implemented in CachedSessionStore.

Referenced by isSessionExpired().

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: