-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to disable filesystem caching of /_delta_log/ directory
- Loading branch information
1 parent
59d0181
commit 8877a18
Showing
7 changed files
with
261 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...no-delta-lake/src/test/java/io/trino/plugin/deltalake/DeltaLakeAlluxioCacheTestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Licensed 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 io.trino.plugin.deltalake; | ||
|
||
import com.google.common.collect.HashMultiset; | ||
import com.google.common.collect.Multiset; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.trino.testing.QueryRunner; | ||
|
||
import java.util.OptionalLong; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static io.trino.filesystem.tracing.CacheFileSystemTraceUtils.CacheOperation; | ||
import static io.trino.filesystem.tracing.CacheFileSystemTraceUtils.getCacheOperationSpans; | ||
import static io.trino.filesystem.tracing.CacheFileSystemTraceUtils.getFileLocation; | ||
import static io.trino.filesystem.tracing.CacheSystemAttributes.CACHE_FILE_READ_POSITION; | ||
import static io.trino.filesystem.tracing.CacheSystemAttributes.CACHE_FILE_READ_SIZE; | ||
import static io.trino.filesystem.tracing.CacheSystemAttributes.CACHE_FILE_WRITE_POSITION; | ||
import static io.trino.filesystem.tracing.CacheSystemAttributes.CACHE_FILE_WRITE_SIZE; | ||
import static io.trino.filesystem.tracing.FileSystemAttributes.FILE_READ_POSITION; | ||
import static io.trino.filesystem.tracing.FileSystemAttributes.FILE_READ_SIZE; | ||
import static java.util.Objects.requireNonNull; | ||
import static java.util.stream.Collectors.toCollection; | ||
|
||
public final class DeltaLakeAlluxioCacheTestUtils | ||
{ | ||
private static final Pattern dataFilePattern = Pattern.compile(".*?/(?<partition>((\\w+)=[^/]*/)*)(?<queryId>\\d{8}_\\d{6}_\\d{5}_\\w{5})_(?<uuid>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"); | ||
|
||
private DeltaLakeAlluxioCacheTestUtils() | ||
{} | ||
|
||
public static Multiset<CacheOperation> getCacheOperations(QueryRunner queryRunner) | ||
{ | ||
return getCacheOperationSpans(queryRunner) | ||
.stream() | ||
.map(DeltaLakeAlluxioCacheTestUtils::createCacheOperation) | ||
.collect(toCollection(HashMultiset::create)); | ||
} | ||
|
||
private static CacheOperation createCacheOperation(SpanData span) | ||
{ | ||
String operationName = span.getName(); | ||
Attributes attributes = span.getAttributes(); | ||
String path = getFileLocation(span); | ||
String fileName = path.replaceFirst(".*/", ""); | ||
|
||
OptionalLong position = switch (operationName) { | ||
case "Alluxio.readCached", "Alluxio.readExternalStream" -> OptionalLong.of(requireNonNull(attributes.get(CACHE_FILE_READ_POSITION))); | ||
case "Alluxio.writeCache" -> OptionalLong.of(requireNonNull(attributes.get(CACHE_FILE_WRITE_POSITION))); | ||
case "Input.readFully" -> OptionalLong.of(requireNonNull(attributes.get(FILE_READ_POSITION))); | ||
default -> OptionalLong.empty(); | ||
}; | ||
|
||
OptionalLong length = switch (operationName) { | ||
case "Alluxio.readCached", "Alluxio.readExternalStream" -> OptionalLong.of(requireNonNull(attributes.get(CACHE_FILE_READ_SIZE))); | ||
case "Alluxio.writeCache" -> OptionalLong.of(requireNonNull(attributes.get(CACHE_FILE_WRITE_SIZE))); | ||
case "Input.readFully" -> OptionalLong.of(requireNonNull(attributes.get(FILE_READ_SIZE))); | ||
default -> OptionalLong.empty(); | ||
}; | ||
|
||
if (!path.contains("_delta_log") && !path.contains("/.trino")) { | ||
Matcher matcher = dataFilePattern.matcher(path); | ||
if (matcher.matches()) { | ||
String changeData = path.contains("/_change_data/") ? "change_data/" : ""; | ||
if (!path.contains("=")) { | ||
return new CacheOperation(operationName, "data", position, length); | ||
} | ||
return new CacheOperation(operationName, changeData + matcher.group("partition"), position, length); | ||
} | ||
if (path.contains("/part-00000-")) { | ||
return new CacheOperation(operationName, "data", position, length); | ||
} | ||
if (path.contains("/deletion_vector_")) { | ||
return new CacheOperation(operationName, "deletion_vector", position, length); | ||
} | ||
} | ||
else { | ||
return new CacheOperation(operationName, fileName, position, length); | ||
} | ||
throw new IllegalArgumentException("File not recognized: " + path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.