Skip to content
Merged
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
17 changes: 1 addition & 16 deletions plugin/trino-delta-lake/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -331,23 +331,8 @@
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>6.0.13</version>
<version>7.1.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<!-- conflicts with version pulled from trino-hive -->
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import io.airlift.log.Logger;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import io.minio.notification.NotificationEvent;
import io.minio.notification.NotificationInfo;
import io.minio.BucketExistsArgs;
import io.minio.CloseableIterator;
import io.minio.ListObjectsArgs;
import io.minio.ListenBucketNotificationArgs;
import io.minio.MakeBucketArgs;
import io.minio.PutObjectArgs;
import io.minio.Result;
import io.minio.messages.Event;
import io.minio.messages.NotificationRecords;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -72,12 +77,10 @@ public MinioClient()

public MinioClient(String endpoint, String accessKey, String secretKey)
{
try {
client = new io.minio.MinioClient(endpoint, accessKey, secretKey);
}
catch (InvalidPortException | InvalidEndpointException e) {
throw new RuntimeException(e);
}
client = io.minio.MinioClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.build();
}

public void copyResourcePath(String bucket, String resourcePath, String target)
Expand Down Expand Up @@ -106,13 +109,14 @@ public void putObject(String bucket, byte[] contents, String targetPath)
putObject(bucket, ByteSource.wrap(contents), targetPath);
}

public void captureBucketNotifications(String bucket, Consumer<NotificationEvent> consumer)
public void captureBucketNotifications(String bucket, Consumer<Event> consumer)
{
ensureBucketExists(bucket);

ListenableFuture<?> future = executor.submit(new NotificationListener(client, bucket, consumer));

addCallback(future, new FutureCallback<Object>() {
addCallback(future, new FutureCallback<Object>()
{
@Override
public void onSuccess(Object result)
{
Expand All @@ -130,16 +134,21 @@ public void onFailure(Throwable t)
public List<String> listObjects(String bucket, String path)
{
try {
return stream(client.listObjects(bucket, path)).map(
result -> {
return stream(client.listObjects(
ListObjectsArgs.builder()
.bucket(bucket)
.prefix(path)
.recursive(true)
.useUrlEncodingType(false)
.build()))
.map(result -> {
try {
return result.get().objectName();
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
).collect(toImmutableList());
}).collect(toImmutableList());
}
catch (Exception e) {
throw new RuntimeException(e);
Expand All @@ -156,7 +165,10 @@ public void makeBucket(String bucketName)
throw new IllegalArgumentException("Bucket " + bucketName + " already created in this classloader");
}
try {
client.makeBucket(bucketName);
client.makeBucket(
MakeBucketArgs.builder()
.bucket(bucketName)
.build());
}
catch (Exception e) {
// revert bucket registration so we can retry the call on transient errors
Expand All @@ -168,7 +180,9 @@ public void makeBucket(String bucketName)
public void ensureBucketExists(String bucketName)
{
try {
if (!client.bucketExists(bucketName)) {
if (!client.bucketExists(BucketExistsArgs.builder()
.bucket(bucketName)
.build())) {
makeBucket(bucketName);
}
}
Expand All @@ -181,7 +195,12 @@ private void putObject(String bucket, ByteSource byteSource, String targetPath)
{
try {
try (InputStream inputStream = byteSource.openStream()) {
client.putObject(bucket, targetPath, inputStream, null, null, null, null);
client.putObject(
PutObjectArgs.builder()
.bucket(bucket)
.object(targetPath)
.stream(inputStream, byteSource.size(), -1)
.build());
}
}
catch (Exception e) {
Expand All @@ -198,12 +217,11 @@ public void close()
private static class NotificationListener
implements Runnable
{
private final Logger logger = Logger.get(MinioClient.NotificationListener.class);
private final io.minio.MinioClient client;
private final String bucket;
private final Consumer<NotificationEvent> consumer;
private final Consumer<Event> consumer;

private NotificationListener(io.minio.MinioClient client, String bucket, Consumer<NotificationEvent> consumer)
private NotificationListener(io.minio.MinioClient client, String bucket, Consumer<Event> consumer)
{
this.client = requireNonNull(client, "client is null");
this.bucket = requireNonNull(bucket, "bucket is null");
Expand All @@ -213,24 +231,21 @@ private NotificationListener(io.minio.MinioClient client, String bucket, Consume
@Override
public void run()
{
try {
client.listenBucketNotification(bucket, "*", "*", ALL_MINIO_EVENTS, this::processNotificationInfo);
try (CloseableIterator<Result<NotificationRecords>> iterator = client.listenBucketNotification(
ListenBucketNotificationArgs.builder()
.bucket(bucket)
.prefix("*")
.suffix("*")
.events(ALL_MINIO_EVENTS)
.build())) {
while (iterator.hasNext()) {
NotificationRecords records = iterator.next().get();
records.events().forEach(consumer);
}
}
catch (Exception e) {
throw new RuntimeException(e);
}
}

private void processNotificationInfo(NotificationInfo notificationInfo)
{
for (int i = 0; i < notificationInfo.records.length; i++) {
try {
consumer.accept(notificationInfo.records[i]);
}
catch (Exception e) {
logger.warn(e, "Notification was not accepted");
}
}
}
}
}