forked from Qortal/qortal
Add API call DELETE /admin/repository which actually performs repository maintenance (takes several minutes)
This commit is contained in:
parent
a6f42df9d6
commit
81a5b154c2
@ -40,7 +40,6 @@ import org.qortal.account.Account;
|
|||||||
import org.qortal.account.PrivateKeyAccount;
|
import org.qortal.account.PrivateKeyAccount;
|
||||||
import org.qortal.api.ApiError;
|
import org.qortal.api.ApiError;
|
||||||
import org.qortal.api.ApiErrors;
|
import org.qortal.api.ApiErrors;
|
||||||
import org.qortal.api.ApiException;
|
|
||||||
import org.qortal.api.ApiExceptionFactory;
|
import org.qortal.api.ApiExceptionFactory;
|
||||||
import org.qortal.api.Security;
|
import org.qortal.api.Security;
|
||||||
import org.qortal.api.model.ActivitySummary;
|
import org.qortal.api.model.ActivitySummary;
|
||||||
@ -437,8 +436,6 @@ public class AdminResource {
|
|||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_HEIGHT);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_HEIGHT);
|
||||||
} catch (ApiException e) {
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,8 +491,6 @@ public class AdminResource {
|
|||||||
return syncResult.name();
|
return syncResult.name();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
||||||
} catch (ApiException e) {
|
|
||||||
throw e;
|
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
||||||
} catch (InterruptedException e) {
|
} 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,10 @@ public class HSQLDBRepository implements Repository {
|
|||||||
public void performPeriodicMaintenance() throws DataException {
|
public void performPeriodicMaintenance() throws DataException {
|
||||||
// Defrag DB - takes a while!
|
// Defrag DB - takes a while!
|
||||||
try (Statement stmt = this.connection.createStatement()) {
|
try (Statement stmt = this.connection.createStatement()) {
|
||||||
|
LOGGER.info("performing maintenance - this will take a while");
|
||||||
|
stmt.execute("CHECKPOINT");
|
||||||
stmt.execute("CHECKPOINT DEFRAG");
|
stmt.execute("CHECKPOINT DEFRAG");
|
||||||
|
LOGGER.info("maintenance completed");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DataException("Unable to defrag repository");
|
throw new DataException("Unable to defrag repository");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user