Skip to content
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

Issue #336: Added throttling of repair messages (will add the retransmission of repair messages logic soon) #371

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/crdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ impl Crdt {
}
fn run_window_request(
window: &Window,
me: &ReplicatedData,
from: &ReplicatedData,
ix: u64,
blob_recycler: &BlobRecycler,
Expand All @@ -599,7 +600,17 @@ impl Crdt {
let rblob = blob.read().unwrap();
let blob_ix = rblob.get_index().expect("run_window_request get_index");
if blob_ix == ix {
let num_retransmits = rblob.meta.num_retransmits;

if me.current_leader_id == me.id &&
num_retransmits != 0 &&
!num_retransmits.is_power_of_two()
{
return None;
}

let out = blob_recycler.allocate();

// copy to avoid doing IO inside the lock
{
let mut outblob = out.write().unwrap();
Expand All @@ -611,6 +622,10 @@ impl Crdt {
//come up with a cleaner solution for this when sender signatures are checked
outblob.set_id(from.id).expect("blob set_id");
}

drop(rblob);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of dropping that, can you pass it back to the recycler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I'll add some tests. Here, I just wanted to release the read lock so that I can obtain the write lock to modify the blob, not free the underlying blob to the recycler.

let mut wblob = blob.write().unwrap();
wblob.meta.num_retransmits += 1;
return Some(out);
}
} else {
Expand Down Expand Up @@ -683,7 +698,7 @@ impl Crdt {
me.repair_addr
);
assert_ne!(from.repair_addr, me.repair_addr);
Self::run_window_request(&window, &from, ix, blob_recycler)
Self::run_window_request(&window, &me, &from, ix, blob_recycler)
}
Err(_) => {
warn!("deserialize crdt packet failed");
Expand Down Expand Up @@ -1092,18 +1107,18 @@ mod tests {
"127.0.0.1:1238".parse().unwrap(),
);
let recycler = BlobRecycler::default();
let rv = Crdt::run_window_request(&window, &me, 0, &recycler);
let rv = Crdt::run_window_request(&window, &me, &me, 0, &recycler);
assert!(rv.is_none());
let out = recycler.allocate();
out.write().unwrap().meta.size = 200;
window.write().unwrap()[0] = Some(out);
let rv = Crdt::run_window_request(&window, &me, 0, &recycler);
let rv = Crdt::run_window_request(&window, &me, &me, 0, &recycler);
assert!(rv.is_some());
let v = rv.unwrap();
//test we copied the blob
assert_eq!(v.read().unwrap().meta.size, 200);
let len = window.read().unwrap().len() as u64;
let rv = Crdt::run_window_request(&window, &me, len, &recycler);
let rv = Crdt::run_window_request(&window, &me, &me, len, &recycler);
assert!(rv.is_none());
}
}
1 change: 1 addition & 0 deletions src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub const NUM_BLOBS: usize = (NUM_PACKETS * PACKET_DATA_SIZE) / BLOB_SIZE;
#[repr(C)]
pub struct Meta {
pub size: usize,
pub num_retransmits: u64,
pub addr: [u16; 8],
pub port: u16,
pub v6: bool,
Expand Down