OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
foreign_storage::ForeignTableRefreshScheduler Class Reference

#include <ForeignTableRefreshScheduler.h>

Static Public Member Functions

static void start (std::atomic< bool > &is_program_running)
 
static void stop ()
 
static void setWaitDuration (int64_t duration_in_seconds)
 
static bool isRunning ()
 
static bool hasRefreshedTable ()
 
static void resetHasRefreshedTable ()
 

Static Private Member Functions

static void invalidateQueryEngineCaches ()
 

Static Private Attributes

static std::atomic< bool > is_scheduler_running_ {false}
 
static std::chrono::seconds thread_wait_duration_ {60}
 
static std::thread scheduler_thread_
 
static std::atomic< bool > has_refreshed_table_ {false}
 
static std::mutex wait_mutex_
 
static std::condition_variable wait_condition_
 

Detailed Description

Definition at line 26 of file ForeignTableRefreshScheduler.h.

Member Function Documentation

bool foreign_storage::ForeignTableRefreshScheduler::hasRefreshedTable ( )
static

Definition at line 100 of file ForeignTableRefreshScheduler.cpp.

References has_refreshed_table_.

100  {
101  return has_refreshed_table_;
102 }
void foreign_storage::ForeignTableRefreshScheduler::invalidateQueryEngineCaches ( )
staticprivate

Definition at line 25 of file ForeignTableRefreshScheduler.cpp.

References legacylockmgr::ExecutorOuterLock, legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), and CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCaches().

Referenced by start().

25  {
26  auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
29  // todo (yoonmin): support per-table invalidation
32 }
static void invalidateCaches()
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool foreign_storage::ForeignTableRefreshScheduler::isRunning ( )
static

Definition at line 96 of file ForeignTableRefreshScheduler.cpp.

References is_scheduler_running_.

96  {
97  return is_scheduler_running_;
98 }
void foreign_storage::ForeignTableRefreshScheduler::resetHasRefreshedTable ( )
static

Definition at line 104 of file ForeignTableRefreshScheduler.cpp.

References has_refreshed_table_.

104  {
105  has_refreshed_table_ = false;
106 }
void foreign_storage::ForeignTableRefreshScheduler::setWaitDuration ( int64_t  duration_in_seconds)
static

Definition at line 92 of file ForeignTableRefreshScheduler.cpp.

References thread_wait_duration_.

92  {
93  thread_wait_duration_ = std::chrono::seconds{duration_in_seconds};
94 }
void foreign_storage::ForeignTableRefreshScheduler::start ( std::atomic< bool > &  is_program_running)
static

Definition at line 34 of file ForeignTableRefreshScheduler.cpp.

References logger::ERROR, has_refreshed_table_, Catalog_Namespace::SysCatalog::instance(), invalidateQueryEngineCaches(), is_scheduler_running_, LOG, foreign_storage::refresh_foreign_table(), scheduler_thread_, run_benchmark_import::tables, thread_wait_duration_, wait_condition_, and wait_mutex_.

Referenced by startHeavyDBServer().

34  {
35  if (is_program_running && !is_scheduler_running_) {
36  is_scheduler_running_ = true;
37  scheduler_thread_ = std::thread([&is_program_running]() {
38  while (is_program_running && is_scheduler_running_) {
39  auto& sys_catalog = Catalog_Namespace::SysCatalog::instance();
40  // Exit if scheduler has been stopped asynchronously
41  if (!is_program_running || !is_scheduler_running_) {
42  return;
43  }
44  bool at_least_one_table_refreshed = false;
45  for (const auto& catalog : sys_catalog.getCatalogsForAllDbs()) {
46  // Exit if scheduler has been stopped asynchronously
47  if (!is_program_running || !is_scheduler_running_) {
48  return;
49  }
50  auto tables = catalog->getAllForeignTablesForRefresh();
51  for (auto table : tables) {
52  // Exit if scheduler has been stopped asynchronously
53  if (!is_program_running || !is_scheduler_running_) {
54  return;
55  }
56  try {
57  refresh_foreign_table(*catalog, table->tableName, false);
58  } catch (std::runtime_error& e) {
59  LOG(ERROR) << "Scheduled refresh for table \"" << table->tableName
60  << "\" resulted in an error. " << e.what();
61  }
62  has_refreshed_table_ = true;
63  at_least_one_table_refreshed = true;
64  }
65  }
66  if (at_least_one_table_refreshed) {
68  }
69  // Exit if scheduler has been stopped asynchronously
70  if (!is_program_running || !is_scheduler_running_) {
71  return;
72  }
73 
74  // A condition variable is used here (instead of a sleep call)
75  // in order to allow for thread wake-up, even in the middle
76  // of a wait interval.
77  std::unique_lock<std::mutex> wait_lock(wait_mutex_);
78  wait_condition_.wait_for(wait_lock, thread_wait_duration_);
79  }
80  });
81  }
82 }
#define LOG(tag)
Definition: Logger.h:217
void refresh_foreign_table(Catalog_Namespace::Catalog &catalog, const std::string &table_name, const bool evict_cached_entries)
static SysCatalog & instance()
Definition: SysCatalog.h:337

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void foreign_storage::ForeignTableRefreshScheduler::stop ( )
static

Definition at line 84 of file ForeignTableRefreshScheduler.cpp.

References is_scheduler_running_, scheduler_thread_, and wait_condition_.

Referenced by startHeavyDBServer().

84  {
86  is_scheduler_running_ = false;
87  wait_condition_.notify_one();
88  scheduler_thread_.join();
89  }
90 }

+ Here is the caller graph for this function:

Member Data Documentation

std::atomic< bool > foreign_storage::ForeignTableRefreshScheduler::has_refreshed_table_ {false}
staticprivate

Definition at line 42 of file ForeignTableRefreshScheduler.h.

Referenced by hasRefreshedTable(), resetHasRefreshedTable(), and start().

std::atomic< bool > foreign_storage::ForeignTableRefreshScheduler::is_scheduler_running_ {false}
staticprivate

Definition at line 39 of file ForeignTableRefreshScheduler.h.

Referenced by isRunning(), start(), and stop().

std::thread foreign_storage::ForeignTableRefreshScheduler::scheduler_thread_
staticprivate

Definition at line 41 of file ForeignTableRefreshScheduler.h.

Referenced by start(), and stop().

std::chrono::seconds foreign_storage::ForeignTableRefreshScheduler::thread_wait_duration_ {60}
staticprivate

Definition at line 40 of file ForeignTableRefreshScheduler.h.

Referenced by setWaitDuration(), and start().

std::condition_variable foreign_storage::ForeignTableRefreshScheduler::wait_condition_
staticprivate

Definition at line 44 of file ForeignTableRefreshScheduler.h.

Referenced by start(), and stop().

std::mutex foreign_storage::ForeignTableRefreshScheduler::wait_mutex_
staticprivate

Definition at line 43 of file ForeignTableRefreshScheduler.h.

Referenced by start().


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