MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / refresh_state

Method refresh_state

gateway/src/main_service.rs:1310–1343  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

1308 }
1309
1310 pub(crate) fn refresh_state(&mut self) -> Result<()> {
1311 // Get local WG handshakes and sync to KvStore
1312 let handshakes = self.latest_handshakes(None)?;
1313
1314 // Build a map from public_key to instance_id for lookup
1315 let pk_to_id: BTreeMap<&str, &str> = self
1316 .state
1317 .instances
1318 .iter()
1319 .map(|(id, info)| (info.public_key.as_str(), id.as_str()))
1320 .collect();
1321
1322 // Sync local handshake observations to KvStore
1323 for (pk, (ts, _)) in &handshakes {
1324 if let Some(&instance_id) = pk_to_id.get(pk.as_str()) {
1325 if let Err(err) = self.kv_store.sync_instance_handshake(instance_id, *ts) {
1326 debug!("failed to sync instance handshake: {err:?}");
1327 }
1328 }
1329 }
1330
1331 // Update this node's last_seen in KvStore
1332 let now = SystemTime::now()
1333 .duration_since(UNIX_EPOCH)
1334 .map(|d| d.as_secs())
1335 .unwrap_or(0);
1336 if let Err(err) = self
1337 .kv_store
1338 .sync_node_last_seen(self.config.sync.node_id, now)
1339 {
1340 debug!("failed to sync node last_seen: {err:?}");
1341 }
1342 Ok(())
1343 }
1344
1345 /// Sync connection count for an instance to KvStore
1346 pub(crate) fn sync_connections(&self, instance_id: &str, count: u64) {

Callers 2

statusMethod · 0.80
recycleMethod · 0.80

Calls 5

latest_handshakesMethod · 0.80
sync_node_last_seenMethod · 0.80
as_strMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected