![](/img/trans.png)
[英]Accessing per-key state store in Apache Flink that changes dynamically
[英]Setting up and accessing Flink Queryable State (NullPointerException)
我正在使用Flink v1.4.0
,我已經設置了兩個不同的工作。 第一個是使用來自Kafka主題的數據並將它們存儲到可查詢狀態(QS)的管道。 數據按日期鍵入。 第二個向QS作業提交查詢並處理返回的數據。
這兩項工作在Flink v.1.3.2
都運行良好。 但隨着新的更新,一切都破裂了。 這是第一份工作的代碼的一部分:
private void runPipeline() throws Exception {
StreamExecutionEnvironment env = configurationEnvironment();
QueryableStateStream<String, DataBucket> dataByDate = env.addSource(sourceDataFromKafka())
.map(NewDataClass::new)
.keyBy(data.date)
.asQueryableState("QSName", reduceIntoSingleDataBucket());
}
這是客戶端的代碼:
QueryableStateClient client = new QueryableStateClient("localhost", 6123);
// the state descriptor of the state to be fetched.
ValueStateDescriptor<DataBucket> descriptor = new ValueStateDescriptor<>(
"QSName",
TypeInformation.of(new TypeHint<DataBucket>() {}));
jobId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String key = "2017-01-06";
CompletableFuture<ValueState<DataBucket> resultFuture = client.getKvState(
jobId,
"QSName",
key,
BasicTypeInfo.STRING_TYPE_INFO,
descriptor);
try {
ValueState<DataBucket> valueState = resultFuture.get();
DataBucket bucket = valueState.value();
System.out.println(bucket.getLabel());
} catch (IOException | InterruptionException | ExecutionException e) {
throw new RunTimeException("Unable to query bucket key: " + key , e);
}
我按照以下鏈接按照說明操作: https : //ci.apache.org/projects/flink/flink-docs-release-1.4/dev/stream/state/queryable_state.html
通過將flink-queryable-state-runtime_2.11-1.4.0.jar
的opt/
文件夾中的flink-queryable-state-runtime_2.11-1.4.0.jar
包含到lib/
文件夾並確認它在任務中運行,確保在我的Flink集群上啟用可查詢狀態經理。
我一直收到以下錯誤:
Exception in thread "main" java.lang.NullPointerException
at org.apache.flink.api.java.typeutils.GenericTypeInfo.createSerializer(GenericTypeInfo.java:84)
at org.apache.flink.api.common.state.StateDescriptor.initializeSerializerUnlessSet(StateDescriptor.java:253)
at org.apache.flink.queryablestate.client.QueryableStateClient.getKvState(QueryableStateClient.java:210)
at org.apache.flink.queryablestate.client.QueryableStateClient.getKvState(QueryableStateClient.java:174)
at com.company.dept.query.QuerySubmitter.main(QuerySubmitter.java:37)
知道發生了什么事嗎? 我認為我的要求根本沒有達到QS ......真的不知道我是否以及如何改變任何東西。 謝謝。
因此,事實證明,導致此錯誤的是兩件事。 第一個是使用錯誤的構造函數在客戶端創建descriptor
。 我不得不使用僅作為輸入QS和TypeHint的名稱的那個,而是使用另一個,其中keySerialiser
和默認值如下所示:
ValueStateDescriptor<DataBucket> descriptor = new ValueStateDescriptor<>(
"QSName",
TypeInformation.of(new TypeHint<DataBucket>() {}).createSerializer(new ExecutionConfig()),
DataBucket.emptyBucket()); // or anything that can be used as a default value
第二個與主機和端口值相關。 端口與v1.3.2
現在設置為9069不同,localhost在我的情況下也不同。 您可以通過檢查該行的任何任務管理器的日志來驗證這兩者: Started the Queryable State Proxy Server @ ...
最后,如果您在這里是因為您希望允許端口范圍用於可查詢的狀態客戶端代理,我建議您按照相應的問題(FLINK-7788)進行操作: https ://issues.apache.org/jira/browse/ FLINK-7788 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.