Skip to content

Commit

Permalink
Refactor most of the filesystem logic out of Client and move under a …
Browse files Browse the repository at this point in the history
…common mutex
  • Loading branch information
Jason Gauci committed May 7, 2019
1 parent 0ced2ca commit e3f0716
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 186 deletions.
4 changes: 2 additions & 2 deletions src/base/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace codefs {
string FileSystem::serializeFileDataCompressed(const string& path) {
std::lock_guard<std::recursive_mutex> lock(fileDataMutex);
std::lock_guard<std::recursive_mutex> lock(mutex);
MessageWriter writer;
if (allFileData.find(path) == allFileData.end()) {
writer.writePrimitive<int>(0);
Expand All @@ -25,7 +25,7 @@ string FileSystem::serializeFileDataCompressed(const string& path) {

void FileSystem::deserializeFileDataCompressed(const string& path,
const string& s) {
std::lock_guard<std::recursive_mutex> lock(fileDataMutex);
std::lock_guard<std::recursive_mutex> lock(mutex);
MessageReader reader;
reader.load(decompressString(s));
int numFiles = reader.readPrimitive<int>();
Expand Down
14 changes: 7 additions & 7 deletions src/base/FileSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FileSystem {
}

virtual optional<FileData> getNode(const string &path) {
std::lock_guard<std::recursive_mutex> lock(fileDataMutex);
std::lock_guard<std::recursive_mutex> lock(mutex);
auto it = allFileData.find(path);
if (it == allFileData.end()) {
return nullopt;
Expand All @@ -20,7 +20,7 @@ class FileSystem {
}

void setNode(const FileData &fileData) {
std::lock_guard<std::recursive_mutex> lock(fileDataMutex);
std::lock_guard<std::recursive_mutex> lock(mutex);
allFileData.erase(fileData.path());
if (fileData.deleted()) {
// The node is deleted, Don't add
Expand All @@ -35,15 +35,15 @@ class FileSystem {
}

void createStub(const string &path) {
std::lock_guard<std::recursive_mutex> lock(fileDataMutex);
std::lock_guard<std::recursive_mutex> lock(mutex);
FileData stub;
stub.set_path(path);
stub.set_invalid(true);
setNode(stub);
}

void deleteNode(const string &path) {
std::lock_guard<std::recursive_mutex> lock(fileDataMutex);
std::lock_guard<std::recursive_mutex> lock(mutex);
auto it = allFileData.find(path);
if (it != allFileData.end()) {
allFileData.erase(it);
Expand All @@ -53,8 +53,8 @@ class FileSystem {
virtual string absoluteToRelative(const string &absolutePath) {
if (absolutePath.find(rootPath) != 0) {
LOGFATAL << "Tried to convert absolute path to fuse that wasn't inside "
"the absolute FS: "
<< absolutePath << " " << rootPath;
"the absolute FS: "
<< absolutePath << " " << rootPath;
}
string relative = absolutePath.substr(rootPath.size());
if (relative.length() == 0) {
Expand Down Expand Up @@ -107,7 +107,7 @@ class FileSystem {
protected:
string rootPath;
shared_ptr<thread> fuseThread;
std::recursive_mutex fileDataMutex;
std::recursive_mutex mutex;
};
} // namespace codefs

Expand Down
Loading

0 comments on commit e3f0716

Please sign in to comment.