Apply a committed entry. Idempotent by `applied_index`: entries at or below the current watermark are ignored.
(&mut self, index: u64, entry: &MetadataEntry)
| 56 | /// Apply a committed entry. Idempotent by `applied_index`: |
| 57 | /// entries at or below the current watermark are ignored. |
| 58 | pub fn apply(&mut self, index: u64, entry: &MetadataEntry) { |
| 59 | if index != 0 && index <= self.applied_index { |
| 60 | debug!( |
| 61 | index, |
| 62 | watermark = self.applied_index, |
| 63 | "metadata cache: skipping already-applied entry" |
| 64 | ); |
| 65 | return; |
| 66 | } |
| 67 | self.applied_index = index; |
| 68 | |
| 69 | match entry { |
| 70 | MetadataEntry::CatalogDdl { payload: _ } |
| 71 | | MetadataEntry::CatalogDdlAudited { payload: _, .. } => { |
| 72 | // Opaque to the cluster crate. The host-side applier |
| 73 | // decodes the payload and writes through to |
| 74 | // `SystemCatalog`. We just count it — both DDL |
| 75 | // shapes contribute to `catalog_entries_applied`. |
| 76 | self.catalog_entries_applied += 1; |
| 77 | } |
| 78 | MetadataEntry::TopologyChange(change) => self.topology_log.push(change.clone()), |
| 79 | MetadataEntry::RoutingChange(change) => self.routing_log.push(change.clone()), |
| 80 | |
| 81 | MetadataEntry::ClusterVersionBump { from, to } => { |
| 82 | if *from != self.cluster_version && self.cluster_version != 0 { |
| 83 | warn!( |
| 84 | expected = self.cluster_version, |
| 85 | got = *from, |
| 86 | "cluster version bump mismatch" |
| 87 | ); |
| 88 | } |
| 89 | self.cluster_version = *to; |
| 90 | } |
| 91 | |
| 92 | MetadataEntry::DescriptorLeaseGrant(lease) => { |
| 93 | if lease.expires_at > self.last_applied_hlc { |
| 94 | self.last_applied_hlc = lease.expires_at; |
| 95 | } |
| 96 | self.leases |
| 97 | .insert((lease.descriptor_id.clone(), lease.node_id), lease.clone()); |
| 98 | } |
| 99 | MetadataEntry::DescriptorLeaseRelease { |
| 100 | node_id, |
| 101 | descriptor_ids, |
| 102 | } => { |
| 103 | for id in descriptor_ids { |
| 104 | self.leases.remove(&(id.clone(), *node_id)); |
| 105 | } |
| 106 | } |
| 107 | // Drain state is host-side (lives in |
| 108 | // `nodedb::control::lease::DescriptorDrainTracker`); |
| 109 | // the cluster-side cache only tracks lease state |
| 110 | // directly. These no-op arms keep the exhaustive |
| 111 | // match coverage so adding new variants is a |
| 112 | // compile-time error here too. |
| 113 | MetadataEntry::DescriptorDrainStart { expires_at, .. } => { |
| 114 | if *expires_at > self.last_applied_hlc { |
| 115 | self.last_applied_hlc = *expires_at; |