lweitzendorf commented on code in PR #2393: URL: https://github.com/apache/jackrabbit-oak/pull/2393#discussion_r2240741318
########## oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentGraph.java: ########## @@ -0,0 +1,243 @@ +/* + * 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.segment.file.tar; + +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.zip.CRC32; + +import org.apache.jackrabbit.oak.commons.Buffer; +import org.apache.jackrabbit.oak.segment.SegmentId; +import org.apache.jackrabbit.oak.segment.data.SegmentData; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; +import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class SegmentGraph { + + private static final Logger log = LoggerFactory.getLogger(SegmentGraph.class); + + private static final int FOOTER_SIZE = 16; + + /** + * Magic byte sequence at the end of the graph block. + * <p> + * The file is read from the end (the tar file is read from the end: the + * last entry is the index, then the graph). File format: + * <ul> + * <li>0 padding to make the footer end at a 512 byte boundary</li> + * <li>The list of UUIDs (segments included the graph; this includes + * segments in this tar file, and referenced segments in tar files with a + * lower sequence number). 16 bytes each.</li> + * <li>The graph data. The index of the source segment UUID (in the above + * list, 4 bytes), then the list of referenced segments (the indexes of + * those; 4 bytes each). Then the list is terminated by -1.</li> + * <li>The last part is the footer, which contains metadata of the graph + * (size, checksum, the number of UUIDs).</li> + * </ul> + */ + private static final int MAGIC = ('\n' << 24) + ('0' << 16) + ('G' << 8) + '\n'; + + @NotNull Map<UUID, Set<UUID>> edgeMap; + + public SegmentGraph() { + this.edgeMap = new HashMap<>(); + } + + private SegmentGraph(@NotNull Map<UUID, Set<UUID>> edgeMap) { + this.edgeMap = edgeMap; + } + + public void addEdge(@NotNull UUID from, @NotNull UUID to) { + edgeMap.computeIfAbsent(from, k -> new HashSet<>()).add(to); + } + + public @NotNull Map<UUID, Set<UUID>> getEdges() { + return Collections.unmodifiableMap(edgeMap); + } + + public @NotNull Set<UUID> getEdges(@NotNull UUID from) { Review Comment: The edges are only accessed in a handful of places, none of which seem sensitive to ordering. -- 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