Skip to content

Commit

Permalink
Merge pull request #1281 from tdrwenski/fix-s3-perf-regression
Browse files Browse the repository at this point in the history
Revert s3 performance regression that checked if files were ncml by opening them
  • Loading branch information
haileyajohnson authored Dec 29, 2023
2 parents 50045d8 + d59848f commit a4cd72c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cdm/core/src/main/java/ucar/nc2/dataset/DatasetUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ public static DatasetUrl findDatasetUrl(String orgLocation) throws IOException {
// - we have a simple url: e.g. http://... ; contact the server
if (leadProtocol.equals("file") || leadProtocol.equals("cdms3")) {
serviceType = decodePathExtension(trueUrl); // look at the path extension
if (serviceType == null && checkIfNcml(MFiles.create(location))) {
// If it's a S3 file, it is expensive to peak inside to check if it's ncml, so we will only check extension
if (serviceType == null && !leadProtocol.equals("cdms3") && checkIfNcml(new File(location))) {
serviceType = ServiceType.NCML;
}
} else {
Expand Down Expand Up @@ -514,12 +515,12 @@ private static boolean checkIfRemoteNcml(String location) throws IOException {
return false;
}

private static boolean checkIfNcml(MFile mFile) throws IOException {
if (!mFile.exists()) {
private static boolean checkIfNcml(File file) throws IOException {
if (!file.exists()) {
return false;
}

try (BufferedInputStream in = new BufferedInputStream(mFile.getInputStream(), NUM_BYTES_TO_DETERMINE_NCML)) {
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file), NUM_BYTES_TO_DETERMINE_NCML)) {
byte[] bytes = new byte[NUM_BYTES_TO_DETERMINE_NCML];
int bytesRead = in.read(bytes);

Expand Down

0 comments on commit a4cd72c

Please sign in to comment.