Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refresh hive table metadata forcely every 5min #18

Merged
merged 2 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/Storages/Hive/HiveCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void HiveMetastoreClient::tryCallHiveClient(std::function<void(ThriftHiveMetasto

HiveMetastoreClient::HiveTableMetadataPtr HiveMetastoreClient::getTableMetadata(const String & db_name, const String & table_name)
{
LOG_TRACE(log, "Get table metadata for {}.{}", db_name, table_name);
LOG_DEBUG(log, "Get table metadata for {}.{}", db_name, table_name);

auto table = std::make_shared<Apache::Hadoop::Hive::Table>();
std::vector<Apache::Hadoop::Hive::Partition> partitions;
Expand Down Expand Up @@ -128,7 +128,7 @@ std::vector<Apache::Hadoop::Hive::Partition> HiveMetastoreClient::HiveTableMetad

std::vector<HiveMetastoreClient::FileInfo> HiveMetastoreClient::HiveTableMetadata::getFilesByLocation(const HDFSFSPtr & fs, const String & location)
{
LOG_TRACE(log, "List directory {}", location);
LOG_DEBUG(log, "List directory {}", location);
std::map<String, PartitionInfo>::iterator it;
if (!empty_partition_keys)
{
Expand All @@ -139,7 +139,7 @@ std::vector<HiveMetastoreClient::FileInfo> HiveMetastoreClient::HiveTableMetadat

if (it->second.initialized)
{
LOG_TRACE(log, "Get {} files under directory {}", it->second.files.size(), location);
LOG_DEBUG(log, "Get {} files under directory {}", it->second.files.size(), location);
return it->second.files;
}
}
Expand All @@ -165,7 +165,7 @@ std::vector<HiveMetastoreClient::FileInfo> HiveMetastoreClient::HiveTableMetadat
it->second.files = result;
it->second.initialized = true;
}
LOG_TRACE(log, "Get {} files under directory {}", result.size(), location);
LOG_DEBUG(log, "Get {} files under directory {}", result.size(), location);
return result;
}

Expand Down Expand Up @@ -196,8 +196,9 @@ void HiveMetastoreClient::HiveTableMetadata::updateIfNeeded(const std::vector<Ap
new_partition_infos.emplace(partition.sd.location, std::move(it->second));
}
}

partition_infos.swap(new_partition_infos);
last_update_time = time(nullptr);
LOG_DEBUG(log, "Finish update metadata for table {}.{}", db_name, table_name);
}

bool HiveMetastoreClient::HiveTableMetadata::shouldUpdate(const std::vector<Apache::Hadoop::Hive::Partition> & partitions)
Expand All @@ -216,7 +217,9 @@ bool HiveMetastoreClient::HiveTableMetadata::shouldUpdate(const std::vector<Apac
if (!old_partition_info.haveSameParameters(partition))
return true;
}
return false;

auto now = time(nullptr);
return now - last_update_time >= 300;
}


Expand Down
1 change: 1 addition & 0 deletions src/Storages/Hive/HiveCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class HiveMetastoreClient
/// Mutex to protect partition_infos.
mutable std::mutex mutex;
std::map<String, PartitionInfo> partition_infos;
time_t last_update_time{0};

const bool empty_partition_keys;
const HiveFilesCachePtr hive_files_cache;
Expand Down