Skip to content

[C++][Parquet] Thoughts on classes in key_toolkit.h #46217

@kapoisu

Description

@kapoisu

Describe the enhancement requested

KeyToolkit is used internally according to the comment. It looks more like a mere aggregate. I suggest redefine it as a struct and change existing member functions to free functions, which can be implemented by the public interfaces of existing member variables. The only exception which may introduce invariants is the first part of KeyToolket::RotateMasterKeys(),

const auto now = internal::CurrentTimePoint();
auto lock = last_cache_clean_for_key_rotation_time_mutex_.Lock();
if (now > last_cache_clean_for_key_rotation_time_ +
std::chrono::duration<double>(kCacheCleanPeriodForKeyRotation)) {
kek_write_cache_per_token().Clear();
last_cache_clean_for_key_rotation_time_ = now;
}
lock.Unlock();

However, TwoLevelCacheWithExpiration (the object return by kek_write_cache_per_token() in the code above) has nearly identical logic,

void CheckCacheForExpiredTokens(double cache_cleanup_period_seconds) {
auto lock = mutex_.Lock();
const auto now = internal::CurrentTimePoint();
if (now > (last_cache_cleanup_timestamp_ +
std::chrono::duration<double>(cache_cleanup_period_seconds))) {
RemoveExpiredEntriesNoMutex();
last_cache_cleanup_timestamp_ =
now + std::chrono::duration<double>(cache_cleanup_period_seconds);
}
}

except that the timestamp is set to now + cache_cleanup_period_seconds, which looks like a bug.

The same change can be applied to KeyWithMasterId.
I'll work on it if this gets approved.

Component(s)

C++

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions