-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-29035 : new version of cache #6441
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
base: master
Are you sure you want to change the base?
Changes from all commits
abd759f
19481e6
6713373
ae3fce6
7a9f12b
861404e
81845d6
513b49d
0f1b3aa
788a01f
cec47cf
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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * 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.iceberg.hive; | ||
|
|
||
| import org.apache.hadoop.hive.metastore.IMetaStoreClient; | ||
| import org.apache.hadoop.hive.metastore.api.GetProjectionsSpec; | ||
| import org.apache.hadoop.hive.metastore.api.NoSuchObjectException; | ||
| import org.apache.hadoop.hive.metastore.api.Table; | ||
| import org.apache.hadoop.hive.metastore.client.builder.GetTableProjectionsSpecBuilder; | ||
| import org.apache.iceberg.BaseMetastoreTableOperations; | ||
| import org.apache.iceberg.ClientPool; | ||
| import org.apache.iceberg.MetadataTableType; | ||
| import org.apache.iceberg.catalog.TableIdentifier; | ||
| import org.apache.iceberg.exceptions.NoSuchTableException; | ||
| import org.apache.thrift.TException; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Fetches the location of a given metadata table. | ||
| * <p>Since the location mutates with each transaction, this allows determining if a cached version of the | ||
| * table is the latest known in the HMS database.</p> | ||
| */ | ||
| public class MetadataLocator { | ||
| private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(MetadataLocator.class); | ||
| private static final GetProjectionsSpec PARAM_SPEC = new GetTableProjectionsSpecBuilder() | ||
| .includeParameters() // only fetches table.parameters | ||
| .build(); | ||
| private final HiveCatalog catalog; | ||
|
|
||
| public MetadataLocator(HiveCatalog catalog) { | ||
| this.catalog = catalog; | ||
| } | ||
|
|
||
| public HiveCatalog getCatalog() { | ||
| return catalog; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the location of the metadata table identified by the given identifier, or null if the table is | ||
| * not a metadata table. | ||
| * <p>This uses the Thrift API to fetch the table parameters, which is more efficient than fetching the entire table object.</p> | ||
|
Check warning on line 59 in standalone-metastore/metastore-rest-catalog/src/main/java/org/apache/iceberg/hive/MetadataLocator.java
|
||
| * @param identifier the identifier of the metadata table to fetch the location for | ||
| * @return the location of the metadata table, or null if the table does not exist or is not a metadata table | ||
| * @throws NoSuchTableException if the table does not exist | ||
| */ | ||
| public String getLocation(TableIdentifier identifier) { | ||
| final ClientPool<IMetaStoreClient, TException> clients = catalog.clientPool(); | ||
|
Check failure on line 65 in standalone-metastore/metastore-rest-catalog/src/main/java/org/apache/iceberg/hive/MetadataLocator.java
|
||
| final String catName = catalog.name(); | ||
| final TableIdentifier baseTableIdentifier; | ||
| if (!catalog.isValidIdentifier(identifier)) { | ||
| if (!isValidMetadataIdentifier(identifier)) { | ||
| return null; | ||
| } else { | ||
| baseTableIdentifier = TableIdentifier.of(identifier.namespace().levels()); | ||
| } | ||
| } else { | ||
| baseTableIdentifier = identifier; | ||
| } | ||
| String database = baseTableIdentifier.namespace().level(0); | ||
| String tableName = baseTableIdentifier.name(); | ||
| try { | ||
| List<Table> tables = clients.run( | ||
| client -> client.getTables(catName, database, Collections.singletonList(tableName), PARAM_SPEC) | ||
| ); | ||
| return tables == null || tables.isEmpty() | ||
| ? null | ||
| : tables.getFirst().getParameters().get(BaseMetastoreTableOperations.METADATA_LOCATION_PROP); | ||
|
henrib marked this conversation as resolved.
|
||
| } catch (NoSuchTableException e) { | ||
|
Check warning on line 86 in standalone-metastore/metastore-rest-catalog/src/main/java/org/apache/iceberg/hive/MetadataLocator.java
|
||
| LOGGER.debug("Table {} not found: {}", baseTableIdentifier, e.getMessage()); | ||
| throw e; | ||
| } catch (NoSuchObjectException e) { | ||
| throw new NoSuchTableException("Table %s not found: %s", baseTableIdentifier, e.getMessage()); | ||
| } catch (TException e) { | ||
| LOGGER.info("Table {} parameters fetch failed: {}", baseTableIdentifier, e.getMessage()); | ||
| throw new RuntimeException("Failed to fetch table parameters for " + baseTableIdentifier, e); | ||
|
Check warning on line 93 in standalone-metastore/metastore-rest-catalog/src/main/java/org/apache/iceberg/hive/MetadataLocator.java
|
||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| throw new RuntimeException("Interrupted while fetching table parameters for " + baseTableIdentifier, e); | ||
|
Check warning on line 96 in standalone-metastore/metastore-rest-catalog/src/main/java/org/apache/iceberg/hive/MetadataLocator.java
|
||
| } | ||
| } | ||
|
|
||
| private boolean isValidMetadataIdentifier(TableIdentifier identifier) { | ||
| return MetadataTableType.from(identifier.name()) != null | ||
| && catalog.isValidIdentifier(TableIdentifier.of(identifier.namespace().levels())); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.