-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_gridfs.cpp
More file actions
66 lines (52 loc) · 1.83 KB
/
Copy pathlocal_gridfs.cpp
File metadata and controls
66 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "local_gridfs.h"
#include "local_grid_file.h"
#include "fs_logger.h"
using namespace mgridfs;
map<string, LocalGridFile*> mgridfs::LocalGridFS::_localGridFileMap;
LocalGridFS::LocalGridFS() {
}
LocalGridFS::~LocalGridFS() {
}
LocalGridFS& LocalGridFS::get() {
static LocalGridFS localGridFS;
return localGridFS;
}
LocalGridFile* LocalGridFS::findByName(const string& filename) {
LocalGridFileMap::const_iterator pIt = _localGridFileMap.find(filename);
if (pIt == _localGridFileMap.end()) {
return NULL;
}
return pIt->second;
}
LocalGridFile* LocalGridFS::createFile(const string& filename) {
// Enhance further to include local on-disk and hybrid approach for managing files more
// efficiently without high RAM usage on the system
LocalGridFile* localGridFile = new (nothrow) LocalMemoryGridFile(filename);
if (localGridFile) {
// If the local file was allocated, add the specified filename to the map as well
_localGridFileMap.insert(LocalGridFileMap::value_type(filename, localGridFile));
}
return localGridFile;
}
bool LocalGridFS::releaseFile(const string& filename) {
LocalGridFileMap::const_iterator pIt = _localGridFileMap.find(filename);
if (pIt == _localGridFileMap.end()) {
warn() << "File not found for releaseFile {file: " << filename << "}" << endl;
return true; // Although file is not found, it is not really an error
}
LocalGridFile* localGridFile = pIt->second;
_localGridFileMap.erase(filename);
if (!localGridFile) {
error() << "Encountered NULL file entry in releaseFile {file: " << filename << "}" << endl;
return false;
}
if (localGridFile->flush()) {
warn() << "Failed to flush before deletion in releaseFile {file: " << filename << "}, may result in corrupt file data."
<< endl;
}
delete localGridFile;
return true;
}
bool LocalGridFS::releaseAllFiles(bool flushAll) {
return false;
}