diff --git a/src/main/java/org/qortal/api/resource/AdminResource.java b/src/main/java/org/qortal/api/resource/AdminResource.java index 88b15e60..f24389bf 100644 --- a/src/main/java/org/qortal/api/resource/AdminResource.java +++ b/src/main/java/org/qortal/api/resource/AdminResource.java @@ -531,7 +531,7 @@ public class AdminResource { } @GET - @Path("/repository") + @Path("/repository/data") @Operation( summary = "Export sensitive/node-local data from repository.", description = "Exports data to .script files on local machine" @@ -561,7 +561,7 @@ public class AdminResource { } @POST - @Path("/repository") + @Path("/repository/data") @Operation( summary = "Import data into repository.", description = "Imports data from file on local machine. Filename is forced to 'import.script' if apiKey is not set.", @@ -611,6 +611,44 @@ public class AdminResource { } } + @POST + @Path("/repository/checkpoint") + @Operation( + summary = "Checkpoint data in repository.", + description = "Forces repository to checkpoint uncommitted writes.", + responses = { + @ApiResponse( + description = "\"true\"", + content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(type = "string")) + ) + } + ) + @ApiErrors({ApiError.REPOSITORY_ISSUE}) + @SecurityRequirement(name = "apiKey") + public String checkpointRepository() { + Security.checkApiCallAllowed(request); + + try (final Repository repository = RepositoryManager.getRepository()) { + ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock(); + + blockchainLock.lockInterruptibly(); + + try { + repository.checkpoint(true); + repository.saveChanges(); + + return "true"; + } finally { + blockchainLock.unlock(); + } + } catch (InterruptedException e) { + // We couldn't lock blockchain to perform checkpoint + return "false"; + } catch (DataException e) { + throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e); + } + } + @DELETE @Path("/repository") @Operation( diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java index d3815dcc..7c694b53 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java @@ -382,7 +382,7 @@ public class HSQLDBRepository implements Repository { try (Statement stmt = this.connection.createStatement()) { stmt.execute(quick ? "CHECKPOINT" : "CHECKPOINT DEFRAG"); } catch (SQLException e) { - throw new DataException("Unable to perform repositor checkpoint"); + throw new DataException("Unable to perform repository checkpoint"); } }