(conn protocol.Connection)
| 1339 | } |
| 1340 | |
| 1341 | func (m *model) ensureIndexHandler(conn protocol.Connection) *indexHandlerRegistry { |
| 1342 | deviceID := conn.DeviceID() |
| 1343 | connID := conn.ConnectionID() |
| 1344 | |
| 1345 | m.mut.Lock() |
| 1346 | defer m.mut.Unlock() |
| 1347 | |
| 1348 | indexHandlerRegistry, ok := m.indexHandlers.Get(deviceID) |
| 1349 | if ok && indexHandlerRegistry.conn.ConnectionID() == connID { |
| 1350 | // This is an existing and proper index handler for this connection. |
| 1351 | return indexHandlerRegistry |
| 1352 | } |
| 1353 | |
| 1354 | if ok { |
| 1355 | // A handler exists, but it's for another connection than the one we |
| 1356 | // now got a ClusterConfig on. This should be unusual as it means |
| 1357 | // the other side has decided to start using a new primary |
| 1358 | // connection but we haven't seen it close yet. Ideally it will |
| 1359 | // close shortly by itself... |
| 1360 | slog.Warn("Abandoning old index handler in favour of new connection", deviceID.LogAttr(), slog.String("old", indexHandlerRegistry.conn.ConnectionID()), slog.String("new", connID)) |
| 1361 | m.indexHandlers.RemoveAndWait(deviceID, 0) |
| 1362 | } |
| 1363 | |
| 1364 | // Create a new index handler for this device. |
| 1365 | indexHandlerRegistry = newIndexHandlerRegistry(conn, m.sdb, m.deviceDownloads[deviceID], m.evLogger) |
| 1366 | for id, fcfg := range m.folderCfgs { |
| 1367 | l.Debugln("Registering folder", id, "for", deviceID.Short()) |
| 1368 | runner, _ := m.folderRunners.Get(id) |
| 1369 | indexHandlerRegistry.RegisterFolderState(fcfg, runner) |
| 1370 | } |
| 1371 | m.indexHandlers.Add(deviceID, indexHandlerRegistry) |
| 1372 | |
| 1373 | return indexHandlerRegistry |
| 1374 | } |
| 1375 | |
| 1376 | func (m *model) getIndexHandlerRLocked(conn protocol.Connection) (*indexHandlerRegistry, bool) { |
| 1377 | // Reads from index handlers, which requires the mutex to be read locked |
no test coverage detected