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

Method DoCopyToLocal

src/leveldb/table/persistent_cache_helper.cc:44–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44void PersistentCacheHelper::DoCopyToLocal(Env *env, const std::string &fname, uint64_t fsize,
45 const std::string &key,
46 std::shared_ptr<PersistentCache> p_cache) {
47 LEVELDB_LOG("Schedule Copy To Local: %s, Pending Num: %u\n", fname.c_str(), pending_num_.load());
48 uint64_t time_s = env->NowMicros();
49
50 std::unique_ptr<SequentialFile> dfs_file;
51 SequentialFile *tmp_file;
52 auto s = env->NewSequentialFile(fname, &tmp_file);
53
54 if (!s.ok()) {
55 LEVELDB_LOG("Copy To Local Failed %s : %s\n", fname.c_str(), s.ToString().c_str());
56 return;
57 }
58 dfs_file.reset(tmp_file);
59
60 WriteableCacheFile *cache_file;
61 s = p_cache->NewWriteableCacheFile(key, &cache_file);
62 if (!s.ok()) {
63 LEVELDB_LOG("Copy To Local Failed %s : %s\n", fname.c_str(), s.ToString().c_str());
64 return;
65 }
66 assert(cache_file->refs_);
67
68 std::unique_ptr<char[]> buf(new char[1048576]); // Read 1M data each time
69 Slice result;
70 size_t local_size = 0;
71
72 while (dfs_file->Read(1048576, &result, buf.get()).ok() && result.size() > 0 &&
73 cache_file->Append(result).ok()) {
74 local_size += result.size();
75 }
76
77 if (local_size == fsize) {
78 {
79 WriteLock _(&closing_file_rw_mutex_);
80 cache_file->Close(key);
81 }
82 uint64_t time_used = env->NowMicros() - time_s;
83 LEVELDB_LOG("copy %s to local success in %llu ms.\n", fname.c_str(),
84 static_cast<unsigned long long>(time_used) / 1000);
85 } else {
86 cache_file->Abandon();
87 uint64_t dfs_file_size = 0;
88 s = env->GetFileSize(fname, &dfs_file_size);
89 if (!s.ok()) {
90 LEVELDB_LOG("dfs GetFileSize fail %s : %s\n", fname.c_str(), s.ToString().c_str());
91 } else {
92 LEVELDB_LOG(
93 "copy %s to local fail, size %lu, dfs size %lu, local "
94 "size %lu\n",
95 fname.c_str(), fsize, dfs_file_size, local_size);
96 }
97 }
98}
99
100Status PersistentCacheHelper::TryReadFromPersistentCache(
101 const std::shared_ptr<PersistentCache> &p_cache, const Slice &key, uint64_t offset,

Callers

nothing calls this directly

Calls 13

NowMicrosMethod · 0.45
NewSequentialFileMethod · 0.45
okMethod · 0.45
ToStringMethod · 0.45
resetMethod · 0.45
NewWriteableCacheFileMethod · 0.45
ReadMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45
AppendMethod · 0.45
CloseMethod · 0.45
AbandonMethod · 0.45

Tested by

no test coverage detected