MCPcopy Create free account
hub / github.com/baidu/tera / GetPersistentCache

Function GetPersistentCache

src/io/utils_leveldb.cc:527–581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

525}
526
527leveldb::Status GetPersistentCache(std::shared_ptr<leveldb::PersistentCache>* cache) {
528 static std::shared_ptr<leveldb::PersistentCache> persistent_cache = nullptr;
529 static std::once_flag once_flag;
530 static leveldb::Status status;
531 std::call_once(once_flag, []() {
532 if (!FLAGS_tera_enable_persistent_cache) {
533 return;
534 }
535 auto& cache_paths = GetPersistentCachePaths();
536 auto& cache_sizes = GetPersistentCacheSizes();
537 if (!cache_sizes.empty() && (cache_sizes.size() != cache_paths.size())) {
538 LOG(FATAL) << "Unmatch cache size and cache path, please check tera.flag. Cache path num: "
539 << cache_paths.size() << ". Cache size num: " << cache_sizes.size();
540 }
541 if (cache_paths.empty()) {
542 status = leveldb::Status::InvalidArgument("Empty persistent cache path.");
543 return;
544 }
545 for (auto& cache_path : cache_paths) {
546 leveldb::Env::Default()->CreateDir(cache_path);
547 }
548 leveldb::EnvOptions opt;
549 opt.use_direct_io_read = FLAGS_tera_leveldb_use_direct_io_read;
550 opt.use_direct_io_write = FLAGS_tera_leveldb_use_direct_io_write;
551 opt.posix_write_buffer_size = FLAGS_tera_leveldb_posix_write_buffer_size;
552 std::vector<leveldb::PersistentCacheConfig> configs;
553 for (size_t i = 0; i != cache_paths.size(); ++i) {
554 uint64_t size{0};
555 status = GetPathDiskSize(cache_paths[i], &size);
556 if (!status.ok()) {
557 return;
558 }
559 assert(size > 2L << 30);
560 // Use 2G of cache size for persistent cache meta data and other overheads.
561 int64_t cache_size = cache_sizes.empty() ? size - (2L << 30) : cache_sizes[i] << 20;
562 configs.emplace_back(leveldb::Env::Default(), cache_paths[i], cache_size);
563
564 LOG(INFO) << "Initing persistent pache, path: " << cache_paths[i]
565 << ", size: " << utils::ConvertByteToString(size)
566 << ", cache size: " << utils::ConvertByteToString(cache_size);
567 configs.back().SetEnvOptions(opt);
568 configs.back().write_retry_times = FLAGS_persistent_cache_write_retry_times;
569 if (FLAGS_tera_enable_persistent_cache_transfer_flash_env_files) {
570 configs.back().transfer_flash_env_files = true;
571 }
572 }
573 status = leveldb::NewShardedPersistentCache(configs, &persistent_cache);
574 });
575
576 if (status.ok()) {
577 *cache = persistent_cache;
578 }
579
580 return status;
581}
582
583} // namespace io
584} // namespace leveldb

Callers 3

SetupOptionsForLGMethod · 0.85
InitCacheSystemMethod · 0.85

Calls 8

GetPathDiskSizeFunction · 0.85
ConvertByteToStringFunction · 0.85
SetEnvOptionsMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
CreateDirMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected