原因:error xsdb6:另一个derby示例可能已经启动了数据库

evrscar2  于 2021-05-29  发布在  Hadoop
关注(0)|答案(11)|浏览(820)

我正在尝试运行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)

我看到存在metastore\u db文件夹。。
我的hive metastore包含mysql作为metastore。但是不确定为什么错误显示为derby execption

qqrboqgw

qqrboqgw1#

很难找到另一个线程访问derby metastore\u db的位置,如果能够找到进程,那么可以使用kill命令杀死它。
重启系统的最佳解决方案。

olhwl3o2

olhwl3o22#

如果在windows计算机上启动was应用程序时遇到问题:
使用任务管理器终止java进程
删除 db.lck 文件存在于 WebSphere\AppServer\profiles\AppSrv04\databases\EJBTimers\server1\EJBTimerDB (我的数据库是引起问题的ejbtimerdb)
重新启动应用程序。

xcitsw88

xcitsw883#

我是通过运行 sqlContext._get_hive_ctx() 这是由于最初尝试将流水线rdd加载到Dataframe中时出错 Exception: ("You must build Spark with Hive. Export 'SPARK_HIVE=true' and run build/sbt assembly", Py4JJavaError(u'An error occurred while calling None.org.apache.spark.sql.hive.HiveContext.\n', JavaObject id=o29)) 所以你可以在重建它之前运行它,但仅供参考我看到其他人报告这对他们没有帮助。

t1rydlwq

t1rydlwq4#

这是在我使用pyspark ml word2vec时发生的。我试着加载以前建立的模型。诀窍是,只需使用sqlcontext创建pyspark或scala的空Dataframe。下面是python语法-

from pyspark.sql.types import StructType

schema = StructType([])`
empty = sqlContext.createDataFrame(sc.emptyRDD(), schema)

这是一个解决方法。我的问题用了这个块就解决了。注意-仅当从hivecontext而不是sqlcontext示例化sqlcontext时才会发生。

zz2j4svz

zz2j4svz5#

在另一种情况下,当您试图将动态帧转换为Dataframe时,可以看到相同错误的是aws glue dev端点的spark repl。
实际上有几个不同的例外,如: pyspark.sql.utils.IllegalArgumentException: u"Error while instantiating 'org.apache.spark.sql.hive.HiveSessionState':" ERROR XSDB6: Another instance of Derby may have already booted the database /home/glue/metastore_db. java.sql.SQLException: Failed to start database 'metastore_db' with class loader org.apache.spark.sql.hive.client.IsolatedClientLoader 这个解决方案很难用谷歌找到,但最终会在这里描述。
加载的repl包含一个示例化的 SparkSession 在变量中 spark 你只需要在创建一个新的 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()
nfg76nw0

nfg76nw06#

如果您在sparkshell中运行,那么不应该示例化hivecontext,有一个自动创建的调用 sqlContext (该名称具有误导性-如果使用hive编译spark,它将是一个hivecontext)。请参阅此处的类似讨论。
如果您不是在shell中运行-此异常意味着您在同一jvm中创建了多个hivecontext,这似乎是不可能的-您只能创建一个。

okxuctiv

okxuctiv7#

我在创建表时也遇到了同样的问题。

sqlContext.sql("CREATE TABLE....

我可以看到许多关于 ps -ef | grep spark-shell 所以我杀了他们然后重新开始 spark-shell . 它对我有用。

6gpjuf90

6gpjuf908#

lck(lock)文件是一种访问控制文件,它锁定数据库,以便只有一个用户可以访问或更新数据库。该错误表明有另一个示例正在使用同一个数据库。因此需要删除.lck文件。在主目录中,转到metastore\u db并删除所有.lck文件。

4xrmg8kj

4xrmg8kj9#

我在spark shell上创建Dataframe时遇到了相同的错误:
原因:error xsdb6:derby的另一个示例可能已经启动了数据库/metastore\u db。
原因:
我发现这是因为spark shell的多个其他示例已经在运行并且已经持有derby db,所以当我启动另一个spark shell并使用rdd.todf()在其上创建Dataframe时,它抛出了错误:
解决方案:
我运行ps命令来查找spark shell的其他示例:
ps-ef | grepSpark壳
我用kill命令杀了他们:
kill-9 spark shell processid(示例:kill-9 4848)
在所有的sparkshell示例都消失之后,我启动了一个新的sparkshell并重新运行了我的Dataframe函数,它运行得很好:)

webghufk

webghufk10#

在我的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 plugin中发布我正在清理这个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

<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>
ohtdti5x

ohtdti5x11#

这个错误是因为您试图在同一个节点上运行多个sparkshell,或者由于系统故障,它在没有正确退出sparkshell的情况下被关闭,出于任何原因,您只需找出进程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

相关问题