shodaaan commented on code in PR #2252: URL: https://github.com/apache/jackrabbit-oak/pull/2252#discussion_r2063005909
########## oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoFullGcNodeBinSumBsonSize.java: ########## @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jackrabbit.oak.plugins.document.mongo; + +import com.mongodb.BasicDBObject; +import static com.mongodb.client.model.Filters.eq; +import static com.mongodb.client.model.Filters.in; +import com.mongodb.client.model.Updates; +import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; +import static org.apache.jackrabbit.oak.plugins.document.Collection.SETTINGS; +import static org.apache.jackrabbit.oak.plugins.document.Document.ID; +import org.apache.jackrabbit.oak.plugins.document.FullGcNodeBin; +import org.apache.jackrabbit.oak.plugins.document.NodeDocument; +import org.apache.jackrabbit.oak.plugins.document.UpdateOp; +import org.bson.conversions.Bson; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * This class is a wrapper around a MongoFullGcNodeBin + * that sums the bson size of the documents that are removed or updated and then update the value in the SETTINGS collection + */ +class MongoFullGcNodeBinSumBsonSize implements FullGcNodeBin { + private static final Logger LOG = LoggerFactory.getLogger(MongoFullGcNodeBinSumBsonSize.class); + + private final MongoFullGcNodeBin delegate; + private final MongoDocumentStore store; + + public MongoFullGcNodeBinSumBsonSize(MongoFullGcNodeBin delegate) { + this.delegate = delegate; + this.store = delegate.getMongoDocumentStore(); + } + + @Override + public void setEnabled(boolean value) { + delegate.setEnabled(value); + } + + @Override + public List<NodeDocument> findAndUpdate(List<UpdateOp> updateOpList) { + List<String> ids = updateOpList.stream().map(UpdateOp::getId).collect(Collectors.toList()); + //get the total bson size before the update + long initialBsonSize = getBsonSize(ids); + LOG.debug("bson size before update: {}", initialBsonSize); + //remove garbage properties + List<NodeDocument> updated = delegate.findAndUpdate(updateOpList); + if (!updated.isEmpty()) { + //calculate the diff of the bson size after update + long afterUpdateBsonSize = getBsonSize(ids); + LOG.debug("bson size after update: {}", afterUpdateBsonSize); + if (initialBsonSize > 0 && afterUpdateBsonSize > 0) { + //sum up the removed bson size + addBsonSize(initialBsonSize - afterUpdateBsonSize); + } + } + return updated; + } + + @Override + public int remove(Map<String, Long> orphanOrDeletedRemovalMap) { Review Comment: Please consider adding method description that mentions the fact that the size of deleted documents will be saved to the SETTINGS collection. ########## oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoFullGcNodeBinSumBsonSize.java: ########## @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jackrabbit.oak.plugins.document.mongo; + +import com.mongodb.BasicDBObject; +import static com.mongodb.client.model.Filters.eq; +import static com.mongodb.client.model.Filters.in; +import com.mongodb.client.model.Updates; +import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; +import static org.apache.jackrabbit.oak.plugins.document.Collection.SETTINGS; +import static org.apache.jackrabbit.oak.plugins.document.Document.ID; +import org.apache.jackrabbit.oak.plugins.document.FullGcNodeBin; +import org.apache.jackrabbit.oak.plugins.document.NodeDocument; +import org.apache.jackrabbit.oak.plugins.document.UpdateOp; +import org.bson.conversions.Bson; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * This class is a wrapper around a MongoFullGcNodeBin + * that sums the bson size of the documents that are removed or updated and then update the value in the SETTINGS collection + */ +class MongoFullGcNodeBinSumBsonSize implements FullGcNodeBin { + private static final Logger LOG = LoggerFactory.getLogger(MongoFullGcNodeBinSumBsonSize.class); + + private final MongoFullGcNodeBin delegate; + private final MongoDocumentStore store; + + public MongoFullGcNodeBinSumBsonSize(MongoFullGcNodeBin delegate) { + this.delegate = delegate; + this.store = delegate.getMongoDocumentStore(); + } + + @Override + public void setEnabled(boolean value) { + delegate.setEnabled(value); + } + + @Override + public List<NodeDocument> findAndUpdate(List<UpdateOp> updateOpList) { Review Comment: Please consider adding method description that mentions the fact that the size of deleted documents will be saved to the SETTINGS collection. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: oak-dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org