| 18 | } |
| 19 | |
| 20 | std::unique_ptr<CacheData> CacheData::downgradeCacheData(std::unique_ptr<CacheData> cacheData, std::string id, std::shared_ptr<Context> ctx) { |
| 21 | |
| 22 | // if its not a GPU cacheData, then we can't downgrade it, so we can just return it |
| 23 | if (cacheData->get_type() != ral::cache::CacheDataType::GPU){ |
| 24 | return cacheData; |
| 25 | } else { |
| 26 | CodeTimer cacheEventTimer(false); |
| 27 | cacheEventTimer.start(); |
| 28 | |
| 29 | std::unique_ptr<ral::frame::BlazingTable> table = cacheData->decache(); |
| 30 | |
| 31 | std::shared_ptr<spdlog::logger> cache_events_logger = spdlog::get("cache_events_logger"); |
| 32 | |
| 33 | // lets first try to put it into CPU |
| 34 | if (blazing_host_memory_resource::getInstance().get_memory_used() + table->sizeInBytes() < |
| 35 | blazing_host_memory_resource::getInstance().get_memory_limit()){ |
| 36 | |
| 37 | auto CPUCache = std::make_unique<CPUCacheData>(std::move(table)); |
| 38 | |
| 39 | cacheEventTimer.stop(); |
| 40 | if(cache_events_logger) { |
| 41 | cache_events_logger->info("{ral_id}|{query_id}|{message_id}|{cache_id}|{num_rows}|{num_bytes}|{event_type}|{timestamp_begin}|{timestamp_end}|{description}", |
| 42 | "ral_id"_a=(ctx ? ctx->getNodeIndex(ral::communication::CommunicationData::getInstance().getSelfNode()) : -1), |
| 43 | "query_id"_a=(ctx ? ctx->getContextToken() : -1), |
| 44 | "message_id"_a="", |
| 45 | "cache_id"_a=id, |
| 46 | "num_rows"_a=(CPUCache ? CPUCache->num_rows() : -1), |
| 47 | "num_bytes"_a=(CPUCache ? CPUCache->sizeInBytes() : -1), |
| 48 | "event_type"_a="DowngradeCacheData", |
| 49 | "timestamp_begin"_a=cacheEventTimer.start_time(), |
| 50 | "timestamp_end"_a=cacheEventTimer.end_time(), |
| 51 | "description"_a="Downgraded CacheData to CPU cache"); |
| 52 | } |
| 53 | return CPUCache; |
| 54 | } else { |
| 55 | // want to get only cache directory where orc files should be saved |
| 56 | std::string orc_files_path = ral::communication::CommunicationData::getInstance().get_cache_directory(); |
| 57 | |
| 58 | auto localCache = std::make_unique<CacheDataLocalFile>(std::move(table), orc_files_path, |
| 59 | (ctx ? std::to_string(ctx->getContextToken()) |
| 60 | : "none")); |
| 61 | |
| 62 | cacheEventTimer.stop(); |
| 63 | if(cache_events_logger) { |
| 64 | cache_events_logger->info("{ral_id}|{query_id}|{message_id}|{cache_id}|{num_rows}|{num_bytes}|{event_type}|{timestamp_begin}|{timestamp_end}|{description}", |
| 65 | "ral_id"_a=(ctx ? ctx->getNodeIndex(ral::communication::CommunicationData::getInstance().getSelfNode()) : -1), |
| 66 | "query_id"_a=(ctx ? ctx->getContextToken() : -1), |
| 67 | "message_id"_a="", |
| 68 | "cache_id"_a=id, |
| 69 | "num_rows"_a=(localCache ? localCache->num_rows() : -1), |
| 70 | "num_bytes"_a=(localCache ? localCache->sizeInBytes() : -1), |
| 71 | "event_type"_a="DowngradeCacheData", |
| 72 | "timestamp_begin"_a=cacheEventTimer.start_time(), |
| 73 | "timestamp_end"_a=cacheEventTimer.end_time(), |
| 74 | "description"_a="Downgraded CacheData to Disk cache to path: " + orc_files_path); |
| 75 | } |
| 76 | |
| 77 | return localCache; |
no test coverage detected