Skip to content

Commit 0be2f2d

Browse files
committed
Addressed the review comments.
1 parent b6afb96 commit 0be2f2d

File tree

5 files changed

+72
-44
lines changed

5 files changed

+72
-44
lines changed

turbonfs/inc/fcsm.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class fcsm
108108
void ensure_commit(uint64_t write_off,
109109
uint64_t write_len,
110110
struct rpc_task *task = nullptr,
111-
std::atomic<bool> *conditional_variable = nullptr);
111+
std::atomic<bool> *conditional_variable = nullptr,
112+
bool commit_full = false);
112113

113114
/**
114115
* Callbacks to be called when flush/commit successfully complete.

turbonfs/inc/nfs_inode.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ struct nfs_inode
333333
* Note: As of now, we are not using this flag as commit changes not yet
334334
* integrated, so we are setting this flag to true.
335335
*/
336-
bool stable_write = false;
336+
bool stable_write = true;
337337

338338
public:
339339
/*

turbonfs/src/fcsm.cpp

+42-6
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,12 @@ void fcsm::ctgtq_cleanup()
341341
void fcsm::ensure_commit(uint64_t write_off,
342342
uint64_t write_len,
343343
struct rpc_task *task,
344-
std::atomic<bool> *conditional_variable)
344+
std::atomic<bool> *conditional_variable,
345+
bool commit_full)
345346
{
346347
assert(inode->is_flushing);
347348
assert(!inode->is_stable_write());
349+
assert(!commit_full || task == nullptr);
348350

349351
/*
350352
* If any of the flush/commit targets are waiting completion, state machine
@@ -383,13 +385,23 @@ void fcsm::ensure_commit(uint64_t write_off,
383385
uint64_t commit_bytes =
384386
inode->get_filecache()->get_bytes_to_commit();
385387

388+
/*
389+
* If commit_full flag is true, wait_for_ongoing_flush()
390+
* committed the commit_pending bytes. Now we need to flush
391+
* dirty bytes and commit them.
392+
*/
393+
if (commit_full) {
394+
assert(commit_bytes == 0);
395+
commit_bytes = inode->get_filecache()->get_bytes_to_flush();
396+
}
397+
386398
if (commit_bytes == 0) {
387399
/*
388400
* TODO: Make sure this doesn't result in small-blocks being written.
389401
*/
390-
const int64_t bytes =
391-
inode->get_filecache()->get_bytes_to_flush() -
392-
inode->get_filecache()->max_dirty_extent_bytes();
402+
const int64_t bytes = (inode->get_filecache()->get_bytes_to_flush() -
403+
inode->get_filecache()->max_dirty_extent_bytes());
404+
393405
commit_bytes = std::max(bytes, (int64_t) 0);
394406
}
395407

@@ -477,11 +489,21 @@ void fcsm::ensure_commit(uint64_t write_off,
477489
ctgtq.emplace(this,
478490
0 /* target flush_seq */,
479491
target_committed_seq_num /* target commit_seq */,
480-
task);
492+
task,
493+
conditional_variable);
481494
} else {
482495
if (task) {
483496
task->reply_write(task->rpc_api->write_task.get_size());
484497
}
498+
499+
/*
500+
* Flush_cache_and_wait() waiting for dirty_bytes to flushed,
501+
* can't complete until all dirty bytes flushed. so add the
502+
* flush target.
503+
*/
504+
if (commit_full) {
505+
ensure_flush(0, 0, nullptr, conditional_variable);
506+
}
485507
}
486508

487509
return;
@@ -514,6 +536,12 @@ void fcsm::ensure_commit(uint64_t write_off,
514536

515537
assert(committing_seq_num == (prev_committing_seq_num + bytes));
516538
assert(committing_seq_num > committed_seq_num);
539+
540+
/*
541+
* Enqueue this target, on_commit_callback() completes
542+
* this target. Otherwise task/conditional_variable
543+
* waiting for this to complete never called.
544+
*/
517545
ctgtq.emplace(this,
518546
0 /* target flush_seq */,
519547
target_committed_seq_num /* target commit_seq */,
@@ -675,13 +703,21 @@ void fcsm::ensure_flush(uint64_t write_off,
675703
const uint64_t flushing_seq_num_before = flushing_seq_num;
676704
assert(flushed_seq_num <= flushing_seq_num);
677705

678-
// sync_membufs() will update flushing_seq_num() and mark fcsm running.
706+
/*
707+
* sync_membufs() will update flushing_seq_num() and mark fcsm running.
708+
* Task is not passed to sync_membufs, but enqueued to ftgtq.
709+
*/
679710
inode->sync_membufs(bc_vec, false /* is_flush */, nullptr);
680711

681712
assert(is_running());
682713
assert(flushing_seq_num == (flushing_seq_num_before + bytes));
683714
assert(flushed_seq_num <= flushing_seq_num);
684715

716+
/*
717+
* Enqueue this target, on_flush_complete() completes
718+
* this target. Otherwise task/conditional_variable
719+
* waiting for this to complete never called.
720+
*/
685721
ftgtq.emplace(this,
686722
target_flushed_seq_num /* target flush_seq */,
687723
0 /* commit_seq */,

turbonfs/src/nfs_inode.cpp

+13-22
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ nfs_inode::nfs_inode(const struct nfs_fh3 *filehandle,
3434
assert(write_error == 0);
3535

3636
// We start doing unstable writes until proven o/w.
37-
assert(stable_write == false);
37+
assert(stable_write == true);
3838
assert(commit_state == commit_state_t::COMMIT_NOT_NEEDED);
3939

4040
#ifndef ENABLE_NON_AZURE_NFS
@@ -554,8 +554,12 @@ bool nfs_inode::check_stable_write_required(off_t offset)
554554
void nfs_inode::commit_membufs(std::vector<bytes_chunk>& bc_vec)
555555
{
556556
assert(is_flushing);
557-
// Commit is only called by FCSM, so it must be running.
558-
// assert(get_fcsm()->is_running());
557+
558+
/*
559+
* Commit is only called by FCSM, either callback of completion
560+
* or inline as part of ensure_commit.
561+
*/
562+
assert(get_fcsm()->is_running() || !get_fcsm()->fc_cb_count());
559563

560564
set_commit_in_progress();
561565

@@ -1349,12 +1353,17 @@ int nfs_inode::flush_cache_and_wait()
13491353
*/
13501354
wait_for_ongoing_flush();
13511355
std::atomic_bool complete = false;
1356+
13521357
/*
13531358
* Set the flush target for both stable/unstable write.
13541359
* ensure_commit() doesn't set target for whole unflushed
13551360
* bytes.
13561361
*/
1357-
get_fcsm()->ensure_flush(0, 0, nullptr, &complete);
1362+
if (is_stable_write()) {
1363+
get_fcsm()->ensure_flush(0, 0, nullptr, &complete);
1364+
} else {
1365+
get_fcsm()->ensure_commit(0, 0, nullptr, &complete, true);
1366+
}
13581367
flush_unlock();
13591368

13601369
// Wait for flush to complete.
@@ -1368,24 +1377,6 @@ int nfs_inode::flush_cache_and_wait()
13681377
::usleep(1000);
13691378
}
13701379

1371-
flush_lock();
1372-
// Issue commit to commit_pending.
1373-
if (!is_stable_write()) {
1374-
complete = false;
1375-
get_fcsm()->ensure_commit(0, 0, nullptr, &complete);
1376-
}
1377-
flush_unlock();
1378-
1379-
iter = 0;
1380-
while (complete != true) {
1381-
if (++iter % 1000 == 0) {
1382-
AZLogWarn("[{}] flush_cache_and_wait() waiting for ongoing"
1383-
" flush to complete still waiting, iter: {}",
1384-
get_fuse_ino(), iter);
1385-
}
1386-
::usleep(1000);
1387-
}
1388-
13891380
return get_write_error();
13901381
}
13911382

turbonfs/src/rpc_task.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -877,20 +877,6 @@ static void commit_callback(
877877
AZLogDebug("[{}] commit_callback, number of bc committed: {}",
878878
ino, bc_vec_ptr->size());
879879

880-
#ifdef ENABLE_PARANOID
881-
/*
882-
* We always pick *all* commit-pending bcs for committing, and while commit
883-
* is going on no other flush can run, hence new commit pending bcs cannot
884-
* be added, so when an ongoing commit completes we we must not have any
885-
* commit pending bcs in the cache.
886-
*/
887-
{
888-
std::vector<bytes_chunk> bc_vec =
889-
inode->get_filecache()->get_commit_pending_bcs();
890-
assert(bc_vec.empty());
891-
}
892-
#endif
893-
894880
uint64_t commit_bytes = 0;
895881
/*
896882
* Now that the request has completed, we can query libnfs for the
@@ -998,6 +984,20 @@ static void commit_callback(
998984
inode->set_stable_write();
999985
}
1000986

987+
#ifdef ENABLE_PARANOID
988+
/*
989+
* We always pick *all* commit-pending bcs for committing, and while commit
990+
* is going on no other flush can run, hence new commit pending bcs cannot
991+
* be added, so when an ongoing commit completes we we must not have any
992+
* commit pending bcs in the cache.
993+
*/
994+
{
995+
std::vector<bytes_chunk> bc_vec =
996+
inode->get_filecache()->get_commit_pending_bcs();
997+
assert(bc_vec.empty());
998+
}
999+
#endif
1000+
10011001
if (status == 0) {
10021002
assert(commit_bytes > 0);
10031003
/*

0 commit comments

Comments
 (0)