Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[openhouse] Implement TableOperations-specific FileIO instance #241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions integrations/java/openhouse-java-runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ext {
sparkVersion = '3.1.1'
springVersion = '2.7.8'
hadoopVersion = '2.10.0'
caffeineVersion = '2.9.3'
}

dependencies {
Expand All @@ -41,6 +42,7 @@ dependencies {
exclude group: 'com.zaxxer', module: 'HikariCP-java7'
exclude group: 'org.apache.commons', module: 'commons-lang3'
}
implementation("com.github.ben-manes.caffeine:caffeine:" + caffeineVersion)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also do output jar check to see if the newly added library is appropriately relocated? the output jar should look as follows:
image


// Following codeblock completely relocates contents of the jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static com.linkedin.openhouse.javaclient.OpenHouseTableOperations.*;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalListener;
import com.linkedin.openhouse.client.ssl.HttpConnectionStrategy;
import com.linkedin.openhouse.client.ssl.TablesApiClientFactory;
import com.linkedin.openhouse.javaclient.api.SupportsGrantRevoke;
Expand All @@ -21,6 +24,7 @@
import com.linkedin.openhouse.tables.client.model.GetAllTablesResponseBody;
import com.linkedin.openhouse.tables.client.model.GetTableResponseBody;
import com.linkedin.openhouse.tables.client.model.UpdateAclPoliciesRequestBody;
import java.io.Closeable;
import java.net.MalformedURLException;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -68,7 +72,7 @@
*/
@Slf4j
public class OpenHouseCatalog extends BaseMetastoreCatalog
implements Configurable, SupportsNamespaces, SupportsGrantRevoke {
implements Configurable, SupportsNamespaces, SupportsGrantRevoke, Closeable {

private TableApi tableApi;

Expand All @@ -88,6 +92,8 @@ public class OpenHouseCatalog extends BaseMetastoreCatalog

protected Map<String, String> properties;

private Cache<TableOperations, FileIO> fileIOCloser;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these look like temporary duplication of code that will be available in upstream iceberg with version bump. Can we add a todo identifiying the PR and version of iceberg that introduced the fileIOcloser and instructions on removing the code duplication later?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious. How long the entries are present in the cache? Wondering if the cache will be populated with too many objects if there are more tables operation done in a short period of time. Do you think is going to consume more memory?


private static final String DEFAULT_CLUSTER = "local";

private static final String CLUSTER_PROPERTY = "cluster";
Expand Down Expand Up @@ -130,6 +136,7 @@ public void initialize(String name, Map<String, String> properties) {
this.fileIO = loadFileIO(properties);

this.cluster = properties.getOrDefault(CLUSTER_PROPERTY, DEFAULT_CLUSTER);
this.fileIOCloser = newFileIOCloser();
}

protected FileIO loadFileIO(Map<String, String> properties) {
Expand Down Expand Up @@ -235,13 +242,17 @@ public void renameTable(TableIdentifier from, TableIdentifier to) {

@Override
public TableOperations newTableOps(TableIdentifier tableIdentifier) {
return OpenHouseTableOperations.builder()
.tableIdentifier(tableIdentifier)
.fileIO(fileIO)
.tableApi(tableApi)
.snapshotApi(snapshotApi)
.cluster(cluster)
.build();
FileIO tableOperationsLocalFileIO = loadFileIO(properties);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also change the signature of loadFileIO to following:

protected FileIO loadFileIO(TableIdentifier tableIdentifier, Map<String, String> properties) {

reason:
Each table can have its own storage, table1 -> hdfs, table2 -> s3, table3 -> adls . We'd need to instantiate/load the right FileIO per table and properties.

TableOperations openHouseTableOperations =
OpenHouseTableOperations.builder()
.tableIdentifier(tableIdentifier)
.fileIO(tableOperationsLocalFileIO)
.tableApi(tableApi)
.snapshotApi(snapshotApi)
.cluster(cluster)
.build();
fileIOCloser.put(openHouseTableOperations, openHouseTableOperations.io());
return openHouseTableOperations;
}

/**
Expand Down Expand Up @@ -592,4 +603,25 @@ private TableMetadata createStagedMetadata() {
return new StaticTableOperations(tableLocation, fileIO).refresh();
}
}

@Override
public void close() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add unit tests to validate this logic?

if (fileIOCloser != null) {
fileIOCloser.invalidateAll();
fileIOCloser.cleanUp();
}
}

private Cache<TableOperations, FileIO> newFileIOCloser() {
return Caffeine.newBuilder()
.weakKeys()
.removalListener(
Copy link
Member

@abhisheknath2011 abhisheknath2011 Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the listener is invoked to perform close?

(RemovalListener<TableOperations, FileIO>)
(ops, fileIO, cause) -> {
if (null != fileIO) {
fileIO.close();
}
})
.build();
}
}