Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxiaojian committed Mar 28, 2024
1 parent 4e814ca commit 425c91c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

package org.apache.paimon.catalog;

import org.apache.paimon.client.ClientPool;
import org.apache.paimon.factories.Factory;
import org.apache.paimon.options.Options;

import java.io.Serializable;

/** Context for lock context factory to create lock. */
public interface CatalogLockContextFactory<CP extends ClientPool.ClientPoolImpl>
extends Factory, Serializable {
public interface CatalogLockContextFactory extends Factory, Serializable {
CatalogLockContext createLockContext(Options lockOptions, boolean closeConnectionsUsed);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.paimon.schema.SchemaManager;
import org.apache.paimon.schema.TableSchema;
import org.apache.paimon.utils.Preconditions;
import org.apache.paimon.utils.StringUtils;

import org.apache.paimon.shade.guava30.com.google.common.collect.ImmutableMap;
import org.apache.paimon.shade.guava30.com.google.common.collect.Lists;
Expand Down Expand Up @@ -351,8 +352,8 @@ public Optional<CatalogLockFactory> defaultLockFactory() {

@Override
public Optional<CatalogLockContext> lockContext() {
String lock = catalogOptions.get(LOCK_TYPE);
if (lock == null || lock.equals("jdbc")) {
String lock = catalogOptions.get(LOCK_TYPE).toLowerCase();
if (StringUtils.isBlank(lock) || lock.equals(JdbcCatalogLockFactory.IDENTIFIER)) {
return Optional.of(new JdbcCatalogLockContext(connections, options, false));
} else {
return lockContextFactory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.paimon.options.Options;

/** Factory for jdbc catalog lock context. */
public class JdbcCatalogLockContextFactory implements CatalogLockContextFactory<JdbcClientPool> {
public class JdbcCatalogLockContextFactory implements CatalogLockContextFactory {

@Override
public String identifier() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,14 +689,17 @@ public static Catalog createHiveCatalog(CatalogContext context) {
}

public static HiveConf createHiveConf(CatalogContext context) {
String uri = context.options().get(CatalogOptions.URI);
String hiveConfDir = context.options().get(HIVE_CONF_DIR);
String hadoopConfDir = context.options().get(HADOOP_CONF_DIR);
HiveConf hiveConf =
HiveCatalog.createHiveConf(hiveConfDir, hadoopConfDir, context.hadoopConf());
return createHiveConf(context.options(), context.hadoopConf());
}

public static HiveConf createHiveConf(Options options, Configuration hadoopConf) {
String uri = options.get(CatalogOptions.URI);
String hiveConfDir = options.get(HIVE_CONF_DIR);
String hadoopConfDir = options.get(HADOOP_CONF_DIR);
HiveConf hiveConf = HiveCatalog.createHiveConf(hiveConfDir, hadoopConfDir, hadoopConf);

// always using user-set parameters overwrite hive-site.xml parameters
context.options().toMap().forEach(hiveConf::set);
options.toMap().forEach(hiveConf::set);
if (uri != null) {
hiveConf.set(HiveConf.ConfVars.METASTOREURIS.varname, uri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.paimon.catalog.CatalogLockContext;
import org.apache.paimon.options.Options;
import org.apache.paimon.utils.HadoopUtils;

/** Hive {@link CatalogLockContext}. */
public class HiveCatalogLockContext implements CatalogLockContext {
Expand All @@ -28,6 +29,15 @@ public class HiveCatalogLockContext implements CatalogLockContext {
private final String clientClassName;
private final Options options;

public HiveCatalogLockContext(Options options) {
this.hiveConf =
new SerializableHiveConf(
HiveCatalog.createHiveConf(
options, HadoopUtils.getHadoopConfiguration(options)));
this.clientClassName = options.get(HiveCatalogFactory.METASTORE_CLIENT_CLASS);
this.options = options;
}

public HiveCatalogLockContext(
SerializableHiveConf hiveConf, String clientClassName, Options options) {
this.hiveConf = hiveConf;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.hive;

import org.apache.paimon.catalog.CatalogLockContext;
import org.apache.paimon.catalog.CatalogLockContextFactory;
import org.apache.paimon.options.Options;

/** Hive {@link CatalogLockContextFactory}. */
public class HiveCatalogLockContextFactory implements CatalogLockContextFactory {
@Override
public String identifier() {
return HiveCatalogLock.LOCK_IDENTIFIER;
}

@Override
public CatalogLockContext createLockContext(Options lockOptions, boolean closeConnectionsUsed) {
return new HiveCatalogLockContext(lockOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@

org.apache.paimon.hive.HiveCatalogFactory
org.apache.paimon.hive.HiveCatalogLockFactory
org.apache.paimon.hive.HiveCatalogLockContextFactory

0 comments on commit 425c91c

Please sign in to comment.