Skip to content

Commit 6709c8d

Browse files
authored
chore(master): improve FS operations style (#658)
Main changes: - Rename gFilesystemOperations to gFSOperations, which is shorter and maintains the context. - Rename the functions in IFilesystemOperation interface to match better our code style. Signed-off-by: guillex <[email protected]>
2 parents 928b940 + bdb4a93 commit 6709c8d

23 files changed

+1009
-1076
lines changed

src/master/changelog.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ void load_changelogs() {
313313
uint64_t first = changelogGetFirstLogVersion(s);
314314
uint64_t last = changelogGetLastLogVersion(s);
315315
if (last >= first) {
316-
if (last >= gFilesystemOperations->fs_getversion()) { load_changelog(s); }
316+
if (last >= gFSOperations->getMetadataVersion()) { load_changelog(s); }
317317
} else {
318318
throw InitializeException(
319319
"changelog " + fullFileName +
320320
" inconsistent, "
321321
"use sfsmetarestore to recover the filesystem; "
322322
"current fs version: " +
323-
std::to_string(gFilesystemOperations->fs_getversion()) +
323+
std::to_string(gFSOperations->getMetadataVersion()) +
324324
", first change in the file: " + std::to_string(first));
325325
}
326326
} else if (oldExists && s != kChangelogFilename) {
@@ -346,7 +346,7 @@ void load_changelog(const std::string &path) {
346346
uint64_t appliedEntries = 0;
347347
while (std::getline(changelog, line).good()) {
348348
id = std::stoull(line, &end);
349-
if (id < gFilesystemOperations->fs_getversion()) {
349+
if (id < gFSOperations->getMetadataVersion()) {
350350
++skippedEntries;
351351
continue;
352352
} else if (!first) {

src/master/chunks.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class Chunk {
357357
Goal result;
358358
int prev_goal = -1;
359359
for (auto counter : goalCounters_) {
360-
const Goal &goal = gFilesystemOperations->fs_get_goal_definition(counter.goal);
360+
const Goal &goal = gFSOperations->getGoalDefinition(counter.goal);
361361
if (prev_goal != (int)counter.goal) {
362362
result.mergeIn(goal);
363363
prev_goal = counter.goal;
@@ -823,7 +823,7 @@ void chunk_emergency_increase_version(Chunk *c) {
823823
c->operation = Chunk::SET_VERSION;
824824
c->version++;
825825
chunk_update_checksum(c);
826-
gFilesystemOperations->fs_incversion(c->chunkid);
826+
gFSOperations->increaseChunkVersion(c->chunkid);
827827
emit_chunk_changed(c);
828828
}
829829

@@ -1105,7 +1105,7 @@ uint8_t chunk_multi_modify(uint64_t ochunkid, uint32_t *lockid, uint8_t goal,
11051105
return SAUNAFS_ERROR_NOCHUNKSERVERS;
11061106
}
11071107
}
1108-
ChunkCopiesCalculator calculator(gFilesystemOperations->fs_get_goal_definition(goal));
1108+
ChunkCopiesCalculator calculator(gFSOperations->getGoalDefinition(goal));
11091109
for (const auto &server_with_type : serversWithChunkTypes) {
11101110
calculator.addPart(server_with_type.second, MediaLabel::kWildcard);
11111111
}
@@ -1570,8 +1570,7 @@ void chunk_server_has_chunk(matocsserventry *ptr, uint64_t chunkid, uint32_t ver
15701570
// chunkserver has nonexistent chunk, so create it for future deletion
15711571
if (chunkid >= ChunksMetadata::getNextChunkId() &&
15721572
gChunkIdGenerator->isStrictlyMonotonic()) {
1573-
gFilesystemOperations->fs_set_nextchunkid(FsContext::getForMaster(eventloop_time()),
1574-
chunkid + 1);
1573+
gFSOperations->setNextChunkId(FsContext::getForMaster(eventloop_time()), chunkid + 1);
15751574
}
15761575
c = chunk_new(chunkid, new_version);
15771576
c->lockedto = (uint32_t)eventloop_time()+UNUSED_DELETE_TIMEOUT;

src/master/filesystem.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static void metadataPollServe(const std::vector<pollfd> &pdesc) {
117117
if (dumper->useMetarestore()) {
118118
// master should recalculate its checksum
119119
safs_pretty_syslog(LOG_WARNING, "dumping metadata failed, recalculating checksum");
120-
gFilesystemOperations->fs_start_checksum_recalculation();
120+
gFSOperations->startChecksumRecalculation();
121121
}
122122
unlink(kMetadataTmpFilename);
123123
}
@@ -229,9 +229,7 @@ static void ensureChunkIdGenerator() {
229229
}
230230

231231
static void initFSOperations() {
232-
if (!gFilesystemOperations) {
233-
gFilesystemOperations = std::make_unique<FilesystemOperationsBase>();
234-
}
232+
if (!gFSOperations) { gFSOperations = std::make_unique<FilesystemOperationsBase>(); }
235233
}
236234

237235
/* executed in master mode */
@@ -439,7 +437,7 @@ void fs_reload(void) {
439437

440438
void fs_unload() {
441439
safs_pretty_syslog(LOG_WARNING, "unloading filesystem at %" PRIu64,
442-
gFilesystemOperations->fs_getversion());
440+
gFSOperations->getMetadataVersion());
443441
restore_reset();
444442
matoclserv_session_unload();
445443
chunk_unload();

src/master/filesystem_checksum_updater.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ class ChecksumUpdater {
5454
lastEntry_ = gMetadata->metadataVersion;
5555
if (metadataserver::isMaster() && !gChecksumBackgroundUpdater.inProgress()) {
5656
std::string versionString = saunafsVersionToString(SAUNAFS_VERSHEX);
57-
uint64_t checksum = gFilesystemOperations->fs_checksum(ChecksumMode::kGetCurrent);
58-
gFilesystemOperations->fs_changelog(ts, "CHECKSUM(%s):%" PRIu64, versionString.c_str(),
59-
checksum);
57+
uint64_t checksum = gFSOperations->metadataChecksum(ChecksumMode::kGetCurrent);
58+
gFSOperations->changeLog(ts, "CHECKSUM(%s):%" PRIu64, versionString.c_str(), checksum);
6059
}
6160
}
6261

src/master/filesystem_node.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static uint64_t file_realsize(FSNodeFile *node, uint32_t nonzero_chunks, uint64_
148148
(void)file_size;
149149
return 0; // Doesn't really matter. Metarestore doesn't need this value
150150
#else
151-
const Goal &goal = gFilesystemOperations->fs_get_goal_definition(node->goal);
151+
const Goal &goal = gFSOperations->getGoalDefinition(node->goal);
152152

153153
uint64_t full_size = 0;
154154
for (const auto &slice : goal) {
@@ -1484,12 +1484,12 @@ uint8_t fsnodes_undel(uint32_t ts, FSNodeFile *node) {
14841484
assert(metadataserver::isMaster());
14851485
#endif
14861486

1487-
gFilesystemOperations->fs_changelog(
1488-
ts,
1489-
"CREATE(%" PRIiNode ",%s,%c,%d,%" PRIu32 ",%" PRIu32 ",%" PRIu32 "):%" PRIiNode,
1490-
p->id, fsnodes_escape_name(name).c_str(),
1491-
static_cast<char>(FSNodeType::kDirectory), n->mode & 07777, (uint32_t)0,
1492-
(uint32_t)0, (uint32_t)0, n->id);
1487+
gFSOperations->changeLog(ts,
1488+
"CREATE(%" PRIiNode ",%s,%c,%d,%" PRIu32 ",%" PRIu32
1489+
",%" PRIu32 "):%" PRIiNode,
1490+
p->id, fsnodes_escape_name(name).c_str(),
1491+
static_cast<char>(FSNodeType::kDirectory), n->mode & 07777,
1492+
(uint32_t)0, (uint32_t)0, (uint32_t)0, n->id);
14931493
}
14941494
p = static_cast<FSNodeDirectory*>(n);
14951495
assert(n->type == FSNodeType::kDirectory);

0 commit comments

Comments
 (0)