Skip to content

Commit

Permalink
Remove useless zero entry when bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Feb 8, 2024
1 parent 4c66766 commit 80eb97c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions raftify/src/storage/heed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,6 @@ impl HeedStorageCore {
config: config.clone(),
};

let mut writer = storage.env.write_txn()?;
storage.append(&mut writer, &[Entry::default()])?;
writer.commit()?;

Ok(storage)
}

Expand Down Expand Up @@ -487,12 +483,14 @@ impl HeedStorageCore {
}

fn first_index(&self, reader: &heed::RoTxn) -> Result<u64> {
let first_entry = self
.entries_db
.first(reader)?
.expect("There should always be at least one entry in the db");

Ok(first_entry.0.parse::<u64>().unwrap() + 1)
match self.entries_db.first(reader)? {
Some((index, _first_entry)) => Ok(index.parse::<u64>().unwrap()),
None => {
// TODO: Pass proper arguments after handling snapshot's `request_index` and `to`
let snapshot = self.snapshot(reader, 0, 0)?;
Ok(snapshot.get_metadata().get_index() + 1)
}
}
}

fn entry(&self, reader: &heed::RoTxn, index: u64) -> Result<Option<Entry>> {
Expand Down

0 comments on commit 80eb97c

Please sign in to comment.