Commit 33f8fac
committed
[fix](editlog) Fix BDBEnvironment.close() ConcurrentModificationException with two-phase close
BDBEnvironment.close() iterates openedDatabases without acquiring
lock.writeLock(), while openDatabase() concurrently modifies the same
ArrayList under the write lock. This causes ConcurrentModificationException
when a RollbackException triggers close() on the replayer thread while
HTTP/heartbeat/RPC handler threads call openDatabase() via getMaxJournalId().
Fix with two-phase close pattern:
- Phase 1 (under writeLock): detach all resources — copy openedDatabases
to a local list, clear the original, and null out epochDB and
replicatedEnvironment fields. This atomically makes them invisible to
concurrent openDatabase() callers.
- Phase 2 (outside lock): perform the actual db.close() and env.close()
calls without holding the lock, avoiding blocking unrelated threads
during potentially slow close operations.
Also fix misleading "will exit" in log messages — close() does not exit.1 parent 9ecfd40 commit 33f8fac
1 file changed
Lines changed: 33 additions & 12 deletions
Lines changed: 33 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
482 | | - | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
483 | 485 | | |
484 | | - | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
485 | 510 | | |
486 | 511 | | |
487 | 512 | | |
488 | | - | |
| 513 | + | |
489 | 514 | | |
490 | 515 | | |
491 | | - | |
492 | 516 | | |
493 | | - | |
| 517 | + | |
494 | 518 | | |
495 | | - | |
496 | | - | |
| 519 | + | |
497 | 520 | | |
498 | | - | |
| 521 | + | |
499 | 522 | | |
500 | 523 | | |
501 | 524 | | |
502 | | - | |
| 525 | + | |
503 | 526 | | |
504 | | - | |
505 | | - | |
506 | | - | |
| 527 | + | |
507 | 528 | | |
508 | 529 | | |
509 | 530 | | |
| |||
0 commit comments