Added POST /arbitrary/resources/cache/rebuild endpoint to allow a rebuild of the cache.

This commit is contained in:
CalDescent 2023-05-07 11:43:48 +01:00
parent eb7a29dd2e
commit 200b0f3412
3 changed files with 33 additions and 3 deletions

View File

@ -1119,6 +1119,36 @@ public class ArbitraryResource {
}
@POST
@Path("/resources/cache/rebuild")
@Operation(
summary = "Rebuild arbitrary resources cache from transactions",
responses = {
@ApiResponse(
description = "true on success",
content = @Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(
type = "boolean"
)
)
)
}
)
@SecurityRequirement(name = "apiKey")
public String rebuildCache(@HeaderParam(Security.API_KEY_HEADER) String apiKey) {
Security.checkApiCallAllowed(request);
try (final Repository repository = RepositoryManager.getRepository()) {
RepositoryManager.buildArbitraryResourcesCache(repository, true);
return "true";
} catch (DataException e) {
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.REPOSITORY_ISSUE, e.getMessage());
}
}
// Shared methods
private String preview(String directoryPath, Service service) {

View File

@ -403,7 +403,7 @@ public class Controller extends Thread {
RepositoryManager.setRequestedCheckpoint(Boolean.TRUE);
try (final Repository repository = RepositoryManager.getRepository()) {
RepositoryManager.buildInitialArbitraryResourcesCache(repository);
RepositoryManager.buildArbitraryResourcesCache(repository, false);
}
}
catch (DataException e) {

View File

@ -64,7 +64,7 @@ public abstract class RepositoryManager {
}
}
public static boolean buildInitialArbitraryResourcesCache(Repository repository) throws DataException {
public static boolean buildArbitraryResourcesCache(Repository repository, boolean forceRebuild) throws DataException {
if (Settings.getInstance().isLite()) {
// Lite nodes have no blockchain
return false;
@ -73,7 +73,7 @@ public abstract class RepositoryManager {
try {
// Check if QDNResources table is empty
List<ArbitraryResourceData> resources = repository.getArbitraryRepository().getArbitraryResources(10, 0, false);
if (!resources.isEmpty()) {
if (!resources.isEmpty() && !forceRebuild) {
// Resources exist in the cache, so assume complete.
// We avoid checkpointing and prevent the node from starting up in the case of a rebuild failure, so
// we shouldn't ever be left in a partially rebuilt state.