You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2022/05/30 07:24:04 UTC

[GitHub] [hudi] minihippo commented on a diff in pull request #5064: [HUDI-3654] Initialize hudi metastore module.

minihippo commented on code in PR #5064:
URL: https://github.com/apache/hudi/pull/5064#discussion_r884500396


##########
hudi-metastore/src/main/java/org/apache/hudi/common/table/HoodieTableMetastoreClient.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.hudi.common.table;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hudi.common.config.HoodieMetastoreConfig;
+import org.apache.hudi.common.fs.ConsistencyGuardConfig;
+import org.apache.hudi.common.fs.FileSystemRetryConfig;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.metastore.client.HoodieMetastoreClient;
+import org.apache.hudi.metastore.client.RetryingHoodieMetastoreClient;
+import org.apache.hudi.metastore.thrift.NoSuchObjectException;
+import org.apache.hudi.metastore.thrift.Table;
+import org.apache.hudi.common.table.timeline.HoodieMetastoreBasedTimeline;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.List;
+import java.util.Set;
+
+public class HoodieTableMetastoreClient extends HoodieTableMetaClient {
+  private static final Logger LOG = LogManager.getLogger(HoodieTableMetastoreClient.class);
+
+  private String databaseName;
+  private String tableName;
+  private Table table;
+  private HoodieMetastoreClient metastoreClient;
+
+  public HoodieTableMetastoreClient(Configuration conf, ConsistencyGuardConfig consistencyGuardConfig, FileSystemRetryConfig fileSystemRetryConfig,
+      String databaseName, String tableName, HoodieMetastoreConfig config) {
+    super(conf, config.getString(HoodieWriteConfig.BASE_PATH), false, consistencyGuardConfig, Option.of(TimelineLayoutVersion.CURR_LAYOUT_VERSION),
+        config.getString(HoodieTableConfig.PAYLOAD_CLASS_NAME), fileSystemRetryConfig);
+    if (databaseName == null || tableName == null) {
+      throw new HoodieException("The database and table name have to be specified");
+    }
+    this.databaseName = databaseName;
+    this.tableName = tableName;
+    this.metastoreConfig = config;
+    this.metastoreClient = RetryingHoodieMetastoreClient.getProxy(config);
+    this.table = initOrGetTable(databaseName, tableName, config);
+    // TODO: transfer table parameters to table config
+    this.tableConfig = new HoodieTableConfig();
+    tableConfig.setTableVersion(HoodieTableVersion.THREE);
+    tableConfig.setAll(config.getProps());
+  }
+
+  private Table initOrGetTable(String db, String tb, HoodieMetastoreConfig config) {
+    Table table;
+    try {
+      table = metastoreClient.getTable(databaseName, tableName);
+    } catch (HoodieException e) {
+      if (e.getCause() instanceof NoSuchObjectException) {
+        LOG.info(String.format("Table %s.%s doesn't exist, will create it.", db, tb));
+        table = new Table();
+        table.setDbName(db);
+        table.setTableName(tb);
+        table.setLocation(config.getString(HoodieWriteConfig.BASE_PATH));
+        table.setOwner("");

Review Comment:
   Cloud u explain it?



##########
hudi-metastore/src/main/java/org/apache/hudi/common/table/HoodieTableMetastoreClient.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.hudi.common.table;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hudi.common.config.HoodieMetastoreConfig;
+import org.apache.hudi.common.fs.ConsistencyGuardConfig;
+import org.apache.hudi.common.fs.FileSystemRetryConfig;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.metastore.client.HoodieMetastoreClient;
+import org.apache.hudi.metastore.client.RetryingHoodieMetastoreClient;
+import org.apache.hudi.metastore.thrift.NoSuchObjectException;
+import org.apache.hudi.metastore.thrift.Table;
+import org.apache.hudi.common.table.timeline.HoodieMetastoreBasedTimeline;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.List;
+import java.util.Set;
+
+public class HoodieTableMetastoreClient extends HoodieTableMetaClient {
+  private static final Logger LOG = LogManager.getLogger(HoodieTableMetastoreClient.class);
+
+  private String databaseName;
+  private String tableName;
+  private Table table;
+  private HoodieMetastoreClient metastoreClient;
+
+  public HoodieTableMetastoreClient(Configuration conf, ConsistencyGuardConfig consistencyGuardConfig, FileSystemRetryConfig fileSystemRetryConfig,
+      String databaseName, String tableName, HoodieMetastoreConfig config) {
+    super(conf, config.getString(HoodieWriteConfig.BASE_PATH), false, consistencyGuardConfig, Option.of(TimelineLayoutVersion.CURR_LAYOUT_VERSION),
+        config.getString(HoodieTableConfig.PAYLOAD_CLASS_NAME), fileSystemRetryConfig);
+    if (databaseName == null || tableName == null) {
+      throw new HoodieException("The database and table name have to be specified");
+    }
+    this.databaseName = databaseName;
+    this.tableName = tableName;
+    this.metastoreConfig = config;
+    this.metastoreClient = RetryingHoodieMetastoreClient.getProxy(config);
+    this.table = initOrGetTable(databaseName, tableName, config);
+    // TODO: transfer table parameters to table config
+    this.tableConfig = new HoodieTableConfig();
+    tableConfig.setTableVersion(HoodieTableVersion.THREE);
+    tableConfig.setAll(config.getProps());
+  }
+
+  private Table initOrGetTable(String db, String tb, HoodieMetastoreConfig config) {
+    Table table;
+    try {
+      table = metastoreClient.getTable(databaseName, tableName);
+    } catch (HoodieException e) {
+      if (e.getCause() instanceof NoSuchObjectException) {
+        LOG.info(String.format("Table %s.%s doesn't exist, will create it.", db, tb));
+        table = new Table();
+        table.setDbName(db);
+        table.setTableName(tb);
+        table.setLocation(config.getString(HoodieWriteConfig.BASE_PATH));
+        table.setOwner("");
+        table.setTableType(config.getString(HoodieTableConfig.TYPE.key()));
+        metastoreClient.createTable(table);
+        table = metastoreClient.getTable(databaseName, tableName);
+      } else {
+        throw e;
+      }
+    }
+    return table;
+  }
+
+  /**
+   * @return Hoodie Table Type
+   */
+  public HoodieTableType getTableType() {
+    return HoodieTableType.valueOf(table.getTableType());
+  }
+
+  /**
+   * Get the active instants as a timeline.
+   *
+   * @return Active instants timeline
+   */
+  public synchronized HoodieActiveTimeline getActiveTimeline() {
+    if (activeTimeline == null) {
+      activeTimeline = new HoodieMetastoreBasedTimeline(this, metastoreConfig);
+    }
+    return activeTimeline;
+  }
+
+  /**
+   * Reload ActiveTimeline and cache.
+   *

Review Comment:
   will delete



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org