Skip to content

Commit

Permalink
Adjust time advancement to be done by State
Browse files Browse the repository at this point in the history
I'm working now to get rotation logic introduced in State. The first
step is to move time advancement to a single place in State -- the
advance time function -- although reads and what not in File still
induce advances I think. All will be smoothed out eventually.

Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
  • Loading branch information
blt committed Oct 28, 2024
1 parent 23f5cf9 commit b72b315
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions lading/src/generator/file_gen/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,31 @@ impl State {
/// Will panic if passed `now` is less than recorded `now`. Time can only
/// advance.
pub fn advance_time(&mut self, now: Tick) {
// Okay so here's the idea.
//
// 1. I introduce a read-only File via boolean flag
// 2. A File has a "peer" Option<Inode> that allows for lookup of the next in line
// 3. The names are held here. We traverse the linked list of peers and
// then delete anything past max_rotations.
//
// The State holds all notion of when a File should rotate and also be
// deleted. The File has no say in that at all.

// nothing yet beyond updating the clock, rotations to come
assert!(now >= self.now);

for node in self.nodes.values_mut() {
match node {
Node::File { file, .. } => {
file.advance_time(now);
// TODO add rotation logic here
}
Node::Directory { .. } => {
// directories are immutable though time flows around them
}
}
}

self.now = now;
}

Expand All @@ -267,26 +290,23 @@ impl State {
pub fn getattr(&mut self, now: Tick, inode: Inode) -> Option<NodeAttributes> {
self.advance_time(now);

self.nodes.get_mut(&inode).map(|node| {
node.advance_time(now);
match node {
Node::File { file, .. } => NodeAttributes {
inode,
kind: NodeType::File,
size: file.bytes_written,
access_tick: file.access_tick,
modified_tick: file.modified_tick,
status_tick: file.status_tick,
},
Node::Directory { .. } => NodeAttributes {
inode,
kind: NodeType::Directory,
size: 0,
access_tick: self.now,
modified_tick: self.now,
status_tick: self.now,
},
}
self.nodes.get(&inode).map(|node| match node {
Node::File { file, .. } => NodeAttributes {
inode,
kind: NodeType::File,
size: file.bytes_written,
access_tick: file.access_tick,
modified_tick: file.modified_tick,
status_tick: file.status_tick,
},
Node::Directory { .. } => NodeAttributes {
inode,
kind: NodeType::Directory,
size: 0,
access_tick: self.now,
modified_tick: self.now,
status_tick: self.now,
},
})
}

Expand Down

0 comments on commit b72b315

Please sign in to comment.