广播 TypeSafe 配置抛出异常用户 class 抛出异常:java.io.UTFDataFormatException:编码字符串太长:70601 字节?
Broadcasting TypeSafe Config throws exception User class threw exception: java.io.UTFDataFormatException: encoded string too long: 70601 bytes?
正如问题标题所说,我正在尝试向执行者广播 TypeSafe 配置,以便我的代码可以访问该配置。不幸的是,我遇到了一个例外
object AppConfigUtility {
var config: Config = ConfigFactory.empty()
var brConfig: Broadcast[Config] = _
/**
* Broadcast the config so it can be available for executors to use
* @param sc
*/
def broadCastConfig(sc: SparkContext): Unit = {
brConfig = sc.broadcast(config)
}
def loadConfig(): Unit = {
//some actual implementation of loading my application.conf file
}
}
当我在我的主要方法中调用 broadCastConfig 时,它抛出以下异常
用户 class 抛出异常:java.io.UTFDataFormatException:编码字符串太长:70601 字节
我的 application.conf 的最终大小仅为 3KB 或 3000 字节,远未达到 64KB 的限制,所以我不是为什么会遇到此错误。
似乎您在 application.conf
中有 长字符串 导致了问题..
用 this :64KB String limit in Java data streams 例子你可以证明。
public static void main(String[] args) throws Exception {
// generate string longer than 64KB
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; i++)
sb.append("1234567890");
String s = sb.toString();
// write the string into the stream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeUTF(s);
dos.close();
}
所面临的相似但不相同的问题已得到修复
我建议解析 application.conf 并将其设置为一个对象,然后使用广播将其发送给所有执行程序。
意味着..您可以发送任何可序列化的对象进行广播...但是采用application.conf
的形式
正如问题标题所说,我正在尝试向执行者广播 TypeSafe 配置,以便我的代码可以访问该配置。不幸的是,我遇到了一个例外
object AppConfigUtility {
var config: Config = ConfigFactory.empty()
var brConfig: Broadcast[Config] = _
/**
* Broadcast the config so it can be available for executors to use
* @param sc
*/
def broadCastConfig(sc: SparkContext): Unit = {
brConfig = sc.broadcast(config)
}
def loadConfig(): Unit = {
//some actual implementation of loading my application.conf file
}
}
当我在我的主要方法中调用 broadCastConfig 时,它抛出以下异常
用户 class 抛出异常:java.io.UTFDataFormatException:编码字符串太长:70601 字节
我的 application.conf 的最终大小仅为 3KB 或 3000 字节,远未达到 64KB 的限制,所以我不是为什么会遇到此错误。
似乎您在 application.conf
中有 长字符串 导致了问题..
用 this :64KB String limit in Java data streams 例子你可以证明。
public static void main(String[] args) throws Exception {
// generate string longer than 64KB
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; i++)
sb.append("1234567890");
String s = sb.toString();
// write the string into the stream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeUTF(s);
dos.close();
}
所面临的相似但不相同的问题已得到修复
我建议解析 application.conf 并将其设置为一个对象,然后使用广播将其发送给所有执行程序。
意味着..您可以发送任何可序列化的对象进行广播...但是采用application.conf
的形式