-
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
652445b
commit 7c4524f
Showing
6 changed files
with
153 additions
and
3 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
39 changes: 39 additions & 0 deletions
39
...c/main/java/io/trino/plugin/deltalake/cache/MutableDeltaLogDeltaLakeCacheKeyProvider.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,39 @@ | ||
/* | ||
* 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.cache; | ||
|
||
import io.trino.filesystem.TrinoInputFile; | ||
|
||
import java.util.Optional; | ||
|
||
import static io.trino.plugin.deltalake.transactionlog.TransactionLogUtil.TRANSACTION_LOG_DIRECTORY; | ||
|
||
public class MutableDeltaLogDeltaLakeCacheKeyProvider | ||
extends DeltaLakeCacheKeyProvider | ||
{ | ||
/** | ||
* Extends DeltaLakeCacheKeyProvider by returning Optional.empty() for all files in the _delta_log directory. | ||
* This CacheKeyProvider implementation is useful in those scenarios when Delta Tables are deleted and re-created, and caching their _delta_log directories should be avoided. | ||
*/ | ||
@Override | ||
public Optional<String> getCacheKey(TrinoInputFile inputFile) | ||
{ | ||
String path = inputFile.location().path(); | ||
// Explicitly exclude the files in the _delta_log directory as they can change when the Delta Table is overwritten, https://github.com/trinodb/trino/issues/21451 | ||
if (path.contains("/" + TRANSACTION_LOG_DIRECTORY + "/")) { | ||
return Optional.empty(); | ||
} | ||
return super.getCacheKey(inputFile); | ||
} | ||
} |
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
69 changes: 69 additions & 0 deletions
69
...st/java/io/trino/plugin/deltalake/cache/TestMutableDeltaLogDeltaLakeCacheKeyProvider.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,69 @@ | ||
/* | ||
* 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.cache; | ||
|
||
import io.trino.filesystem.Location; | ||
import io.trino.filesystem.TrinoInputFile; | ||
import io.trino.filesystem.cache.CacheKeyProvider; | ||
import io.trino.filesystem.memory.MemoryInputFile; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.parallel.Execution; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
import static io.airlift.slice.Slices.EMPTY_SLICE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; | ||
import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT; | ||
|
||
@TestInstance(PER_CLASS) | ||
@Execution(CONCURRENT) | ||
public class TestMutableDeltaLogDeltaLakeCacheKeyProvider | ||
{ | ||
private CacheKeyProvider cacheKeyProvider; | ||
|
||
@BeforeAll | ||
public void setUp() | ||
{ | ||
cacheKeyProvider = new MutableDeltaLogDeltaLakeCacheKeyProvider(); | ||
} | ||
|
||
@Test | ||
public void testCacheableFileReturnsCacheKey() | ||
throws IOException | ||
{ | ||
String filePath = "prefix/test_delta_table/part-00001-0161445f-38f8-46be-a0dc-d49ca3af30b2-c000.snappy.parquet"; | ||
TrinoInputFile cacheableFile = new MemoryInputFile(Location.of("memory:///" + filePath), EMPTY_SLICE); | ||
|
||
Optional<String> cacheKey = cacheKeyProvider.getCacheKey(cacheableFile); | ||
|
||
assertThat(cacheKey).isPresent(); | ||
assertThat(cacheKey.get()).isEqualTo(filePath); | ||
} | ||
|
||
@Test | ||
public void testUncacheableFileReturnsEmptyCacheKey() | ||
throws IOException | ||
{ | ||
String filePath = "prefix/test_delta_table/_delta_log/00000000000000000001.json"; | ||
TrinoInputFile uncacheableFile = new MemoryInputFile(Location.of("memory:///" + filePath), EMPTY_SLICE); | ||
|
||
Optional<String> cacheKey = cacheKeyProvider.getCacheKey(uncacheableFile); | ||
|
||
assertThat(cacheKey).isEmpty(); | ||
} | ||
} |