OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
foreign_storage::RefreshTimeCalculator Class Reference

#include <RefreshTimeCalculator.h>

Static Public Member Functions

static int64_t getNextRefreshTime (const std::map< std::string, std::string, std::less<>> &foreign_table_options)
 
static int64_t getCurrentTime ()
 
static void setMockCurrentTime (int64_t mock_current_time)
 
static void resetMockCurrentTime ()
 

Static Private Attributes

static std::atomic< bool > should_use_mock_current_time_ {false}
 
static std::atomic< int64_t > mock_current_time_ {0}
 

Detailed Description

Definition at line 25 of file RefreshTimeCalculator.h.

Member Function Documentation

int64_t foreign_storage::RefreshTimeCalculator::getCurrentTime ( )
static

Definition at line 76 of file RefreshTimeCalculator.cpp.

References CHECK_GT, mock_current_time_, and should_use_mock_current_time_.

Referenced by Catalog_Namespace::Catalog::getAllForeignTablesForRefresh(), getNextRefreshTime(), and Catalog_Namespace::Catalog::updateForeignTableRefreshTimes().

76  {
79  return mock_current_time_;
80  } else {
81  return std::chrono::duration_cast<std::chrono::seconds>(
82  std::chrono::system_clock::now().time_since_epoch())
83  .count();
84  }
85 }
static std::atomic< int64_t > mock_current_time_
#define CHECK_GT(x, y)
Definition: Logger.h:305
static std::atomic< bool > should_use_mock_current_time_

+ Here is the caller graph for this function:

int64_t foreign_storage::RefreshTimeCalculator::getNextRefreshTime ( const std::map< std::string, std::string, std::less<>> &  foreign_table_options)
static

Definition at line 51 of file RefreshTimeCalculator.cpp.

References CHECK, foreign_storage::anonymous_namespace{RefreshTimeCalculator.cpp}::get_interval_duration(), getCurrentTime(), foreign_storage::ForeignTable::NULL_REFRESH_TIME, foreign_storage::ForeignTable::REFRESH_INTERVAL_KEY, and foreign_storage::ForeignTable::REFRESH_START_DATE_TIME_KEY.

Referenced by Catalog_Namespace::anonymous_namespace{Catalog.cpp}::get_next_refresh_time().

52  {
53  int64_t current_time = getCurrentTime();
54  auto start_date_entry = foreign_table_options.find(
56  CHECK(start_date_entry != foreign_table_options.end());
57  auto start_date_time = dateTimeParse<kTIMESTAMP>(start_date_entry->second, 0);
58 
59  // If start date time is current or in the future, then that is the next refresh time
60  if (start_date_time >= current_time) {
61  return start_date_time;
62  }
63  auto interval_entry =
64  foreign_table_options.find(foreign_storage::ForeignTable::REFRESH_INTERVAL_KEY);
65  if (interval_entry != foreign_table_options.end()) {
66  auto interval_duration = get_interval_duration(interval_entry->second);
67  auto num_intervals =
68  (current_time - start_date_time + interval_duration - 1) / interval_duration;
69  return start_date_time + (num_intervals * interval_duration);
70  } else {
71  // If this was a one time refresh, then there is no next refresh time
73  }
74 }
static constexpr const char * REFRESH_START_DATE_TIME_KEY
Definition: ForeignTable.h:44
static constexpr const char * REFRESH_INTERVAL_KEY
Definition: ForeignTable.h:45
#define CHECK(condition)
Definition: Logger.h:291
static constexpr int NULL_REFRESH_TIME
Definition: ForeignTable.h:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void foreign_storage::RefreshTimeCalculator::resetMockCurrentTime ( )
static

Definition at line 92 of file RefreshTimeCalculator.cpp.

References mock_current_time_, and should_use_mock_current_time_.

92  {
95 }
static std::atomic< int64_t > mock_current_time_
static std::atomic< bool > should_use_mock_current_time_
void foreign_storage::RefreshTimeCalculator::setMockCurrentTime ( int64_t  mock_current_time)
static

Definition at line 87 of file RefreshTimeCalculator.cpp.

References mock_current_time_, and should_use_mock_current_time_.

87  {
88  mock_current_time_ = mock_current_time;
90 }
static std::atomic< int64_t > mock_current_time_
static std::atomic< bool > should_use_mock_current_time_

Member Data Documentation

std::atomic<int64_t> foreign_storage::RefreshTimeCalculator::mock_current_time_ {0}
inlinestaticprivate
std::atomic<bool> foreign_storage::RefreshTimeCalculator::should_use_mock_current_time_ {false}
inlinestaticprivate

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