|
21 | 21 |
|
22 | 22 | #include "io/fs/file_handle_cache.h" |
23 | 23 |
|
| 24 | +#include <cstdint> |
24 | 25 | #include <thread> |
25 | 26 | #include <tuple> |
26 | 27 |
|
@@ -102,7 +103,7 @@ FileHandleCache::Accessor::~Accessor() { |
102 | 103 | #ifdef USE_HADOOP_HDFS |
103 | 104 | if (hdfsUnbufferFile(get()->file()) != 0) { |
104 | 105 | VLOG_FILE << "FS does not support file handle unbuffering, closing file=" |
105 | | - << _cache_accessor.get_key()->first; |
| 106 | + << _cache_accessor.get_key()->second.first; |
106 | 107 | destroy(); |
107 | 108 | } else { |
108 | 109 | // Calling explicit release to handle metrics |
@@ -150,11 +151,13 @@ Status FileHandleCache::get_file_handle(const hdfsFS& fs, const std::string& fna |
150 | 151 | FileHandleCache::Accessor* accessor, bool* cache_hit) { |
151 | 152 | DCHECK_GE(mtime, 0); |
152 | 153 | // Hash the key and get appropriate partition |
153 | | - int index = |
154 | | - HashUtil::hash(fname.data(), cast_set<int>(fname.size()), 0) % _cache_partitions.size(); |
| 154 | + uintptr_t fs_identity = reinterpret_cast<uintptr_t>(fs); |
| 155 | + uint32_t seed = HashUtil::hash(&fs_identity, sizeof(fs_identity), 0); |
| 156 | + int index = HashUtil::hash(fname.data(), cast_set<int>(fname.size()), seed) % |
| 157 | + _cache_partitions.size(); |
155 | 158 | FileHandleCachePartition& p = _cache_partitions[index]; |
156 | 159 |
|
157 | | - auto cache_key = std::make_pair(fname, mtime); |
| 160 | + auto cache_key = make_cache_key(fs, fname, mtime); |
158 | 161 |
|
159 | 162 | // If this requires a new handle, skip to the creation codepath. Otherwise, |
160 | 163 | // find an unused entry with the same mtime |
@@ -189,6 +192,15 @@ Status FileHandleCache::get_file_handle(const hdfsFS& fs, const std::string& fna |
189 | 192 | return Status::OK(); |
190 | 193 | } |
191 | 194 |
|
| 195 | +#ifdef BE_TEST |
| 196 | +bool FileHandleCache::same_cache_key_for_test(const hdfsFS& lhs_fs, const std::string& lhs_fname, |
| 197 | + int64_t lhs_mtime, const hdfsFS& rhs_fs, |
| 198 | + const std::string& rhs_fname, int64_t rhs_mtime) { |
| 199 | + return make_cache_key(lhs_fs, lhs_fname, lhs_mtime) == |
| 200 | + make_cache_key(rhs_fs, rhs_fname, rhs_mtime); |
| 201 | +} |
| 202 | +#endif |
| 203 | + |
192 | 204 | void FileHandleCache::_evict_handles_loop() { |
193 | 205 | while (!_is_shut_down.load()) { |
194 | 206 | if (_unused_handle_timeout_secs) { |
|
0 commit comments