Commit a1f1e43
fix(directory-watcher): address race conditions and state consistency issues
This commit fixes several critical and moderate issues identified in code review:
**Critical Fixes:**
1. **Meta-path collision detection**: Add validation in NewDBsFromDirectoryConfig
to detect when multiple databases would share the same meta-path, which
would cause replication state corruption. Returns clear error message
identifying the conflicting databases.
2. **Store.AddDB documentation**: Improve comments explaining the double-check
locking pattern used to handle concurrent additions of the same database.
The pattern prevents duplicates while avoiding holding locks during slow
Open() operations.
**Moderate Fixes:**
3. **Directory removal state consistency**: Refactor removeDatabase and
removeDatabasesUnder to only delete from local map after successful
Store.RemoveDB. Prevents inconsistent state if removal fails.
4. **Context propagation**: Replace context.Background() with dm.ctx in
directory_watcher.go for proper cancellation during shutdown.
**Testing:**
- All unit tests pass
- Integration test failures are pre-existing on this branch, not introduced
by these changes (verified by testing before/after)
Fixes identified in PR #827 code review.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent 41563f4 commit a1f1e43
3 files changed
+34
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
284 | 283 | | |
285 | 284 | | |
286 | 285 | | |
287 | 286 | | |
288 | 287 | | |
289 | 288 | | |
290 | | - | |
| 289 | + | |
291 | 290 | | |
292 | 291 | | |
293 | 292 | | |
294 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
295 | 298 | | |
296 | 299 | | |
297 | 300 | | |
| |||
300 | 303 | | |
301 | 304 | | |
302 | 305 | | |
| 306 | + | |
303 | 307 | | |
304 | 308 | | |
305 | 309 | | |
306 | | - | |
| 310 | + | |
307 | 311 | | |
308 | 312 | | |
309 | 313 | | |
310 | 314 | | |
311 | | - | |
| 315 | + | |
| 316 | + | |
312 | 317 | | |
313 | 318 | | |
314 | 319 | | |
315 | | - | |
| 320 | + | |
316 | 321 | | |
| 322 | + | |
317 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
318 | 329 | | |
319 | 330 | | |
320 | 331 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
605 | 605 | | |
606 | 606 | | |
607 | 607 | | |
| 608 | + | |
| 609 | + | |
608 | 610 | | |
609 | 611 | | |
610 | 612 | | |
611 | 613 | | |
612 | 614 | | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
613 | 624 | | |
614 | 625 | | |
615 | 626 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
176 | 177 | | |
177 | 178 | | |
178 | 179 | | |
| 180 | + | |
| 181 | + | |
179 | 182 | | |
180 | 183 | | |
181 | 184 | | |
182 | 185 | | |
| 186 | + | |
| 187 | + | |
183 | 188 | | |
184 | 189 | | |
185 | 190 | | |
186 | 191 | | |
187 | 192 | | |
| 193 | + | |
| 194 | + | |
188 | 195 | | |
189 | 196 | | |
190 | 197 | | |
| |||
0 commit comments