dataroaring commented on code in PR #62061:
URL: https://github.com/apache/doris/pull/62061#discussion_r3031047433
##########
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:
Done. Adopted two-phase close: detach resources under writeLock, then close
outside the lock. Also fixed the misleading log messages.
--
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]