magibney commented on code in PR #13555: URL: https://github.com/apache/lucene/pull/13555#discussion_r1674172898
########## lucene/core/src/java21/org/apache/lucene/store/GroupedArena.java: ########## @@ -0,0 +1,212 @@ +/* + * 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.lucene.store; + +import java.lang.foreign.AddressLayout; +import java.lang.foreign.Arena; +import java.lang.foreign.MemoryLayout; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; +import java.nio.file.Path; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.lucene.index.IndexFileNames; + +@SuppressWarnings("preview") +final class GroupedArena implements Arena { + + private final String scopeId; + + private final ConcurrentHashMap<String, GroupedArena> arenas; + + private final Arena backing; + + private final AtomicInteger refCt; + + static Arena get(Path p, ConcurrentHashMap<String, GroupedArena> arenas) { + String filename = p.getFileName().toString(); + String segmentName = IndexFileNames.parseSegmentName(filename); + if (filename.length() == segmentName.length()) { + // no segment found; return a 1-off Arena + return Arena.ofShared(); + } + String scopeId = p.getParent().resolve(segmentName).toString(); + Arena ret; + do { Review Comment: 60ff62d9cdd9dec584b8e6ce63e4a7af13b828a2 rewrites this (without the need to clone, and without the `boolean[]` modifiable holder), but I still think we may need the while loop; I tried to better explain my reasoning in the comment: ```java // We loop below to protect against the possibility that we get an entry that is // in the process of being closed. It is unlikely (perhaps impossible?) that this // would happen in practice, based on how Lucene opens IndexInputs. But if we // don't check here it's theoretically possible that our return value would be // backed by an Arena that is closed (and would throw IllegalStateException). // NOTE also: if we admit the possibility that a `Directory` can be used for // purposes other than a Lucene index, then we don't have the implicit protection // conferred by expected usage patterns, and it becomes all the more important to // loop to protect against the possibility of concurrent open/close. ``` -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org