Purge (micro)schema versions#1753
Conversation
| @@ -1,140 +0,0 @@ | |||
| package com.gentics.mesh.core.project.maintenance; | |||
There was a problem hiding this comment.
Completely unused. The correct implementation of ProjectVersionPurgeHandler is loaded elsewhere.
| // truncate the error detail message to the max length for the error detail property | ||
| setErrorDetail(truncateStackTrace(stackTrace)); | ||
| setErrorMessage(e.getMessage()); | ||
| setErrorMessage(StringUtils.substring(e.getMessage(), 0, 255)); |
| } | ||
| if (version.getPreviousVersion() != null) { | ||
| version.getPreviousVersion().setNextVersion(null); | ||
| version.getPreviousVersion().setNextVersion(version.getNextVersion()); |
There was a problem hiding this comment.
Bug in version removal. Worth porting to hotfix.
| if (status != null) { | ||
| boolean allMatching = true; | ||
| for (JobResponse info : response.getData()) { | ||
| if (before.getData().stream().anyMatch(j -> Objects.equal(j.getUuid(), info.getUuid()))) { |
There was a problem hiding this comment.
We count only new jobs.
|
|
||
| @Parameters(name = "{index}: {0}") | ||
| public static Collection<Object[]> parameters() { | ||
| return List.of(new Object[] { 0 }, new Object[] { 1 }, new Object[] { 2 }, new Object[] { 5 }, new Object[] { 8 }); |
There was a problem hiding this comment.
Random meaningful numbers, including 1 (nothing to clean) and 0 (no changes).
| } | ||
|
|
||
| @Test | ||
| @Category({FailingTests.class}) |
There was a problem hiding this comment.
Not anymore failing.
Updated the changelog entry to specify that the purge process saves storage resources.
| * @param version | ||
| * @return | ||
| */ | ||
| Stream<? extends HibNodeFieldContainer> getFieldsContainers(HibSchemaVersion version); |
There was a problem hiding this comment.
Reading all contents for a schema version is extremely inefficient. Also this method is apparently not used anywhere, so better remove it.
| * @param version | ||
| * @return | ||
| */ | ||
| Stream<? extends HibMicronode> getFieldsContainers(HibMicroschemaVersion version); |
There was a problem hiding this comment.
Same comment as above. This method is used from PersistingMicroschemaDao.delete(HibMicroschema), but only to check, whether there is still a micronode using a specific version (before deleting it). There are better methods to check this.
| .map(version -> version.getUuid()) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| containerDao.findAll().stream() |
There was a problem hiding this comment.
This seems to be inefficient and to produce long lasting db locks.
I tested with a database containing a schema with 22.000 versions. The job was running for several minutes until I gave up (there is no visible progress information). During that time, some requests (like getting the schemas for a specific branch) were hanging.
| crudHandler.handleDelete(ac, uuid); | ||
| }, isOrderedBlockingHandlers()); | ||
|
|
||
| InternalEndpointRoute purgeVersionsEndpoint = createRoute(); |
There was a problem hiding this comment.
Using the endpoint DELETE /api/v2/schemas for purging unused schema versions is counterintuitive (same for micoschemas).
…terized requests.
Updated the purge process for schemas and microschemas to use new REST API endpoints, allowing for parameterization by schema name/UUID filters.
| @@ -0,0 +1,2 @@ | |||
| Core: Now it is possible to purge empty (micro)schema versions automatically, via new background jobs. This will save storage and runtime resources of the database. | |||
| The purge process is triggered via REST API `POST /utilities/purge/schemas/versions` and `POST /utilities/purge/microschemas/versions` respectively, and can be parameterized by schema name/UUID filters. | |||
There was a problem hiding this comment.
The calls have to be moved to /utilities because of POST /schemas/{uuid} taking over the /schemas/purge calls
| endpoint.exampleRequest(microschemaExamples.getGeolocationMicroschemaCreateRequest()); | ||
| endpoint.exampleResponse(OK, utilityExamples.createValidationResponse(), "The validation report"); | ||
| endpoint.blockingHandler(rc -> { | ||
| private void addValidationHandler() { |
| /** | ||
| * Set the job start query. | ||
| */ | ||
| void setQuery(String query); |
There was a problem hiding this comment.
General purpose job query.
| purgeSchemaVersionsEndpoint.method(POST); | ||
| purgeSchemaVersionsEndpoint.description("Purge the unused schema versions."); | ||
| purgeSchemaVersionsEndpoint.consumes(APPLICATION_JSON); | ||
| purgeSchemaVersionsEndpoint.exampleRequest(miscExamples.createNameOrUuidsRequest()); |
There was a problem hiding this comment.
I favored a POST body over query parameters request, as it can hold more values, if required. Matter of a discussion though.
|
|
||
| @Override | ||
| public void beforeVersionDeletedFromDatabase(HibMicroschemaVersion version) { | ||
| HibernateTx tx = HibernateTx.get(); |
There was a problem hiding this comment.
It really looks to me that no one had ever tested the deletion of microschema versions until this moment.
Abstract
To same database time/space, we could delete empty versions.
Checklist
General
/CHANGELOG.adocOn API Changes