Skip to content

Commit

Permalink
S3 storage: fix issues from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
vgskye committed Feb 23, 2024
1 parent 052a96c commit 75c4f61
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
import java.util.Optional;

@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"})
@DebugDump
@ConfigSerializable
public class S3Config extends StorageConfig implements S3StorageSettings {
private String endpoint = null;
private String region = "";
private String accessKey = "";
@DebugDump private String endpoint = null;
@DebugDump private String region = "";
@DebugDump private String accessKey = "";
private String secretKey = "";
private String bucket = "";
private Compression compression = Compression.GZIP;
@DebugDump private String bucket = "";
@DebugDump private Compression compression = Compression.GZIP;

@Override
public Optional<String> getEndpoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.bluecolored.bluemap.core.util.OnCloseOutputStream;
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
Expand Down Expand Up @@ -62,10 +63,9 @@ public Optional<CompressedInputStream> readMapTile(String mapId, int lod, Vector
.build()
);
return Optional.of(new CompressedInputStream(is, compression));
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return Optional.empty();
}
} catch (NoSuchKeyException e) {
return Optional.empty();
} catch (SdkException e) {
throw new IOException(e);
}
}
Expand Down Expand Up @@ -104,10 +104,9 @@ public long getLastModified() {
return info.lastModified().getEpochSecond();
}
});
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return Optional.empty();
}
} catch (NoSuchKeyException e) {
return Optional.empty();
} catch (SdkException e) {
throw new IOException(e);
}
}
Expand All @@ -123,10 +122,8 @@ public void deleteMapTile(String mapId, int lod, Vector2i tile) throws IOExcepti
.key(path)
.build()
);
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return;
}
} catch (NoSuchKeyException ignored) {
} catch (SdkException e) {
throw new IOException(e);
}
}
Expand Down Expand Up @@ -166,10 +163,9 @@ public Optional<InputStream> readMeta(String mapId, String name) throws IOExcept
.build()
);
return Optional.of(is);
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return Optional.empty();
}
} catch (NoSuchKeyException e) {
return Optional.empty();
} catch (SdkException e) {
throw new IOException(e);
}
}
Expand Down Expand Up @@ -197,10 +193,9 @@ public long getSize() {
return info.contentLength();
}
});
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return Optional.empty();
}
} catch (NoSuchKeyException e) {
return Optional.empty();
} catch (SdkException e) {
throw new IOException(e);
}
}
Expand All @@ -216,10 +211,8 @@ public void deleteMeta(String mapId, String name) throws IOException {
.key(path)
.build()
);
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return;
}
} catch (NoSuchKeyException ignored) {
} catch (SdkException e) {
throw new IOException(e);
}
}
Expand All @@ -238,22 +231,21 @@ public void purgeMap(String mapId, Function<ProgressInfo, Boolean> onProgress) t
var filesList = files.contents().stream().collect(Collectors.toList());
for (int i = 0; i < filesList.size(); i++) {
var file = filesList.get(i);
client.deleteObject(
DeleteObjectRequest
.builder()
.bucket(bucket)
.key(file.key())
.build()
);
try {
client.deleteObject(
DeleteObjectRequest
.builder()
.bucket(bucket)
.key(file.key())
.build()
);
} catch (NoSuchKeyException ignored) {}

if (!onProgress.apply(
new ProgressInfo((double) (i + 1) / filesList.size())
)) return;
}
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return;
}
} catch (SdkException e) {
throw new IOException(e);
}
}
Expand Down

0 comments on commit 75c4f61

Please sign in to comment.