-
Notifications
You must be signed in to change notification settings - Fork 52
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
import static com.linkedin.openhouse.javaclient.OpenHouseTableOperations.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for fileio per table, we might also need similar changes in OpenHouseInternalCatalog https://github.com/linkedin/openhouse/blob/main/iceberg/openhouse/internalcatalog/src/main/java/com/linkedin/openhouse/internal/catalog/OpenHouseInternalCatalog.java |
||
|
||
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; | ||
|
@@ -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; | ||
|
@@ -68,7 +72,7 @@ | |
*/ | ||
@Slf4j | ||
public class OpenHouseCatalog extends BaseMetastoreCatalog | ||
implements Configurable, SupportsNamespaces, SupportsGrantRevoke { | ||
implements Configurable, SupportsNamespaces, SupportsGrantRevoke, Closeable { | ||
|
||
private TableApi tableApi; | ||
|
||
|
@@ -88,6 +92,8 @@ public class OpenHouseCatalog extends BaseMetastoreCatalog | |
|
||
protected Map<String, String> properties; | ||
|
||
private Cache<TableOperations, FileIO> fileIOCloser; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
|
@@ -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) { | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we also change the signature of loadFileIO to following:
reason: |
||
TableOperations openHouseTableOperations = | ||
OpenHouseTableOperations.builder() | ||
.tableIdentifier(tableIdentifier) | ||
.fileIO(tableOperationsLocalFileIO) | ||
.tableApi(tableApi) | ||
.snapshotApi(snapshotApi) | ||
.cluster(cluster) | ||
.build(); | ||
fileIOCloser.put(openHouseTableOperations, openHouseTableOperations.io()); | ||
return openHouseTableOperations; | ||
} | ||
|
||
/** | ||
|
@@ -592,4 +603,25 @@ private TableMetadata createStagedMetadata() { | |
return new StaticTableOperations(tableLocation, fileIO).refresh(); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
} |
There was a problem hiding this comment.
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: