You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by st...@apache.org on 2024/02/26 14:27:35 UTC
(jackrabbit-oak) 01/01: OAK-10660 : childOrder overwrite-cleanup variant based on getBranch, without additional wiring
This is an automated email from the ASF dual-hosted git repository.
stefanegli pushed a commit to branch OAK-10660-alt
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 617f5e7499ae94a5d3fc648c7f30d40c0906741d
Author: Stefan Egli <st...@apache.org>
AuthorDate: Mon Feb 26 15:27:18 2024 +0100
OAK-10660 : childOrder overwrite-cleanup variant based on getBranch, without additional wiring
---
.../jackrabbit/oak/plugins/document/Commit.java | 40 +++++++++++++++-------
1 file changed, 28 insertions(+), 12 deletions(-)
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
index ea241a79b8..7299a49353 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
@@ -25,6 +25,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
import org.apache.jackrabbit.guava.common.base.Function;
@@ -362,20 +363,35 @@ public class Commit {
NodeDocument.setCommitRoot(op, revision, commitRootDepth);
// special case for :childOrder updates
- if (store.isCommitCleanupFeatureEnabled() && !previousRevisions.isEmpty()) {
- boolean removePreviousSetOperations = false;
- for (Map.Entry<Key, Operation> change : op.getChanges().entrySet()) {
- if (":childOrder".equals(change.getKey().getName()) && Operation.Type.SET_MAP_ENTRY == change.getValue().type) {
- // we are setting child order, so we should remove previous set operations from the same branch
- removePreviousSetOperations= true;
+ if (store.isCommitCleanupFeatureEnabled()) {
+ final Branch localBranch = getBranch();
+ if (localBranch != null) {
+ final TreeSet<Revision> commits = new TreeSet<>(localBranch.getCommits());
+ boolean removePreviousSetOperations = false;
+ for (Map.Entry<Key, Operation> change : op.getChanges().entrySet()) {
+ if (":childOrder".equals(change.getKey().getName()) && Operation.Type.SET_MAP_ENTRY == change.getValue().type) {
+ // we are setting child order, so we should remove previous set operations from the same branch
+ removePreviousSetOperations = true;
+ // branch.getCommits contains all revisions of the branch
+ // including the new one we're about to make
+ // so don't do a removeMapEntry for that
+ commits.remove(change.getKey().getRevision().asBranchRevision());
+ }
}
- }
-
- if (removePreviousSetOperations) {
- for (Revision rev : previousRevisions) {
- op.removeMapEntry(":childOrder", rev);
+ if (removePreviousSetOperations) {
+ if (!commits.isEmpty()) {
+ int countRemoves = 0;
+ for (Revision rev : commits.descendingSet()) {
+ op.removeMapEntry(":childOrder", rev.asTrunkRevision());
+ if (++countRemoves >= 256) {
+ LOG.debug("applyToDocumentStore : only cleaning up last {} branch commits.",
+ countRemoves);
+ break;
+ }
+ }
+ LOG.debug("applyToDocumentStore : childOrder-edited op is: " + op);
+ }
}
- LOG.debug("edited op is: " + op);
}
}