mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-01-30 14:25:36 +02:00
Add actions for building and testing (#8)
* Add a Github action for building and testing On Windows, -- -//third_party/... doesn't seem to work, so add all test directories manually. Also run the tests_*. We run only fastbuild tests here, since the opt tests will be run in the release workflow. Also fix a number of compilation and test issues found along the way.
This commit is contained in:
@@ -40,7 +40,7 @@ DataProvider::DataProvider(
|
||||
: prefetch_size_(prefetch_size),
|
||||
writer_(std::move(writer)),
|
||||
readers_(std::move(readers)),
|
||||
chunks_updated_(true),
|
||||
chunks_updated_{true},
|
||||
cleanup_timeout_sec_(cleanup_timeout_sec),
|
||||
access_idle_timeout_sec_(access_idle_timeout_sec) {
|
||||
if (writer_) {
|
||||
@@ -74,7 +74,7 @@ size_t DataProvider::PrefetchSize(size_t read_size) const {
|
||||
absl::StatusOr<size_t> DataProvider::Get(const ContentIdProto& content_id,
|
||||
void* data, size_t offset,
|
||||
size_t size) {
|
||||
last_access_ts_ = steady_clock_->Now();
|
||||
last_access_sec_ = GetSteadyNowSec();
|
||||
absl::Mutex* content_mutex = GetContentMutex(content_id);
|
||||
absl::StatusOr<size_t> read_bytes;
|
||||
if (writer_) {
|
||||
@@ -127,7 +127,7 @@ absl::StatusOr<size_t> DataProvider::Get(const ContentIdProto& content_id,
|
||||
}
|
||||
|
||||
absl::Status DataProvider::Get(ChunkTransferList* chunks) {
|
||||
last_access_ts_ = steady_clock_->Now();
|
||||
last_access_sec_ = GetSteadyNowSec();
|
||||
// Try to fetch chunks from the cache first.
|
||||
RETURN_IF_ERROR(GetFromWriter(chunks, /*lock_required=*/true));
|
||||
if (chunks->ReadDone()) return absl::OkStatus();
|
||||
@@ -175,7 +175,7 @@ absl::Status DataProvider::Get(ChunkTransferList* chunks) {
|
||||
}
|
||||
|
||||
absl::Status DataProvider::Get(const ContentIdProto& content_id, Buffer* data) {
|
||||
last_access_ts_ = steady_clock_->Now();
|
||||
last_access_sec_ = GetSteadyNowSec();
|
||||
absl::Mutex* content_mutex = GetContentMutex(content_id);
|
||||
absl::Status status = absl::OkStatus();
|
||||
if (writer_) {
|
||||
@@ -324,9 +324,7 @@ void DataProvider::CleanupThreadMain() {
|
||||
next_cleanup_time - steady_clock_->Now())
|
||||
.count())));
|
||||
int64_t time_sec_since_last_access =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(steady_clock_->Now() -
|
||||
last_access_ts_.load())
|
||||
.count();
|
||||
GetSteadyNowSec() - last_access_sec_.load();
|
||||
if (chunks_updated_ &&
|
||||
time_sec_since_last_access > access_idle_timeout_sec_) {
|
||||
WriterMutexLockList locks;
|
||||
@@ -361,4 +359,11 @@ bool DataProvider::WaitForCleanupAndResetForTesting(absl::Duration timeout) {
|
||||
is_cleaned_ = false;
|
||||
return is_cleaned;
|
||||
}
|
||||
|
||||
int64_t DataProvider::GetSteadyNowSec() {
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(steady_clock_->Now() -
|
||||
first_now_)
|
||||
.count();
|
||||
}
|
||||
|
||||
} // namespace cdc_ft
|
||||
|
||||
@@ -105,6 +105,9 @@ class DataProvider : public DataStoreReader {
|
||||
// Periodically cleans up data in |writer_|.
|
||||
void CleanupThreadMain() ABSL_LOCKS_EXCLUDED(shutdown_mutex_, cleaned_mutex_);
|
||||
|
||||
// Returns the current time of |steady_clock_| in seconds.
|
||||
int64_t GetSteadyNowSec();
|
||||
|
||||
static constexpr unsigned int kNumberOfMutexes = 256;
|
||||
|
||||
// How much additional data to prefetch when a max. FUSE read is encountered.
|
||||
@@ -124,15 +127,18 @@ class DataProvider : public DataStoreReader {
|
||||
// Indicates whether the shutdown was triggered.
|
||||
bool shutdown_ ABSL_GUARDED_BY(shutdown_mutex_) = false;
|
||||
|
||||
// The last access time.
|
||||
std::atomic<std::chrono::time_point<std::chrono::steady_clock>>
|
||||
last_access_ts_;
|
||||
// The last access time in seconds since construction. Note that for some
|
||||
// compilers we can't use std::chrono::time_point with atomics, so keep the
|
||||
// time in seconds.
|
||||
std::atomic<int64_t> last_access_sec_;
|
||||
|
||||
// Identifies if new data was added to the cache since the last cleanup.
|
||||
std::atomic<bool> chunks_updated_;
|
||||
|
||||
// Clock to track the last access time.
|
||||
SteadyClock* steady_clock_ = DefaultSteadyClock::GetInstance();
|
||||
const std::chrono::time_point<std::chrono::steady_clock> first_now_ =
|
||||
steady_clock_->Now();
|
||||
|
||||
// Cleanup interval.
|
||||
uint32_t cleanup_timeout_sec_ = kCleanupTimeoutSec;
|
||||
|
||||
Reference in New Issue
Block a user