Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
db6dd66
[jindo] Route reads to io-cache targets by file type
sundapeng Oct 5, 2026
6d0ef43
[jindo] Ask OSS whether a file is gone in the FileIO helpers
sundapeng Oct 6, 2026
6cf5c55
[jindo] Route writes of cacheable files when io-cache.policy has write
sundapeng Oct 6, 2026
30a7d25
[jindo] Keep the FileIO defaults of deleteQuietly, readFileUtf8 and c…
sundapeng Oct 6, 2026
f2e0380
[jindo] Write the io-cache routing test cases inline
sundapeng Oct 6, 2026
8bb021c
Merge remote-tracking branch 'upstream/master' into io-cache-routing
sundapeng Oct 6, 2026
421917d
[jindo] Route exists to a target only with exists in io-cache.policy
sundapeng Oct 7, 2026
1e6598a
[jindo] Route metadata and index files only when named as Paimon writ…
sundapeng Oct 7, 2026
bd41c99
[jindo] Route the changelog manifests paimon-rust writes
sundapeng Oct 8, 2026
5af45bc
[jindo] Give Lance and Vortex the OSS options under io-cache routing
sundapeng Oct 12, 2026
a66792f
[jindo] Recognize postpone and paimon-rust managed BLOB file names in…
sundapeng Oct 13, 2026
3f51a2d
[core] Give each table its own io-cache view of its FileIO
sundapeng Oct 25, 2026
6e90d3a
[core] Keep io-cache views off FileIO, so forwarding FileIOs stay as …
sundapeng Oct 25, 2026
84363ff
[core] Scope the cached FileIO of a REST token to the catalog options…
sundapeng Oct 26, 2026
88561b9
[core] Cover ROW sidecars and the older prefixes a branch inherits in…
sundapeng Oct 26, 2026
39e3428
[common] Keep the io-cache view types in one internal interface
sundapeng Oct 26, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@

import org.apache.paimon.catalog.CatalogContext;
import org.apache.paimon.data.BlobDescriptor;
import org.apache.paimon.fs.iocache.IoCacheViewableFileIO;
import org.apache.paimon.fs.iocache.IoCacheViewableFileIO.TableView;
import org.apache.paimon.options.CatalogOptions;
import org.apache.paimon.options.Options;

import javax.annotation.Nullable;

import java.io.IOException;
import java.io.Serializable;
import java.time.Duration;
Expand All @@ -36,14 +40,39 @@
* An implementation of {@link FileIO} that supports multiple file system schemas. It dynamically
* selects the appropriate {@link FileIO} based on the URI scheme of the given path.
*/
public class ResolvingFileIO implements FileIO {
public class ResolvingFileIO implements IoCacheViewableFileIO {

private static final long serialVersionUID = 1L;

private final Map<CacheKey, FileIO> fileIOMap = new ConcurrentHashMap<>();

private CatalogContext context;

// a table view resolves through its base and applies the view to each FileIO
@Nullable private ResolvingFileIO base;
private TableView view = TableView.NONE;

@Override
public FileIO originOnly() {
return withView(view.originOnly());
}

@Override
public FileIO withTableView(TableView tableView) {
return withView(view.merge(tableView));
}

private FileIO withView(TableView newView) {
if (newView == view) {
return this;
}
ResolvingFileIO result = new ResolvingFileIO();
result.context = context;
result.base = base == null ? this : base;
result.view = newView;
return result;
}

// TODO, how to decide the real fileio is object store or not?
@Override
public boolean isObjectStore() {
Expand Down Expand Up @@ -143,6 +172,10 @@ public String createBlobPresignedUrl(

public FileIO fileIO(Path path) throws IOException {
CacheKey cacheKey = new CacheKey(path.toUri().getScheme(), path.toUri().getAuthority());
if (base != null) {
FileIO resolved = base.fileIO(path);
return fileIOMap.computeIfAbsent(cacheKey, k -> view.apply(resolved));
}
return fileIOMap.computeIfAbsent(
cacheKey,
k -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.apache.paimon.fs.PositionOutputStream;
import org.apache.paimon.fs.RemoteIterator;
import org.apache.paimon.fs.SeekableInputStream;
import org.apache.paimon.fs.iocache.IoCacheViewableFileIO;
import org.apache.paimon.fs.iocache.IoCacheViewableFileIO.TableView;
import org.apache.paimon.options.CatalogOptions;
import org.apache.paimon.options.MemorySize;
import org.apache.paimon.options.Options;
Expand Down Expand Up @@ -53,7 +55,7 @@
* <p>After deserialization, copies of the same catalog-created wrapper lazily reuse a JVM-local
* cache manager.
*/
public class CachingFileIO implements FileIO {
public class CachingFileIO implements IoCacheViewableFileIO {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -216,6 +218,28 @@ public void setRuntimeContext(Map<String, String> options) {
delegate.setRuntimeContext(options);
}

@Override
public FileIO originOnly() {
return withDelegate(IoCacheViewableFileIO.originOnly(delegate));
}

@Override
public FileIO withTableView(TableView view) {
return withDelegate(IoCacheViewableFileIO.withTableView(delegate, view));
}

// a view shares this wrapper's cache
private FileIO withDelegate(FileIO view) {
return view == delegate
? this
: new CachingFileIO(
view,
getOrCreateCacheManager(),
whitelist,
cacheConfiguration,
cacheNamespace);
}

@Override
public void close() throws IOException {
SharedCacheManager shared;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.paimon.fs.iocache;

import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;

import javax.annotation.Nullable;

import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

/**
* A {@link FileIO} whose io-cache routing can be narrowed to the origin or to one table's files.
* Internal to io-cache routing, not a public API.
*/
public interface IoCacheViewableFileIO extends FileIO {

/** A view of this FileIO that sends no request to an io-cache target, for mutable files. */
FileIO originOnly();

/** A view of this FileIO for one table: io-cache routing only serves that table's files. */
FileIO withTableView(TableView view);

/** {@link #originOnly()} of a FileIO that supports views; any other FileIO as is. */
static FileIO originOnly(FileIO fileIO) {
return fileIO instanceof IoCacheViewableFileIO
? ((IoCacheViewableFileIO) fileIO).originOnly()
: fileIO;
}

/** {@link #withTableView(TableView)} of a FileIO that supports views; any other as is. */
static FileIO withTableView(FileIO fileIO, TableView view) {
return fileIO instanceof IoCacheViewableFileIO
? ((IoCacheViewableFileIO) fileIO).withTableView(view)
: fileIO;
}

/** Loads the data file prefixes of the schemas a table has had. */
interface PrefixHistory extends Serializable {

/** Reads them through {@code fileIO}, which sends no request to an io-cache target. */
List<String> filePrefixes(FileIO fileIO) throws IOException;
}

/**
* What io-cache routing knows about the table a FileIO view serves: the locations it owns, the
* prefixes of its data files and where to find the prefixes of its older schemas.
*/
final class TableView implements Serializable {

private static final long serialVersionUID = 1L;

public static final TableView NONE =
new TableView(false, Collections.emptyList(), Collections.emptyList(), null);

private static final TableView ORIGIN_ONLY =
new TableView(true, Collections.emptyList(), Collections.emptyList(), null);

private final boolean originOnly;
private final List<String> roots;
private final List<String> filePrefixes;
@Nullable private final PrefixHistory history;

private TableView(
boolean originOnly,
List<String> roots,
List<String> filePrefixes,
@Nullable PrefixHistory history) {
this.originOnly = originOnly;
this.roots = roots;
this.filePrefixes = filePrefixes;
this.history = history;
}

/** The view of a table whose files are under {@code roots}. */
public static TableView of(
Collection<Path> roots,
Collection<String> filePrefixes,
@Nullable PrefixHistory history) {
List<String> normalizedRoots = new ArrayList<>();
for (Path root : roots) {
addIfAbsent(normalizedRoots, normalizeRoot(root));
}
List<String> prefixes = new ArrayList<>();
for (String prefix : filePrefixes) {
if (prefix != null && !prefix.trim().isEmpty()) {
addIfAbsent(prefixes, prefix);
}
}
return new TableView(
false,
Collections.unmodifiableList(normalizedRoots),
Collections.unmodifiableList(prefixes),
history);
}

/** See {@link IoCacheViewableFileIO#originOnly()}. */
public TableView originOnly() {
return ORIGIN_ONLY;
}

/** This view also serving {@code other}'s table, with its history; origin only stays so. */
public TableView merge(TableView other) {
if (originOnly || other.isNone()) {
return this;
}
if (other.originOnly || isNone()) {
return other;
}
List<String> mergedRoots = new ArrayList<>(roots);
other.roots.forEach(root -> addIfAbsent(mergedRoots, root));
List<String> mergedPrefixes = new ArrayList<>(filePrefixes);
other.filePrefixes.forEach(prefix -> addIfAbsent(mergedPrefixes, prefix));
TableView merged =
new TableView(
false,
Collections.unmodifiableList(mergedRoots),
Collections.unmodifiableList(mergedPrefixes),
other.history == null ? history : other.history);
return merged.equals(this) ? this : merged;
}

public boolean isOriginOnly() {
return originOnly;
}

public boolean isNone() {
return this == NONE || (!originOnly && roots.isEmpty() && filePrefixes.isEmpty());
}

/** Normalized {@code scheme://authority/path} of each location the table owns. */
public List<String> roots() {
return roots;
}

public List<String> filePrefixes() {
return filePrefixes;
}

@Nullable
public PrefixHistory history() {
return history;
}

/** Whether {@code path} is one of the roots or under one. */
public static boolean isUnder(List<String> roots, Path path) {
String location = normalizeRoot(path);
for (String root : roots) {
if (location.equals(root) || location.startsWith(root + "/")) {
return true;
}
}
return false;
}

public FileIO apply(FileIO fileIO) {
if (originOnly) {
return IoCacheViewableFileIO.originOnly(fileIO);
}
return isNone() ? fileIO : IoCacheViewableFileIO.withTableView(fileIO, this);
}

private static String normalizeRoot(Path path) {
URI uri = path.toUri();
String scheme = uri.getScheme() == null ? "" : uri.getScheme().toLowerCase(Locale.ROOT);
String authority = uri.getAuthority() == null ? "" : uri.getAuthority();
String location = uri.getPath() == null ? "" : uri.getPath();
while (location.endsWith("/")) {
location = location.substring(0, location.length() - 1);
}
return scheme + "://" + authority + location;
}

private static void addIfAbsent(List<String> list, String value) {
if (!list.contains(value)) {
list.add(value);
}
}

@Override
public boolean equals(Object o) {
if (!(o instanceof TableView)) {
return false;
}
TableView that = (TableView) o;
return originOnly == that.originOnly
&& roots.equals(that.roots)
&& filePrefixes.equals(that.filePrefixes)
&& Objects.equals(history, that.history);
}

@Override
public int hashCode() {
return Objects.hash(originOnly, roots, filePrefixes, history);
}

@Override
public String toString() {
return originOnly
? "TableView{originOnly}"
: "TableView{roots=" + roots + ", prefixes=" + filePrefixes + "}";
}
}
}
Loading
Loading