-
Notifications
You must be signed in to change notification settings - Fork 54
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
fix(uploader): fix for mismatched ordering of instructions #1858
Conversation
// | ||
// We cannot just disobey the instruction inside the child loop, as the mainloop would be expecting | ||
// a result back for a particular instruction. | ||
if !make_payments { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use if cost_map.is_empty() {
will be more readable ?
if !make_payments { | ||
got_a_previous_force_payment = true; | ||
warn!( | ||
"We were told to force make payment, but cost_map is empty, so we can't do that just yet. Waiting for a task to insert a quote into cost_map" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the msg actually shall be:
We were told cost_map is empty, i.e. no more payment to be maid
// We cannot just disobey the instruction inside the child loop, as the mainloop would be expecting | ||
// a result back for a particular instruction. | ||
if !make_payments { | ||
got_a_previous_force_payment = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better rename the var to be cost_map_was_emptied
make_payments | ||
}; | ||
|
||
if make_payments { | ||
// reset force_make_payment | ||
if got_a_previous_force_payment { | ||
info!("A task inserted a quote into cost_map, so we can now make a forced round of payment!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better change the comment msg to be:
New quote inserted into cost_map, after it was emptied, we shall make a forced round of payment
while let Some(payment) = make_payment_receiver.recv().await { | ||
let make_payments = if let Some((item, quote)) = payment { | ||
let xorname = item.xorname(); | ||
trace!("Inserted {xorname:?} into cost_map"); | ||
|
||
current_batch.push((xorname, quote.clone())); | ||
let _ = cost_map.insert(xorname, (quote.1, quote.2, quote.0.to_bytes())); | ||
cost_map.len() >= batch_size | ||
cost_map.len() >= batch_size || got_a_previous_force_payment | ||
} else { | ||
// using None to indicate as all paid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better update the comment to be :
When the received `payment` is `None`, it notifies no more payment to be made.
There shall be a round of `forced payment` to pay the remaining payments in the cost_map (less than batch_size)
With normal order, there shall be no more payment come in afterwards,
however it could be break due to async channel send.
Hence have to catering such `out-of-order` situation.
There can be a mismatch of ordering between the main loop and the make payment loop because
the instructions are sent via a task(channel.send().await). And there is no guarantee for the
order to come in the same order as they were sent.
We cannot just disobey the instruction inside the child loop, as the mainloop would be expecting
a result back for a particular instruction.