Skip to content

Commit 93ed92a

Browse files
authored
fix: update backup database functionality and improve logging (#2200)
1 parent 540ecc9 commit 93ed92a

9 files changed

Lines changed: 36 additions & 10 deletions

File tree

e2e/src/test/java/com/arcadedb/e2e/JdbcQueriesTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,20 @@ void testSelectSchemaTypes() throws SQLException, ClassNotFoundException {
269269
@Test
270270
void testBackupDatabase() throws SQLException {
271271
try (final Statement stmt = conn.createStatement()) {
272-
assertThat(stmt.execute("{sql}BACKUP DATABASE;")).isTrue();
272+
ResultSet backupDatabase = stmt.executeQuery("{sqlscript}BACKUP DATABASE");
273+
while (backupDatabase.next()) {
274+
assertThat(backupDatabase.getString("result")).isEqualTo("OK");
275+
assertThat(backupDatabase.getString("backupFile")).startsWith("beer-backup-");
276+
}
273277
}
274278

275279
try (final Statement stmt = conn.createStatement()) {
276-
assertThat(stmt.execute("{sqlscript}BACKUP DATABASE;")).isTrue();
280+
ResultSet backupDatabase = stmt.executeQuery("{sql}BACKUP DATABASE");
281+
while (backupDatabase.next()) {
282+
assertThat(backupDatabase.getString("result")).isEqualTo("OK");
283+
assertThat(backupDatabase.getString("backupFile")).startsWith("beer-backup-");
284+
}
285+
277286
}
278287

279288
}

engine/src/main/java/com/arcadedb/query/sql/executor/CountFromTypeStep.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public class CountFromTypeStep extends AbstractExecutionStep {
4040
* @param targetClass An identifier containing the name of the class to count
4141
* @param alias the name of the property returned in the result-set
4242
* @param context the query context
43-
* @param profilingEnabled true to enable the profiling of the execution (for SQL PROFILE)
4443
*/
4544
public CountFromTypeStep(final String targetClass, final String alias, final CommandContext context) {
4645
super(context);

engine/src/main/java/com/arcadedb/query/sql/parser/BackupDatabaseStatement.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public ResultSet executeSimple(final CommandContext context) {
6060

6161
// ASSURE THE DIRECTORY CANNOT BE CHANGED
6262
String backupDirectory = context.getConfiguration().getValueAsString(GlobalConfiguration.SERVER_BACKUP_DIRECTORY);
63+
LogManager.instance().log(this, Level.INFO,
64+
String.format("Backing up database '%s' to directory '%s'", context.getDatabase().getName(), backupDirectory));
6365
if (!backupDirectory.endsWith(File.separator))
6466
backupDirectory += File.separator;
6567

engine/src/main/java/com/arcadedb/query/sql/parser/SimpleExecStatement.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public ResultSet execute(final Database db, final Object[] args, final CommandCo
4848
}
4949
context.setDatabase(db);
5050
context.setInputParameters(args);
51+
52+
if (parentContext != null)
53+
context.setConfiguration(parentContext.getConfiguration());
54+
5155
final SingleOpExecutionPlan executionPlan = (SingleOpExecutionPlan) createExecutionPlan(context);
5256
return executionPlan.executeInternal();
5357
}

engine/src/main/java/com/arcadedb/utility/VariableParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import com.arcadedb.log.LogManager;
2222

23-
import java.util.logging.*;
23+
import java.util.logging.Level;
2424

2525
/**
2626
* Resolve entity class and descriptors using the paths configured.

integration/src/main/java/com/arcadedb/integration/backup/format/FullBackupFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void backupDatabase() throws Exception {
6565
throw new BackupException("The backup file '%s' cannot be created".formatted(backupFile));
6666
}
6767

68-
if (database.isTransactionActive())
68+
if (database.isTransactionActive() && database.getTransaction().hasChanges())
6969
throw new BackupException("Transaction in progress found");
7070

7171
logger.logLine(0, "Executing full backup of database to '%s'...", backupFile);

postgresw/src/main/java/com/arcadedb/postgres/PostgresNetworkExecutor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.arcadedb.network.binary.ChannelBinaryServer;
3535
import com.arcadedb.query.sql.SQLQueryEngine;
3636
import com.arcadedb.query.sql.executor.BasicCommandContext;
37+
import com.arcadedb.query.sql.executor.CommandContext;
3738
import com.arcadedb.query.sql.executor.IteratorResultSet;
3839
import com.arcadedb.query.sql.executor.Result;
3940
import com.arcadedb.query.sql.executor.ResultInternal;
@@ -318,6 +319,7 @@ private void executeCommand() {
318319
else {
319320
if (!portal.executed) {
320321
final Object[] parameters = portal.parameterValues != null ? portal.parameterValues.toArray() : new Object[0];
322+
321323
final ResultSet resultSet = portal.sqlStatement.execute(database, parameters, createCommandContext());
322324
portal.executed = true;
323325
if (portal.isExpectingResult) {
@@ -345,8 +347,8 @@ private void executeCommand() {
345347
}
346348
}
347349

348-
private BasicCommandContext createCommandContext() {
349-
BasicCommandContext commandContext = new BasicCommandContext();
350+
private CommandContext createCommandContext() {
351+
CommandContext commandContext = new BasicCommandContext();
350352
commandContext.setConfiguration(server.getConfiguration());
351353
return commandContext;
352354
}
@@ -836,7 +838,6 @@ private void parseCommand() {
836838
case "sql":
837839
final SQLQueryEngine sqlEngine = (SQLQueryEngine) database.getQueryEngine("sql");
838840
portal.sqlStatement = sqlEngine.parse(query.query, (DatabaseInternal) database);
839-
840841
if (portal.query.equalsIgnoreCase("BEGIN") || portal.query.equalsIgnoreCase("BEGIN TRANSACTION")) {
841842
explicitTransactionStarted = true;
842843
setEmptyResultSet(portal);

postgresw/src/test/java/com/arcadedb/postgres/PostgresWJdbcTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,18 @@ public void endTest() {
6868
void testBackupDatabase() throws Exception {
6969
try (final Connection conn = getConnection()) {
7070
try (final Statement st = conn.createStatement()) {
71-
st.execute("BACKUP DATABASE");
71+
ResultSet backupDatabase = st.executeQuery("{sql}BACKUP DATABASE");
72+
while (backupDatabase.next()) {
73+
assertThat(backupDatabase.getString("result")).isEqualTo("OK");
74+
assertThat(backupDatabase.getString("backupFile")).startsWith("postgresdb-backup-");
75+
}
76+
}
77+
try (final Statement st = conn.createStatement()) {
78+
ResultSet backupDatabase = st.executeQuery("{sqlscript}BACKUP DATABASE");
79+
while (backupDatabase.next()) {
80+
assertThat(backupDatabase.getString("result")).isEqualTo("OK");
81+
assertThat(backupDatabase.getString("backupFile")).startsWith("postgresdb-backup-");
82+
}
7283
}
7384
}
7485
}

server/src/main/java/com/arcadedb/server/ArcadeDBServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public synchronized void start() {
224224

225225
private void createDirectories() {
226226

227-
LogManager.instance().log(this, Level.INFO, "Server root path: %s", serverRootPath);
227+
LogManager.instance().log(this, Level.INFO, "Server root path: %s", configuration.getValueAsString(GlobalConfiguration.SERVER_ROOT_PATH));
228228
LogManager.instance().log(this, Level.INFO, "Databases directory: %s", configuration.getValueAsString(GlobalConfiguration.SERVER_DATABASE_DIRECTORY));
229229
final File databaseDir = new File(configuration.getValueAsString(GlobalConfiguration.SERVER_DATABASE_DIRECTORY));
230230
if (!databaseDir.exists()) {

0 commit comments

Comments
 (0)