Copilot commented on code in PR #62061:
URL: https://github.com/apache/doris/pull/62061#discussion_r3028449662
##########
fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java:
##########
@@ -481,32 +481,37 @@ public List<Long> getDatabaseNames() {
// Close the store and environment
public void close() {
- for (Database db : openedDatabases) {
- try {
- db.close();
- } catch (DatabaseException exception) {
- LOG.error("Error closing db {} will exit",
db.getDatabaseName(), exception);
+ lock.writeLock().lock();
+ try {
+ for (Database db : openedDatabases) {
+ try {
+ db.close();
+ } catch (DatabaseException exception) {
+ LOG.error("Error closing db {} will exit",
db.getDatabaseName(), exception);
Review Comment:
The message fragment “will exit” is misleading here because `close()` does
not exit the process (and the code continues closing other resources). Consider
updating the log text to reflect the actual behavior (e.g., “Error closing db
{}” / “Error closing epoch db {}”) to avoid confusion during incident triage.
##########
fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java:
##########
@@ -481,32 +481,37 @@ public List<Long> getDatabaseNames() {
// Close the store and environment
public void close() {
- for (Database db : openedDatabases) {
- try {
- db.close();
- } catch (DatabaseException exception) {
- LOG.error("Error closing db {} will exit",
db.getDatabaseName(), exception);
+ lock.writeLock().lock();
+ try {
+ for (Database db : openedDatabases) {
+ try {
+ db.close();
+ } catch (DatabaseException exception) {
+ LOG.error("Error closing db {} will exit",
db.getDatabaseName(), exception);
+ }
}
- }
- openedDatabases.clear();
+ openedDatabases.clear();
- if (epochDB != null) {
- try {
- epochDB.close();
- epochDB = null;
- } catch (DatabaseException exception) {
- LOG.error("Error closing db {} will exit",
epochDB.getDatabaseName(), exception);
+ if (epochDB != null) {
+ try {
+ epochDB.close();
+ epochDB = null;
+ } catch (DatabaseException exception) {
+ LOG.error("Error closing db {} will exit",
epochDB.getDatabaseName(), exception);
+ }
}
- }
- if (replicatedEnvironment != null) {
- try {
- // Finally, close the store and environment.
- replicatedEnvironment.close();
- replicatedEnvironment = null;
- } catch (DatabaseException exception) {
- LOG.error("Error closing replicatedEnvironment", exception);
+ if (replicatedEnvironment != null) {
+ try {
+ // Finally, close the store and environment.
+ replicatedEnvironment.close();
+ replicatedEnvironment = null;
+ } catch (DatabaseException exception) {
+ LOG.error("Error closing replicatedEnvironment",
exception);
+ }
}
+ } finally {
+ lock.writeLock().unlock();
}
Review Comment:
Holding the class write-lock while calling into external resource cleanup
(`db.close()`, `epochDB.close()`, `replicatedEnvironment.close()`) can block
unrelated threads for a long time and increases deadlock risk if those close
paths indirectly contend on the same lock or other shared locks. A safer
pattern is a two-phase close: under the write-lock, atomically “detach”
resources (copy/swap `openedDatabases` to a local list, set fields like
`epochDB`/`replicatedEnvironment` to null, optionally set a `closing/closed`
flag to reject new opens), then release the lock and perform the actual
`close()` calls outside the lock.
##########
fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java:
##########
@@ -481,32 +481,37 @@ public List<Long> getDatabaseNames() {
// Close the store and environment
public void close() {
- for (Database db : openedDatabases) {
- try {
- db.close();
- } catch (DatabaseException exception) {
- LOG.error("Error closing db {} will exit",
db.getDatabaseName(), exception);
+ lock.writeLock().lock();
+ try {
+ for (Database db : openedDatabases) {
+ try {
+ db.close();
+ } catch (DatabaseException exception) {
+ LOG.error("Error closing db {} will exit",
db.getDatabaseName(), exception);
+ }
}
- }
- openedDatabases.clear();
+ openedDatabases.clear();
- if (epochDB != null) {
- try {
- epochDB.close();
- epochDB = null;
- } catch (DatabaseException exception) {
- LOG.error("Error closing db {} will exit",
epochDB.getDatabaseName(), exception);
+ if (epochDB != null) {
+ try {
+ epochDB.close();
+ epochDB = null;
+ } catch (DatabaseException exception) {
+ LOG.error("Error closing db {} will exit",
epochDB.getDatabaseName(), exception);
Review Comment:
The message fragment “will exit” is misleading here because `close()` does
not exit the process (and the code continues closing other resources). Consider
updating the log text to reflect the actual behavior (e.g., “Error closing db
{}” / “Error closing epoch db {}”) to avoid confusion during incident triage.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]