配置单元导入失败[java.lang.outofmemoryerror]

smdncfj3  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(397)

我正在使用bash命令将sql数据库导入配置单元客户端节点上的配置单元数据库(使用hortonworks数据平台):

$ hive -f tables.sql

我得到一个错误:

log4j:WARN No such property [maxFileSize] in org.apache.log4j.DailyRollingFileAppender.

Logging initialized using configuration in file:/etc/hive/2.6.1.0-129/0/hive-log4j.properties
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:3332)
    at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:448)
    at java.lang.StringBuilder.append(StringBuilder.java:136)
    at org.apache.hadoop.hive.cli.CliDriver.processReader(CliDriver.java:409)
    at org.apache.hadoop.hive.cli.CliDriver.processFile(CliDriver.java:429)
    at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:718)
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:685)
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:625)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:233)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:148)

我试图将hadoop的heapsize从1gb增加到4GB,但还是出现了错误。有什么想法吗?

atmip9wb

atmip9wb1#

这个 OutOfMemoryError 来自于 CliDriver#processReader(BufferedReader) .

public int processReader(BufferedReader r) throws IOException {
  String line;
  StringBuilder qsb = new StringBuilder();

  while ((line = r.readLine()) != null) {
    // Skipping through comments
    if (! line.startsWith("--")) {
      qsb.append(line + "\n");
    }
  }

  return (processLine(qsb.toString()));
}

它将从文件中读取的所有行添加到 StringBuilder 然后执行它。这一定意味着您指定的输入文件非常大。是否可以将它拆分为多个较小的文件并分别执行,以便减少内存占用?
您提到这是一个sql数据库的导入。apachesqoop可能更适合该用例。

相关问题