Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curvefs/client: fix the problem that chunkCacheManager has been relea… #1178

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions curvefs/src/client/s3/client_s3_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ int FileCacheManager::ReadFromS3(const std::vector<S3ReadRequest> &requests,
<< ", len: " << (*responses)[i].GetBufLen();
}
DataCachePtr dataCache = std::make_shared<DataCache>(
s3ClientAdaptor_, chunkCacheManager.get(), chunkPos,
s3ClientAdaptor_, chunkCacheManager, chunkPos,
(*responses)[i].GetBufLen(), (*responses)[i].GetDataBuf());
chunkCacheManager->AddReadDataCache(dataCache);
i++;
Expand Down Expand Up @@ -1212,11 +1212,10 @@ DataCachePtr ChunkCacheManager::FindWriteableDataCache(
void ChunkCacheManager::WriteNewDataCache(S3ClientAdaptorImpl *s3ClientAdaptor,
uint32_t chunkPos, uint32_t len,
const char *data) {
DataCachePtr dataCache =
std::make_shared<DataCache>(s3ClientAdaptor, this, chunkPos, len, data);
DataCachePtr dataCache = std::make_shared<DataCache>(
s3ClientAdaptor, this->shared_from_this(), chunkPos, len, data);
VLOG(9) << "WriteNewDataCache chunkPos:" << chunkPos << ", len:" << len
<< ", new len:" << dataCache->GetLen()
<< ",chunkIndex:" << index_;
<< ", new len:" << dataCache->GetLen() << ",chunkIndex:" << index_;
WriteLockGuard writeLockGuard(rwLockWrite_);

auto ret = dataWCacheMap_.emplace(chunkPos, dataCache);
Expand Down Expand Up @@ -1426,7 +1425,7 @@ void ChunkCacheManager::UpdateWriteCacheMap(uint64_t oldChunkPos,
}

DataCache::DataCache(S3ClientAdaptorImpl *s3ClientAdaptor,
ChunkCacheManager *chunkCacheManager, uint64_t chunkPos,
ChunkCacheManagerPtr chunkCacheManager, uint64_t chunkPos,
uint64_t len, const char *data)
: s3ClientAdaptor_(s3ClientAdaptor), chunkCacheManager_(chunkCacheManager),
dirty_(true), delete_(false), inReadCache_(false) {
Expand Down
7 changes: 4 additions & 3 deletions curvefs/src/client/s3/client_s3_cache_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ using PageDataMap = std::map<uint64_t, PageData *>;
class DataCache : public std::enable_shared_from_this<DataCache> {
public:
DataCache(S3ClientAdaptorImpl *s3ClientAdaptor,
ChunkCacheManager *chunkCacheManager, uint64_t chunkPos,
ChunkCacheManagerPtr chunkCacheManager, uint64_t chunkPos,
uint64_t len, const char *data);
virtual ~DataCache() {
auto iter = dataMap_.begin();
Expand Down Expand Up @@ -171,7 +171,7 @@ class DataCache : public std::enable_shared_from_this<DataCache> {

private:
S3ClientAdaptorImpl *s3ClientAdaptor_;
ChunkCacheManager* chunkCacheManager_;
ChunkCacheManagerPtr chunkCacheManager_;
uint64_t chunkPos_; // useful chunkPos
uint64_t len_; // useful len
uint64_t actualChunkPos_; // after alignment the actual chunkPos
Expand Down Expand Up @@ -203,7 +203,8 @@ class S3ReadResponse {
uint64_t len_;
};

class ChunkCacheManager {
class ChunkCacheManager
: public std::enable_shared_from_this<ChunkCacheManager> {
public:
ChunkCacheManager(uint64_t index, S3ClientAdaptorImpl *s3ClientAdaptor)
: index_(index), s3ClientAdaptor_(s3ClientAdaptor) {}
Expand Down
6 changes: 3 additions & 3 deletions curvefs/test/client/fs_cache_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TEST(FsCacheManagerTest, test_read_lru_cache_size) {

for (size_t i = 0; i < maxReadCacheByte / smallDataCacheByte; ++i) {
manager.Set(std::make_shared<DataCache>(s3ClientAdaptor_,
mockCacheMgr.get(), 0,
mockCacheMgr, 0,
smallDataCacheByte, buf),
&outIter);
}
Expand All @@ -73,7 +73,7 @@ TEST(FsCacheManagerTest, test_read_lru_cache_size) {
.Times(expectCallTimes)
.WillRepeatedly(Invoke([&counter](uint64_t) { counter.Signal(); }));
manager.Set(std::make_shared<DataCache>(s3ClientAdaptor_,
mockCacheMgr.get(), 0,
mockCacheMgr, 0,
dataCacheByte, buf),
&outIter);

Expand All @@ -89,7 +89,7 @@ TEST(FsCacheManagerTest, test_read_lru_cache_size) {
.WillRepeatedly(Invoke([&counter](uint64_t) { counter.Signal(); }));

manager.Set(std::make_shared<DataCache>(s3ClientAdaptor_,
mockCacheMgr.get(), 0,
mockCacheMgr, 0,
dataCacheByte, buf),
&outIter);
counter.Wait();
Expand Down