Hadoop 原因:错误XSDB6:Derby的另一个实例可能已启动数据库

Hadoop 原因:错误XSDB6:Derby的另一个实例可能已启动数据库,hadoop,apache-spark,derby,Hadoop,Apache Spark,Derby,我正在尝试运行SparkSQL: val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc) 但我得到的错误如下: ... 125 more Caused by: java.sql.SQLException: Another instance of Derby may have already booted the database /root/spark/bin/metastore_db.

我正在尝试运行SparkSQL:

val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc)  
但我得到的错误如下:

        ... 125 more
Caused by: java.sql.SQLException: Another instance of Derby may have already booted the database /root/spark/bin/metastore_db.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
        ... 122 more
Caused by: ERROR XSDB6: Another instance of Derby may have already booted the database /root/spark/bin/metastore_db.
        at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
        at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.privGetJBMSLockOnDB(Unknown Source)
        at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.getJBMSLockOnDB(Unknown Source)
        at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.boot(Unknown Source)
我看到存在一个元存储\u db文件夹。

My hive metastore包含mysql作为metastore。但不确定为什么错误显示为derby Execution

如果您在spark shell中运行,您不应该实例化HiveContext,有一个自动创建的名为
sqlContext
(名称有误导性-如果您使用hive编译spark,它将是HiveContext)。见类似的讨论


如果您没有在shell中运行-此异常意味着您在同一JVM中创建了多个HiveContext,这似乎是不可能的-您只能创建一个。

我通过运行
sqlContext得到此错误。\u get\u hive\u ctx()
这是由于最初试图将流水线RDD加载到数据帧中造成的 我弄错了
Exception:(“您必须使用Hive.Export'Spark\u Hive=true'构建Spark并运行build/sbt assembly”,Py4JJavaError(调用None.org.apache.Spark.sql.Hive.HiveContext时出错。\n',JavaObject id=o29))

因此,您可以在重建它之前运行它,但仅供参考,我看到其他人报告这对他们没有帮助。

在Spark Shell上创建数据帧时,我遇到了相同的错误:

原因:错误XSDB6:另一个Derby实例可能已启动数据库/metastore_db。

原因:

我发现这是因为Spark Shell的多个其他实例已经在运行并持有derby DB,所以当我启动另一个Spark Shell并使用RDD.toDF()在其上创建数据帧时,它抛出了错误:

解决方案:

我运行ps命令查找Spark Shell的其他实例:

ps-ef | grep spark shell

我用kill命令杀了他们:

kill-9火花壳进程ID(示例:kill-9 4848)


在所有SPark Shell实例都消失之后,我启动了一个新的SPark Shell并重新运行了我的数据帧函数,它运行得很好:)

很难找到另一个线程访问derby metastore_db的位置,如果您能够找到该进程,则可以使用kill命令将其杀死


重新启动系统的最佳解决方案。

出现错误的原因是您试图在同一节点中运行多个spark shell,或者由于系统故障,它在没有正确退出spark shell的情况下关闭,出于任何原因,您只需找到进程id并杀死它们,这就是我们的原因

[hadoop@localhost ~]$ ps -ef | grep spark-shell
hadoop    11121   9197  0 17:54 pts/0    00:00:00 grep --color=auto spark-shell
[hadoop@localhost ~]$ kill 9197

如果在windows计算机上启动WAS应用程序时遇到问题:

  • 使用任务管理器杀死java进程
  • 删除
    WebSphere\AppServer\profiles\AppSrv04\databases\EJBTimers\server1\EJBTimerDB
    中存在的
    db.lck
    文件(我的数据库是引起问题的EJBTimerDB)
  • 重新启动应用程序

  • 这是在我使用pyspark ml Word2Vec时发生的。我试图加载以前构建的模型。诀窍是,只需使用sqlContext创建pyspark或scala的空数据帧。以下是python语法-

    from pyspark.sql.types import StructType
    
    schema = StructType([])`
    empty = sqlContext.createDataFrame(sc.emptyRDD(), schema)
    
    这是一个解决办法。使用此块后,我的问题已修复。
    注意-仅当您从HiveContext而不是sqlContext实例化sqlContext时,才会发生这种情况。

    在创建表时,我遇到了相同的问题

    sqlContext.sql("CREATE TABLE....
    

    我可以看到
    ps-ef | grep spark shell的许多条目
    ,所以我杀死了所有条目并重新启动了
    spark shell
    。这对我有用

    当您试图将动态帧转换为数据帧时,您可以看到相同错误的另一种情况是AWS Glue dev端点的Spark REPL

    实际上有几种不同的例外情况,如:

    • pyspark.sql.utils.IllegalArgumentException:u“实例化'org.apache.spark.sql.hive.HiveSessionState'时出错:”
    • 错误XSDB6:Derby的另一个实例可能已经启动了数据库/home/glue/metastore\u db。
    • java.sql.SQLException:无法使用类加载器org.apache.spark.sql.hive.client.IsolatedClient loader启动数据库“metastore\u db”
    谷歌很难找到解决方案,但最终它被描述出来了

    加载的REPL在变量
    spark
    中包含实例化的
    SparkSession
    ,您只需在创建新的
    SparkContext
    之前停止它:

    >>> spark.stop()
    >>> from pyspark.context import SparkContext
    >>> from awsglue.context import GlueContext
    >>>
    >>> glue_context = GlueContext(SparkContext.getOrCreate())
    >>> glue_frame = glue_context.create_dynamic_frame.from_catalog(database=DB_NAME, table_name=T_NAME)
    >>> df = glue_frame.toDF()
    
    lck(锁定)文件是一种访问控制文件,用于锁定数据库,以便只有一个用户可以访问或更新数据库。 该错误表明有另一个实例正在使用相同的数据库。因此,您需要删除.lck文件。
    在主目录中,转到metastore_db并删除所有.lck文件。

    在我的multi-maven spark设置中运行测试用例时,我遇到此错误。 我在测试类中分别创建sparkSession,因为每次通过配置文件传递时,单元测试用例都需要不同的spark参数。 为了解决这个问题,我采用了这种方法。 在Spark 2.2.0中创建sparkSession时

    //This is present in my Parent Trait.
    def createSparkSession(master: String, appName: String, configList: List[(String, String)]): SparkSession ={
        val sparkConf = new SparkConf().setAll(configList)
        val spark = SparkSession
          .builder()
          .master(master)
          .config(sparkConf)
          .enableHiveSupport()
          .appName(appName)
          .getOrCreate()
        spark
      }
    
    在我的测试课上

    //metastore_db_test will test class specific folder in my modules.
    val metaStoreConfig = List(("javax.jdo.option.ConnectionURL", "jdbc:derby:;databaseName=hiveMetaStore/metastore_db_test;create=true"))
        val configList = configContent.convertToListFromConfig(sparkConfigValue) ++ metaStoreConfig
        val spark = createSparkSession("local[*]", "testing", configList)
    
    在maven clean插件中发布,我正在清理这个hiveMetaStore目录

    //Parent POM
    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>3.1.0</version>
                        <configuration>
                            <filesets>
                                <fileset>
                                    <directory>metastore_db</directory>
                                </fileset>
                                <fileset>
                                    <directory>spark-warehouse</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>
    
    //父POM
    org.apache.maven.plugins
    maven清洁插件
    3.1.0
    元存储
    火花仓库
    
    子模块POM

    <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <configuration>
                        <filesets>
                            <fileset>
                                <directory>hiveMetaStore</directory>
                                <includes>
                                    <include>**</include>
                                </includes>
                            </fileset>
                            <fileset>
                                <directory>spark-warehouse</directory>
                            </fileset>
                        </filesets>
                    </configuration>
                </plugin>
    
    
    maven清洁插件
    蜂巢存储