thomasmueller commented on code in PR #1202: URL: https://github.com/apache/jackrabbit-oak/pull/1202#discussion_r1394267494
########## oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedUtils.java: ########## @@ -0,0 +1,45 @@ +/* + * 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.index.indexer.document.flatfile.pipelined; + +import org.apache.commons.io.FileUtils; + +public class PipelinedUtils { + /** + * <p>Format a percentage as a string with 2 decimal places. For instance: + * <code>formatAsPercentage(52, 1000)</code> returns <code>"5.20"</code>.</p> + */ + public static String formatAsPercentage(long numerator, long denominator) { + if (denominator == 0) { + return "N/A"; + } else { + return String.format("%1.2f", (100.0 * numerator) / denominator); + } + } + + public static String formatAsTransferSpeedMBs(long numberOfBytes, long timeMiilis) { Review Comment: Typo ```suggestion public static String formatAsTransferSpeedMBs(long numberOfBytes, long timeMillis) { ``` ########## oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedSortBatchTask.java: ########## @@ -116,48 +136,90 @@ public Result call() throws Exception { } } + private void buildSortArray(NodeStateEntryBatch nseb) { + Stopwatch startTime = Stopwatch.createStarted(); + ByteBuffer buffer = nseb.getBuffer(); + int totalPathSize = 0; + while (buffer.hasRemaining()) { + int positionInBuffer = buffer.position(); + // Read the next key from the buffer + int pathLength = buffer.getInt(); + totalPathSize += pathLength; + if (pathLength > copyBuffer.length) { + LOG.debug("Resizing copy buffer from {} to {}", copyBuffer.length, pathLength); + copyBuffer = new byte[pathLength]; + } + buffer.get(copyBuffer, 0, pathLength); + // Skip the json + int entryLength = buffer.getInt(); + buffer.position(buffer.position() + entryLength); + // Create the sort key + String path = new String(copyBuffer, 0, pathLength, StandardCharsets.UTF_8); + String[] pathSegments = SortKey.genSortKeyPathElements(path); Review Comment: Something like that: int pathSegmentCount = buffer.getInt(); String[] pathSegments = new String[pathSegments]; for (int i = 0; i < pathSegmentCount; i++) { pathSegments[i] = readString(buffer); } this is with a readString utility method, which maybe would anyway make sense. -- 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: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org