refactor: Use ReplicationFactor type in more places

- Remove the replication_factor.replication_factor() in favor of
  usize::from(replication_factor) to make the conversion more explicit.

- Implement Display on ReplicationFactor so that it can be formatted
  without converting to usize

- Use ReplicationFactor in the constructor of LayoutVersion and add a
  method to get a ReplicationFactor from a LayoutVersion, despite
  LayoutVersion still storing it as usize internally.
This commit is contained in:
Yureka
2025-04-20 20:33:34 +02:00
parent e79b485aa8
commit c8e9c45889
4 changed files with 22 additions and 15 deletions
+6 -6
View File
@@ -46,11 +46,11 @@ impl LayoutManager {
let cluster_layout = match persist_cluster_layout.load() {
Ok(x) => {
if x.current().replication_factor != replication_factor.replication_factor() {
if x.current().replication_factor() != replication_factor {
return Err(Error::Message(format!(
"Previous cluster layout has replication factor {}, which is different than the one specified in the config file ({}). The previous cluster layout can be purged, if you know what you are doing, simply by deleting the `cluster_layout` file in your metadata directory.",
x.current().replication_factor,
replication_factor.replication_factor()
x.current().replication_factor(),
replication_factor,
)));
}
x
@@ -301,11 +301,11 @@ impl LayoutManager {
adv.update_trackers
);
if adv.current().replication_factor != self.replication_factor.replication_factor() {
if adv.current().replication_factor() != self.replication_factor {
let msg = format!(
"Received a cluster layout from another node with replication factor {}, which is different from what we have in our configuration ({}). Discarding the cluster layout we received.",
adv.current().replication_factor,
self.replication_factor.replication_factor()
adv.current().replication_factor(),
self.replication_factor,
);
error!("{}", msg);
return Err(Error::Message(msg));