diff --git a/src/main/java/org/qortal/api/resource/AdminResource.java b/src/main/java/org/qortal/api/resource/AdminResource.java index e3e2e2a8..52d7a9e7 100644 --- a/src/main/java/org/qortal/api/resource/AdminResource.java +++ b/src/main/java/org/qortal/api/resource/AdminResource.java @@ -40,7 +40,6 @@ import org.qortal.account.Account; import org.qortal.account.PrivateKeyAccount; import org.qortal.api.ApiError; import org.qortal.api.ApiErrors; -import org.qortal.api.ApiException; import org.qortal.api.ApiExceptionFactory; import org.qortal.api.Security; import org.qortal.api.model.ActivitySummary; @@ -437,8 +436,6 @@ public class AdminResource { throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e); } catch (NumberFormatException e) { throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_HEIGHT); - } catch (ApiException e) { - throw e; } } @@ -494,8 +491,6 @@ public class AdminResource { return syncResult.name(); } catch (IllegalArgumentException e) { throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA); - } catch (ApiException e) { - throw e; } catch (UnknownHostException e) { throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA); } catch (InterruptedException e) { @@ -503,4 +498,31 @@ public class AdminResource { } } + @DELETE + @Path("/repository") + @Operation( + summary = "Perform maintenance on repository.", + description = "Requires enough free space to rebuild repository. This will pause your node for a while." + ) + @ApiErrors({ApiError.REPOSITORY_ISSUE}) + public void performRepositoryMaintenance() { + Security.checkApiCallAllowed(request); + + try (final Repository repository = RepositoryManager.getRepository()) { + ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock(); + + blockchainLock.lockInterruptibly(); + + try { + repository.performPeriodicMaintenance(); + } finally { + blockchainLock.unlock(); + } + } catch (InterruptedException e) { + // No big deal + } catch (DataException e) { + throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e); + } + } + } diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java index 35ce94db..9cf2c07c 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java @@ -351,7 +351,10 @@ public class HSQLDBRepository implements Repository { public void performPeriodicMaintenance() throws DataException { // Defrag DB - takes a while! try (Statement stmt = this.connection.createStatement()) { + LOGGER.info("performing maintenance - this will take a while"); + stmt.execute("CHECKPOINT"); stmt.execute("CHECKPOINT DEFRAG"); + LOGGER.info("maintenance completed"); } catch (SQLException e) { throw new DataException("Unable to defrag repository"); }