Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pinot-segment-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
<groupId>org.xerial.larray</groupId>
<artifactId>larray-mmap</artifactId>
</dependency>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-bytes</artifactId>
<version>2.23.31</version>
</dependency>

<!-- test -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,17 @@ public long size() {

@Override
public PinotDataBuffer view(long start, long end, ByteOrder byteOrder) {
PinotNativeOrderLBuffer view = new PinotNativeOrderLBuffer(_buffer.view(start, end), false, false);
if (byteOrder == NATIVE_ORDER) {
return new PinotNativeOrderLBuffer(_buffer.view(start, end), false, false);
return view;
} else {
return new PinotNonNativeOrderLBuffer(_buffer.view(start, end), false, false);
return new NonNativePinotDataBuffer(view);
}
}

@Override
public ByteBuffer toDirectByteBuffer(long offset, int size, ByteOrder byteOrder) {
return _buffer.toDirectByteBuffer(offset, size).order(byteOrder);
return ByteBufferUtil.newDirectByteBuffer(offset, size, this).order(byteOrder);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* 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;

import com.google.common.base.Preconditions;
import java.io.File;
import java.io.IOException;
import java.nio.ByteOrder;


public class ByteBufferPinotBufferFactory implements PinotBufferFactory {
@Override
public PinotDataBuffer allocateDirect(long size, ByteOrder byteOrder) {
Preconditions.checkArgument(size <= Integer.MAX_VALUE,
"Trying to allocate {} bytes when max is {}", size, Integer.MAX_VALUE);
return PinotByteBuffer.allocateDirect((int) size, byteOrder);
}

@Override
public PinotDataBuffer readFile(File file, long offset, long size, ByteOrder byteOrder)
throws IOException {
Preconditions.checkArgument(size <= Integer.MAX_VALUE,
"Trying to allocate {} bytes when max is {}", size, Integer.MAX_VALUE);
return PinotByteBuffer.loadFile(file, offset, (int) size, byteOrder);
}

@Override
public PinotDataBuffer mapFile(File file, boolean readOnly, long offset, long size, ByteOrder byteOrder)
throws IOException {
Preconditions.checkArgument(size <= Integer.MAX_VALUE,
"Trying to allocate {} bytes when max is {}", size, Integer.MAX_VALUE);
return PinotByteBuffer.mapFile(file, readOnly, offset, (int) size, byteOrder);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* 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;

import com.google.common.collect.Lists;
import java.lang.reflect.Constructor;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;


public class ByteBufferUtil {

private static final ByteBufferCreator _creator;
private static final List<CreatorSupplier> _SUPPLIERS = Lists.newArrayList(
() -> {
Constructor<? extends ByteBuffer> dbbCC =
(Constructor<? extends ByteBuffer>) Class.forName("java.nio.DirectByteBuffer")
.getDeclaredConstructor(Long.TYPE, Integer.TYPE, Object.class);
return (addr, size, att) -> {
dbbCC.setAccessible(true);
try {
return dbbCC.newInstance(Long.valueOf(addr), Integer.valueOf(size), att);
} catch (Exception e) {
throw new IllegalStateException("Failed to create DirectByteBuffer", e);
}
};
},
() -> {
Constructor<? extends ByteBuffer> dbbCC =
(Constructor<? extends ByteBuffer>) Class.forName("java.nio.DirectByteBuffer")
.getDeclaredConstructor(Long.TYPE, Integer.TYPE);
return (addr, size, att) -> {
dbbCC.setAccessible(true);
try {
return dbbCC.newInstance(Long.valueOf(addr), Integer.valueOf(size));
} catch (Exception e) {
throw new IllegalStateException("Failed to create DirectByteBuffer", e);
}
};
}
);

private ByteBufferUtil() {
}

static {
ByteBufferCreator creator = null;
Exception firstException = null;
for (CreatorSupplier supplier : _SUPPLIERS) {
try {
creator = supplier.createCreator();
} catch (ClassNotFoundException | NoSuchMethodException e) {
if (firstException == null) {
firstException = e;
}
}
}
if (creator == null) {
throw new IllegalStateException("Cannot find a way to instantiate DirectByteBuffer. "
+ "Please verify you are using a supported JVM", firstException);
}
_creator = creator;
}

public static ByteBuffer newDirectByteBuffer(long addr, int size, Object att) {
return _creator.newDirectByteBuffer(addr, size, att);
}

private interface CreatorSupplier {
ByteBufferCreator createCreator() throws ClassNotFoundException, NoSuchMethodException;
}

private interface ByteBufferCreator {
ByteBuffer newDirectByteBuffer(long addr, int size, Object att);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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;

import java.io.File;
import java.io.IOException;


public class LArrayPinotBufferFactory extends OnlyNativePinotBufferFactory {
@Override
protected PinotDataBuffer allocateDirect(long size) {
return PinotNativeOrderLBuffer.allocateDirect(size);
}

@Override
protected PinotDataBuffer mapFile(File file, boolean readOnly, long offset, long size)
throws IOException {
return PinotNativeOrderLBuffer.mapFile(file, readOnly, offset, size);
}
}
Loading