yashmayya commented on code in PR #19021: URL: https://github.com/apache/pinot/pull/19021#discussion_r3707330495
########## pinot-segment-spi-foreign/pom.xml: ########## @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>pinot</artifactId> + <groupId>org.apache.pinot</groupId> + <version>1.6.0-SNAPSHOT</version> + </parent> + <artifactId>pinot-segment-spi-foreign</artifactId> Review Comment: Why do we need a separate module for this and why is it called `spi` - isn't it actually just the implementation? Why can't this just sit in `pinot-segment-local` instead? ########## pinot-segment-spi-foreign/src/main/java/org/apache/pinot/segment/spi/memory/foreign/ForeignPinotBufferFactory.java: ########## @@ -0,0 +1,92 @@ +/** + * 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.pinot.segment.spi.memory.foreign; + +import java.io.File; +import java.io.IOException; +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.nio.ByteOrder; +import java.nio.channels.FileChannel; +import java.nio.file.StandardOpenOption; +import org.apache.pinot.segment.spi.memory.NonNativePinotDataBuffer; +import org.apache.pinot.segment.spi.memory.PinotBufferFactory; +import org.apache.pinot.segment.spi.memory.PinotDataBuffer; + + +/// A [PinotBufferFactory] that creates buffers backed by the Foreign Function & Memory API. +/// +/// This is the Java 21+ alternative to +/// [org.apache.pinot.segment.spi.memory.unsafe.UnsafePinotBufferFactory]. It produces [ForeignPinotBuffer] instances +/// backed by a [MemorySegment]. Every buffer owns a dedicated [shared arena][Arena#ofShared()] so that the buffer can +/// be accessed and closed from any thread; closing the buffer closes the arena, which frees the native memory or +/// unmaps the file. +/// +/// Unlike the Unsafe factory this works on every operating system (including Windows), needs no reflection, and maps +/// files larger than [Integer#MAX_VALUE] directly through [FileChannel#map(FileChannel.MapMode, long, long, Arena)]. +/// +/// To select this factory set the `pinot.offheap.buffer.factory` configuration (or the `PINOT_BUFFER_LIBRARY` +/// environment variable) to this class' fully qualified name. +public class ForeignPinotBufferFactory implements PinotBufferFactory { + + @Override + public PinotDataBuffer allocateDirect(long size, ByteOrder byteOrder) { + Arena arena = Arena.ofShared(); Review Comment: There's no safety net here for a leaked buffer. `MmapMemory` has a `finalize()` that `WARN`s and unmaps on GC. `PinotByteBuffer` relies on `DirectByteBuffer`'s cleaner. `Arena.ofShared()` doesn't register a `Cleaner` so lacks a self healing mechanism on leaks. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
