无法从 Spark 应用程序连接到 Hive Metastore

Cannot connect to Hive metastore from Spark application

我正在尝试从 Spark 应用程序连接到 Hive-metastore,但每次它在尝试连接时卡住并因超时而崩溃:

INFO  metastore:376 - Trying to connect to metastore with URI thrift://hive-metastore:9083
WARN  metastore:444 - set_ugi() not successful, Likely cause: new client talking to old server. Continuing without it.
org.apache.thrift.transport.TTransportException: java.net.SocketTimeoutException: Read timed out

应用程序在我创建外部 Hive 的那一行崩溃了table

I 运行 Hive-metastore 以及 Kubernetes 集群中的 Spark 应用程序(使用 Spark K8s operator)。我使用telnet(节点ip:服务节点端口)检查了集群外部的Hive-metastore服务的可访问性,并在集群内部卷曲了该服务,该服务似乎是可评估的。这个错误的原因可能是什么?

这是Spark应用中Hive-metastore uri的配置

val sparkSession = SparkSession
  .builder()
  .config(sparkConf)
  .config("hive.metastore.uris", "thrift://hive-metastore:9083")
  .config("hive.exec.dynamic.partition", "true")
  .config("hive.exec.dynamic.partition.mode", "nonstrict")
  .enableHiveSupport()
  .getOrCreate()

Hive-metastore yaml 配置如下所示:

apiVersion: v1
kind: Service
metadata:
  name: hive-metastore-np
spec:
  selector:
    app: hive-metastore
  ports:
    - protocol: TCP
      targetPort: 9083
      port: 9083
      nodePort: 32083
  type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hive-metastore
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hive-metastore
  template:
    metadata:
      labels:
        app: hive-metastore
    spec:
      containers:
        - name: hive-metastore
          image: mozdata/docker-hive-metastore:1.2.1
          imagePullPolicy: Always
          env:
            - name: DB_URI
              value: postgresql
            - name: DB_USER
              value: hive
            - name: DB_PASSWORD
              value: hive-password
            - name: CORE_CONF_fs_defaultFS
              value: hdfs://hdfs-namenode:8020
          ports:
            - containerPort: 9083

更新:当我尝试 curl hive-metastore:9083 时,该服务可以访问,但它 returns 一个空响应,这意味着 hive-metastore K8s 定义可能存在问题

> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: hive-metastore:9083
> Accept: */*

当集群中的 Hive jar 版本与 Spark 使用的 Hive jar 版本(通常与您使用的 Spark 版本一致)之间存在差异时,会发生此错误。您需要确定集群中使用的 Hive jar 的版本,并将这些 jar 添加到您的 Spark 映像中。然后,您可以通过将以下配置添加到您的 SparkSession,使您的 SparkSession 使用这些兼容的配置单元罐:

  .conf("spark.sql.hive.metastore.version", "<your hive metastore version>")
  .conf("spark.sql.hive.metastore.version", "<your hive version>")
  .conf("spark.sql.hive.metastore.jars", "<uri of all the correct hive jars>")