Browse Source

Add API POST /repository/checkpoint call. Renamed GET/POST /admin/repository calls to /admin/repository/data

AT-sleep-until-message
catbref 4 years ago
parent
commit
253a994438
  1. 42
      src/main/java/org/qortal/api/resource/AdminResource.java
  2. 2
      src/main/java/org/qortal/repository/hsqldb/HSQLDBRepository.java

42
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(

2
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");
}
}

Loading…
Cancel
Save