From 3648c98e4bb94f95add7e1f22caf2189c307012d Mon Sep 17 00:00:00 2001 From: Bruno Bossola Date: Mon, 24 May 2021 11:46:00 +0100 Subject: [PATCH] [REPO-5592] Support for PostgreSQL and MySQL, batch size is now configurable (#485) * Initial support for PosgreSQL, MySQL plus batchSize is now configurable * Changes post review --- .../content/cleanup/ContentStoreCleaner.java | 16 ++++++++++++++-- .../contentdata/ContentUrlOrphanQuery.java | 18 ++++++++++++++++-- .../contentdata/ibatis/ContentDataDAOImpl.java | 3 ++- .../alfresco/content-services-context.xml | 3 +++ .../content-select-SqlMap.xml | 5 +++-- .../content-select-SqlMap.xml | 1 + .../resources/alfresco/repository.properties | 2 ++ 7 files changed, 41 insertions(+), 7 deletions(-) diff --git a/repository/src/main/java/org/alfresco/repo/content/cleanup/ContentStoreCleaner.java b/repository/src/main/java/org/alfresco/repo/content/cleanup/ContentStoreCleaner.java index a835d3117a..bfbe1bbe71 100644 --- a/repository/src/main/java/org/alfresco/repo/content/cleanup/ContentStoreCleaner.java +++ b/repository/src/main/java/org/alfresco/repo/content/cleanup/ContentStoreCleaner.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -125,10 +125,12 @@ public class ContentStoreCleaner private ContentService contentService; private TransactionService transactionService; private int protectDays; + private int batchSize; private DeleteFailureAction deletionFailureAction; public ContentStoreCleaner() { + this.batchSize = 1000; this.protectDays = 7; this.deletionFailureAction = DeleteFailureAction.IGNORE; } @@ -192,6 +194,16 @@ public class ContentStoreCleaner this.protectDays = protectDays; } + /** + * Set the batch size used by the cleaning jobs. The default is 1000 + * + * @param batchSize batch size for each cleanup job + */ + public void setBatchSize(int batchSize) + { + this.batchSize = batchSize; + } + /** * Set the action to take in the event that an orphaned binary failed to get deleted. * The default is {@link DeleteFailureAction#IGNORE}. @@ -329,7 +341,7 @@ public class ContentStoreCleaner { public Long execute() throws Exception { - return cleanBatch(maxOrphanTime, 1000); + return cleanBatch(maxOrphanTime, batchSize); }; }; while (true) diff --git a/repository/src/main/java/org/alfresco/repo/domain/contentdata/ContentUrlOrphanQuery.java b/repository/src/main/java/org/alfresco/repo/domain/contentdata/ContentUrlOrphanQuery.java index 782fd01d23..39ed72d4b3 100644 --- a/repository/src/main/java/org/alfresco/repo/domain/contentdata/ContentUrlOrphanQuery.java +++ b/repository/src/main/java/org/alfresco/repo/domain/contentdata/ContentUrlOrphanQuery.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -34,6 +34,7 @@ package org.alfresco.repo.domain.contentdata; public class ContentUrlOrphanQuery { private Long maxOrphanTimeExclusive; + private Long maxRecords; @Override public String toString() @@ -41,6 +42,7 @@ public class ContentUrlOrphanQuery StringBuilder sb = new StringBuilder(512); sb.append("ContentUrlOrphanQuery") .append("[ maxOrphanTimeExclusive=").append(maxOrphanTimeExclusive) + .append(", maxRecords=").append(maxRecords) .append("]"); return sb.toString(); } @@ -53,5 +55,17 @@ public class ContentUrlOrphanQuery public void setMaxOrphanTimeExclusive(Long maxOrphanTimeExclusive) { this.maxOrphanTimeExclusive = maxOrphanTimeExclusive; - } + } + + public Long getMaxRecords() + { + return maxRecords; + } + + public void setMaxRecords(Long maxRecords) + { + this.maxRecords = maxRecords; + } + + } \ No newline at end of file diff --git a/repository/src/main/java/org/alfresco/repo/domain/contentdata/ibatis/ContentDataDAOImpl.java b/repository/src/main/java/org/alfresco/repo/domain/contentdata/ibatis/ContentDataDAOImpl.java index 4fa49e71cc..55d0a7471c 100644 --- a/repository/src/main/java/org/alfresco/repo/domain/contentdata/ibatis/ContentDataDAOImpl.java +++ b/repository/src/main/java/org/alfresco/repo/domain/contentdata/ibatis/ContentDataDAOImpl.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -155,6 +155,7 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl ContentUrlOrphanQuery query = new ContentUrlOrphanQuery(); query.setMaxOrphanTimeExclusive(maxOrphanTimeExclusive); + query.setMaxRecords((long) maxResults); List results = template.selectList(SELECT_CONTENT_URLS_ORPHANED, query, new RowBounds(0, maxResults)); diff --git a/repository/src/main/resources/alfresco/content-services-context.xml b/repository/src/main/resources/alfresco/content-services-context.xml index 3bdfbac6a3..aed14cdd9e 100644 --- a/repository/src/main/resources/alfresco/content-services-context.xml +++ b/repository/src/main/resources/alfresco/content-services-context.xml @@ -115,6 +115,9 @@ + + ${system.content.cleanerBatchSize} + diff --git a/repository/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/content-select-SqlMap.xml b/repository/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/content-select-SqlMap.xml index a070268dc5..0972b46e38 100644 --- a/repository/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/content-select-SqlMap.xml +++ b/repository/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/content-select-SqlMap.xml @@ -18,9 +18,10 @@ left outer join alf_content_data cd on (cd.content_url_id = cu.id) where cd.id is null and + cu.orphan_time is not null and cu.orphan_time > 0 and - cu.orphan_time < #{maxOrphanTimeExclusive} and - cu.orphan_time is not null + cu.orphan_time < #{maxOrphanTimeExclusive} + limit #{maxRecords} ]]> diff --git a/repository/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/content-select-SqlMap.xml b/repository/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/content-select-SqlMap.xml index 33f9e38ada..118e267533 100644 --- a/repository/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/content-select-SqlMap.xml +++ b/repository/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.MySQLInnoDBDialect/content-select-SqlMap.xml @@ -21,6 +21,7 @@ cu.orphan_time > 0 and cu.orphan_time < #{maxOrphanTimeExclusive} and cu.orphan_time is not null + limit #{maxRecords} ]]> diff --git a/repository/src/main/resources/alfresco/repository.properties b/repository/src/main/resources/alfresco/repository.properties index 71d10c8057..6012d8c185 100644 --- a/repository/src/main/resources/alfresco/repository.properties +++ b/repository/src/main/resources/alfresco/repository.properties @@ -219,6 +219,8 @@ system.content.orphanProtectDays=14 system.content.deletionFailureAction=IGNORE # The CRON expression to trigger the deletion of resources associated with orphaned content. system.content.orphanCleanup.cronExpression=0 0 4 * * ? +# The batch size user by the content store cleaner +system.content.cleanerBatchSize=1000 # The CRON expression to trigger the cleanup of deleted nodes and dangling transactions that are old enough system.nodeServiceCleanup.cronExpression=0 0 21 * * ?