Skip to content

Commit

Permalink
fix: fixed drop database from server
Browse files Browse the repository at this point in the history
Fixed issue #1207. Still waiting more info to be 100% sure this is fixed.
  • Loading branch information
lvca committed Aug 15, 2023
1 parent dc873a2 commit d2b0be9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
27 changes: 14 additions & 13 deletions server/src/main/java/com/arcadedb/server/ArcadeDBServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ public ServerMetrics getServerMetrics() {
return serverMetrics;
}

public Database getDatabase(final String databaseName) {
public ServerDatabase getDatabase(final String databaseName) {
return getDatabase(databaseName, false, true);
}

public Database getOrCreateDatabase(final String databaseName) {
public ServerDatabase getOrCreateDatabase(final String databaseName) {
return getDatabase(databaseName, true, true);
}

Expand Down Expand Up @@ -410,11 +410,11 @@ public String toString() {
return getServerName();
}

public Database getDatabase(final String databaseName, final boolean createIfNotExists, final boolean allowLoad) {
public ServerDatabase getDatabase(final String databaseName, final boolean createIfNotExists, final boolean allowLoad) {
if (databaseName == null || databaseName.trim().isEmpty())
throw new IllegalArgumentException("Invalid database name " + databaseName);

DatabaseInternal db;
ServerDatabase db;
synchronized (databases) {
db = databases.get(databaseName);

Expand All @@ -432,34 +432,35 @@ public Database getDatabase(final String databaseName, final boolean createIfNot
if (defaultDbMode == null)
defaultDbMode = READ_WRITE;

DatabaseInternal embDatabase;
if (createIfNotExists)
db = (DatabaseInternal) (factory.exists() ? factory.open(defaultDbMode) : factory.create());
embDatabase = (DatabaseInternal) (factory.exists() ? factory.open(defaultDbMode) : factory.create());
else {
final Collection<Database> activeDatabases = DatabaseFactory.getActiveDatabaseInstances();
if (!activeDatabases.isEmpty()) {
db = null;
embDatabase = null;
for (Database existentDatabase : activeDatabases) {
if (existentDatabase.getDatabasePath().equals(path)) {
// REUSE THE OPEN DATABASE. THIS TYPICALLY HAPPENS WHEN A SERVER PLUGIN OPENS THE DATABASE AT STARTUP
db = (DatabaseInternal) existentDatabase;
embDatabase = (DatabaseInternal) existentDatabase;
break;
}
}

if (db == null)
if (embDatabase == null)
// OPEN A NEW DATABASE. THIS IS MOSTLY FOR TESTS WHERE MULTIPLE SERVERS SHARE THE SAME JVM
db = (DatabaseInternal) factory.open(defaultDbMode);
embDatabase = (DatabaseInternal) factory.open(defaultDbMode);

} else
db = (DatabaseInternal) factory.open(defaultDbMode);
embDatabase = (DatabaseInternal) factory.open(defaultDbMode);
}

if (configuration.getValueAsBoolean(GlobalConfiguration.HA_ENABLED))
db = new ReplicatedDatabase(this, (EmbeddedDatabase) db);
embDatabase = new ReplicatedDatabase(this, (EmbeddedDatabase) embDatabase);

db = new ServerDatabase(db);
db = new ServerDatabase(embDatabase);

databases.put(databaseName, (ServerDatabase) db);
databases.put(databaseName, db);
}
}
return db;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ private void dropDatabase(final String command) {
if (databaseName.isEmpty())
throw new IllegalArgumentException("Database name empty");

final Database database = httpServer.getServer().getDatabase(databaseName);
final ServerDatabase database = httpServer.getServer().getDatabase(databaseName);

httpServer.getServer().getServerMetrics().meter("http.drop-database").hit();

((DatabaseInternal) database).getEmbedded().drop();
database.getEmbedded().drop();
httpServer.getServer().removeDatabase(database.getName());
}

Expand All @@ -237,8 +237,8 @@ private void closeDatabase(final String command) {
if (databaseName.isEmpty())
throw new IllegalArgumentException("Database name empty");

final Database database = httpServer.getServer().getDatabase(databaseName);
((DatabaseInternal) database).getEmbedded().close();
final ServerDatabase database = httpServer.getServer().getDatabase(databaseName);
database.getEmbedded().close();

httpServer.getServer().getServerMetrics().meter("http.close-database").hit();
httpServer.getServer().removeDatabase(database.getName());
Expand All @@ -250,7 +250,6 @@ private void openDatabase(final String command) {
throw new IllegalArgumentException("Database name empty");

httpServer.getServer().getDatabase(databaseName);

httpServer.getServer().getServerMetrics().meter("http.open-database").hit();
}

Expand Down

0 comments on commit d2b0be9

Please sign in to comment.