Skip to content

Commit

Permalink
Renamed agent assignment ClientData item_times to lv_for_seq
Browse files Browse the repository at this point in the history
  • Loading branch information
josephg committed Oct 27, 2023
1 parent fa0550e commit bebdd75
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
16 changes: 8 additions & 8 deletions src/causalgraph/agent_assignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) struct ClientData {
/// might be ordered as (0, 2, 1). This will only happen when changes are concurrent. The order
/// of time spans must always obey the partial order of changes. But it will not necessarily
/// agree with the order amongst time spans.
pub(crate) item_times: RleVec<KVPair<DTRange>>,
pub(crate) lv_for_seq: RleVec<KVPair<DTRange>>,
}

#[derive(Debug, Clone, Default)]
Expand All @@ -47,16 +47,16 @@ pub struct AgentAssignment {

impl ClientData {
pub fn get_next_seq(&self) -> usize {
self.item_times.end()
self.lv_for_seq.end()
}

pub fn is_empty(&self) -> bool {
self.item_times.is_empty()
self.lv_for_seq.is_empty()
}

#[inline]
pub(crate) fn try_seq_to_lv(&self, seq: usize) -> Option<LV> {
let (entry, offset) = self.item_times.find_with_offset(seq)?;
let (entry, offset) = self.lv_for_seq.find_with_offset(seq)?;
Some(entry.1.start + offset)
}

Expand All @@ -66,7 +66,7 @@ impl ClientData {

/// Note the returned timespan might be shorter than seq_range.
pub fn try_seq_to_lv_span(&self, seq_range: DTRange) -> Option<DTRange> {
let (KVPair(_, entry), offset) = self.item_times.find_with_offset(seq_range.start)?;
let (KVPair(_, entry), offset) = self.lv_for_seq.find_with_offset(seq_range.start)?;

let start = entry.start + offset;
let end = usize::min(entry.end, start + seq_range.len());
Expand Down Expand Up @@ -101,7 +101,7 @@ impl AgentAssignment {
// Create a new id.
self.client_data.push(ClientData {
name: SmartString::from(name),
item_times: RleVec::new()
lv_for_seq: RleVec::new()
});
(self.client_data.len() - 1) as AgentId
}
Expand All @@ -119,7 +119,7 @@ impl AgentAssignment {
///
/// The items returned will always be in sequence order.
pub fn iter_lv_map_for_agent(&self, agent: AgentId) -> impl Iterator<Item = (usize, usize, usize)> + '_ {
self.client_data[agent as usize].item_times.iter()
self.client_data[agent as usize].lv_for_seq.iter()
.map(|KVPair(seq, lv_range)| { (*seq, lv_range.start, lv_range.len()) })
}

Expand Down Expand Up @@ -163,7 +163,7 @@ impl AgentAssignment {
let client_data = &mut self.client_data[agent as usize];

let next_seq = client_data.get_next_seq();
client_data.item_times.push(KVPair(next_seq, span));
client_data.lv_for_seq.push(KVPair(next_seq, span));

self.client_with_localtime.push(KVPair(span.start, AgentSpan {
agent,
Expand Down
12 changes: 6 additions & 6 deletions src/causalgraph/causalgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl CausalGraph {

// Make sure the time isn't already assigned. Can I elide this check in release mode?
// Note I only need to check the start of the seq_range.
let (x, _offset) = client_data.item_times.find_sparse(span.seq_range.start);
let (x, _offset) = client_data.lv_for_seq.find_sparse(span.seq_range.start);
if let Err(range) = x {
assert!(range.end >= span.seq_range.end, "Time range already assigned");
} else {
Expand All @@ -113,7 +113,7 @@ impl CausalGraph {

// Almost always appending to the end but its possible for the same agent ID to be used on
// two concurrent branches, then transmitted in a different order.
client_data.item_times.insert(KVPair(span.seq_range.start, time_span));
client_data.lv_for_seq.insert(KVPair(span.seq_range.start, time_span));
self.agent_assignment.client_with_localtime.push(KVPair(time_start, span));
self.graph.push(parents, time_span);
self.version.advance_by_known_run(parents, time_span);
Expand Down Expand Up @@ -145,15 +145,15 @@ impl CausalGraph {
// 3. There's some overlap. The overlap must be at the start of the entry, because all of
// each item's parents must be known.

match client_data.item_times.find_index(span.seq_range.last()) {
match client_data.lv_for_seq.find_index(span.seq_range.last()) {
Ok(_idx) => {
// If we know the last ID, the entire entry is known. Case 1 - discard and return.
(time_start..time_start).into()
}
Err(idx) => {
// idx is the index where the item could be inserted to maintain order.
if idx >= 1 { // if idx == 0, there's no overlap anyway.
let prev_entry = &mut client_data.item_times.0[idx - 1];
let prev_entry = &mut client_data.lv_for_seq.0[idx - 1];
let previous_end = prev_entry.end();

if previous_end >= span.seq_range.start {
Expand Down Expand Up @@ -182,7 +182,7 @@ impl CausalGraph {
if prev_entry.can_append(&new_entry) {
prev_entry.append(new_entry);
} else {
client_data.item_times.0.insert(idx, new_entry);
client_data.lv_for_seq.0.insert(idx, new_entry);
}

return time_span;
Expand All @@ -191,7 +191,7 @@ impl CausalGraph {

// We know it can't combine with the previous element.
let time_span = (time_start..time_start + span.len()).into();
client_data.item_times.0.insert(idx, KVPair(span.seq_range.start, time_span));
client_data.lv_for_seq.0.insert(idx, KVPair(span.seq_range.start, time_span));
self.agent_assignment.client_with_localtime.push(KVPair(time_start, span));
self.graph.push(parents, time_span);
self.version.advance_by_known_run(parents, time_span);
Expand Down
4 changes: 2 additions & 2 deletions src/causalgraph/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ impl AgentAssignment {

let span = pair.1;
let client = &self.client_data[span.agent as usize];
let actual_range = client.item_times.find_packed_and_split(span.seq_range);
let actual_range = client.lv_for_seq.find_packed_and_split(span.seq_range);

assert_eq!(actual_range.1, expected_range);
}

if deep {
// Also check the other way around.
for (agent, client) in self.client_data.iter().enumerate() {
for range in client.item_times.iter() {
for range in client.lv_for_seq.iter() {
let actual = self.client_with_localtime.find_packed_and_split(range.1);
assert_eq!(actual.1.agent as usize, agent);
}
Expand Down
10 changes: 5 additions & 5 deletions src/causalgraph/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ mod serde_encoding {
impl AgentAssignment {
pub fn summarize_versions(&self) -> VersionSummary {
VersionSummary(self.client_data.iter().filter_map(|c| {
if c.item_times.is_empty() { None } else {
if c.lv_for_seq.is_empty() { None } else {
Some(VSEntry {
name: c.name.clone(),
seq_ranges: c.item_times
seq_ranges: c.lv_for_seq
.iter()
.map(|e| e.range())
.merge_spans()
Expand All @@ -133,7 +133,7 @@ impl AgentAssignment {

pub fn summarize_versions_flat(&self) -> VersionSummaryFlat {
VersionSummaryFlat(self.client_data.iter().filter_map(|c| {
if c.item_times.is_empty() { None }
if c.lv_for_seq.is_empty() { None }
else { Some((c.name.clone(), c.get_next_seq())) }
}).collect())
}
Expand All @@ -146,7 +146,7 @@ impl AgentAssignment {
let mut next_seq = 0;

if let Some(agent_id) = agent_id {
let entries = &self.client_data[agent_id as usize].item_times;
let entries = &self.client_data[agent_id as usize].lv_for_seq;

for e in entries.iter() {
let entry_start = e.0;
Expand Down Expand Up @@ -182,7 +182,7 @@ impl AgentAssignment {
for seq_range in seq_ranges {
// entries.iter_range skips missing entries, so we need to manually yield those.
let mut expect_next_seq = seq_range.start;
for entry in client_data.item_times.iter_range(*seq_range) {
for entry in client_data.lv_for_seq.iter_range(*seq_range) {
let seq_range = entry.range();

if seq_range.start > expect_next_seq {
Expand Down
2 changes: 1 addition & 1 deletion src/encoding/cg_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub(crate) fn read_cg_entry_into_cg(reader: &mut BufParser, persist: bool, cg: &
// We already know the timespan for merged_span - so I could use that and just query the
// rest. But eh. This is smaller and should be just as performant.
let client_data = &cg.agent_assignment.client_data[span.agent as usize];
for KVPair(_, time) in client_data.item_times.iter_range(span.seq_range) {
for KVPair(_, time) in client_data.lv_for_seq.iter_range(span.seq_range) {
read_map.txn_map.push(KVPair(next_file_time, time));
next_file_time += time.len();
}
Expand Down
2 changes: 1 addition & 1 deletion src/list/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ListOpLog {

#[allow(unused)]
pub(crate) fn check_all_changes_rle_merged(&self) {
assert_eq!(self.cg.agent_assignment.client_data[0].item_times.num_entries(), 1);
assert_eq!(self.cg.agent_assignment.client_data[0].lv_for_seq.num_entries(), 1);
// .. And operation log.
assert_eq!(self.cg.graph.entries.num_entries(), 1);
}
Expand Down
4 changes: 2 additions & 2 deletions src/list/encoding/decode_oplog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ impl ListOpLog {
};

let client_data = &mut self.cg.agent_assignment.client_data[removed.agent as usize];
client_data.item_times.remove_ctx(removed.seq_range, &());
client_data.lv_for_seq.remove_ctx(removed.seq_range, &());
}
}

Expand Down Expand Up @@ -790,7 +790,7 @@ impl ListOpLog {
while !crdt_span.seq_range.is_empty() {
// dbg!(&crdt_span);
let client = &self.cg.agent_assignment.client_data[crdt_span.agent as usize];
let (span, offset) = client.item_times.find_sparse(crdt_span.seq_range.start);
let (span, offset) = client.lv_for_seq.find_sparse(crdt_span.seq_range.start);
// dbg!((crdt_span.seq_range, span, offset));
let (span_end, overlap_start) = match span {
// Skip the entry.
Expand Down
4 changes: 2 additions & 2 deletions src/list/oplog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl ListOpLog {
// } else {
// client_data.item_times.insert(KVPair(seq_range.start, timespan));
// }
client_data.item_times.insert(KVPair(seq_range.start, timespan));
client_data.lv_for_seq.insert(KVPair(seq_range.start, timespan));

self.cg.agent_assignment.client_with_localtime.push(KVPair(start, span));
}
Expand All @@ -139,7 +139,7 @@ impl ListOpLog {
let client_data = &mut self.cg.agent_assignment.client_data[agent as usize];

let next_seq = client_data.get_next_seq();
client_data.item_times.push(KVPair(next_seq, span));
client_data.lv_for_seq.push(KVPair(next_seq, span));

self.cg.agent_assignment.client_with_localtime.push(KVPair(span.start, AgentSpan {
agent,
Expand Down
2 changes: 1 addition & 1 deletion src/list/oplog_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl CausalGraph {

// Find out how many items we can eat
let (r, offset) = self.agent_assignment.client_data[self_agent as usize]
.item_times.find_sparse(seq);
.lv_for_seq.find_sparse(seq);
if r.is_ok() {
// Overlap here. Discard from the queue.
break;
Expand Down

0 comments on commit bebdd75

Please sign in to comment.