update time on get

This commit is contained in:
andrew (from workstation) 2020-05-20 18:27:16 +02:00
parent 005675e140
commit 46ddfccaf1
3 changed files with 10 additions and 6 deletions

View File

@ -17,6 +17,7 @@ namespace td {
class FileId {
int32 id = 0;
int32 remote_id = 0;
int64 time = INT64_MAX;
public:
FileId() = default;
@ -34,10 +35,17 @@ class FileId {
return id > 0;
}
int32 get() const {
int32 get() {
time = std::time(nullptr);
return id;
}
int64 get_time() {
auto res = time;
time = INT64_MAX;
return res;
}
int32 get_remote() const {
return remote_id;
}

View File

@ -2941,13 +2941,11 @@ FileId FileManager::next_file_id() {
if (!empty_file_ids_.empty()) {
auto res = empty_file_ids_.back();
empty_file_ids_.pop_back();
file_id_insert_time_[res] = std::time(nullptr);
return FileId{res, 0};
}
auto id = (int32) file_id_info_.size();
FileId res(static_cast<int32>(id), 0);
file_id_insert_time_[id] = std::time(nullptr);
file_id_info_.push_back({});
return res;
}
@ -3488,8 +3486,7 @@ void FileManager::memory_cleanup() {
if (main_node_id != 0) {
auto &node = file_nodes_[main_node_id];
if (node != nullptr && ((int32) i) == node->main_file_id_.get()) {
if (time - file_id_insert_time_[i] > 60 * 5 /* MAIN FILE TTL */) {
file_id_insert_time_[i] = INT64_MAX;
if (time - node->main_file_id_.get_time() > 60 * 5 /* MAIN FILE TTL */) {
for (auto &file_id : node->file_ids_) {
/* DESTROY ASSOCIATED QUERIES */
destroy_query(file_id.get());

View File

@ -559,7 +559,6 @@ class FileManager : public FileLoadManager::Callback {
std::map<FullLocalFileLocation, FileId> local_location_to_file_id_;
std::map<FullGenerateFileLocation, FileId> generate_location_to_file_id_;
std::map<FileDbId, int32> pmc_id_to_file_node_id_;
std::unordered_map<int32, int64> file_id_insert_time_;
std::vector<FileIdInfo> file_id_info_;
vector<int32> empty_file_ids_;