| 147 | STATS_MAX_TUPLE_CACHE_ENTRY_SIZE, 3))) {} |
| 148 | |
| 149 | Status TupleCacheMgr::Init(int64_t process_bytes_limit) { |
| 150 | if (cache_config_.empty()) { |
| 151 | LOG(INFO) << "Tuple Cache is disabled."; |
| 152 | return Status::OK(); |
| 153 | } |
| 154 | |
| 155 | // The expected form of the configuration string is: dir1:capacity |
| 156 | // Example: /tmp/data1:1TB |
| 157 | vector<string> all_cache_configs = Split(cache_config_, ":", SkipEmpty()); |
| 158 | if (all_cache_configs.size() != 2) { |
| 159 | return Status(Substitute("Malformed data cache configuration $0", cache_config_)); |
| 160 | } |
| 161 | |
| 162 | // Parse the capacity string to make sure it's well-formed |
| 163 | bool is_percent = false; |
| 164 | int64_t capacity = ParseUtil::ParseMemSpec(all_cache_configs[1], &is_percent, 0); |
| 165 | if (is_percent) { |
| 166 | return Status(Substitute("Malformed tuple cache capacity configuration $0", |
| 167 | all_cache_configs[1])); |
| 168 | } |
| 169 | // For normal execution (not backend tests), impose a minimum size on the |
| 170 | // cache of 64MB. |
| 171 | if (!TestInfo::is_be_test() && capacity < MIN_TUPLE_CACHE_CAPACITY_BYTES) { |
| 172 | return Status(Substitute( |
| 173 | "Tuple cache capacity $0 is less than the minimum allowed capacity $1", |
| 174 | all_cache_configs[1], MIN_TUPLE_CACHE_CAPACITY_STR)); |
| 175 | } |
| 176 | |
| 177 | vector<string> cache_dirs = Split(all_cache_configs[0], ",", SkipEmpty()); |
| 178 | if (cache_dirs.size() > 1) { |
| 179 | return Status(Substitute("Malformed tuple cache directory $0. " |
| 180 | "The tuple cache only supports a single directory.", all_cache_configs[0])); |
| 181 | } |
| 182 | cache_dir_ = cache_dirs[0]; |
| 183 | |
| 184 | // Verify the validity of the path specified. |
| 185 | if (!FileSystemUtil::IsCanonicalPath(cache_dir_)) { |
| 186 | return Status(Substitute("$0 is not a canonical path", cache_dir_)); |
| 187 | } |
| 188 | RETURN_IF_ERROR(FileSystemUtil::VerifyIsDirectory(cache_dir_)); |
| 189 | |
| 190 | // Verify we can create a file in the cache directory |
| 191 | filesystem::path path = |
| 192 | filesystem::path(cache_dir_) / Substitute("$0test", CACHE_FILE_PREFIX); |
| 193 | RETURN_IF_ERROR(FileSystemUtil::CreateFile(path.string())); |
| 194 | |
| 195 | // Remove any existing cache files from the cache directory. This ensures that the |
| 196 | // usage starts at zero. This also removes the test file we just wrote. |
| 197 | RETURN_IF_ERROR(DeleteExistingFiles()); |
| 198 | |
| 199 | // Check that there is enough space available for the specified cache size |
| 200 | uint64_t available_bytes; |
| 201 | RETURN_IF_ERROR(FileSystemUtil::GetSpaceAvailable(cache_dir_, &available_bytes)); |
| 202 | if (available_bytes < capacity) { |
| 203 | string err = Substitute("Insufficient space for $0. Required $1. Only $2 is " |
| 204 | "available", cache_dir_, PrettyPrinter::PrintBytes(capacity), |
| 205 | PrettyPrinter::PrintBytes(available_bytes)); |
| 206 | LOG(ERROR) << err; |
nothing calls this directly
no test coverage detected