![](/img/trans.png)
[英]Datastax spark cassandra connector - writing DF to cassandra table
[英]Datastax spark cassandra connector with RetryPolicy to write DF to cassandra table
我正在嘗試用一致性級別“EACH_QUORUM”將火花 Dataframe 寫入 cassandra。 我的代碼如下所示:
val sparkBuilder = SparkSession.builder().
config(cassandraHostPropertyProperty, cassandraHosts).
config(cassandraAuthUsernameProperty, CASSANDRA_AUTH_USER_KEY).
config(cassandraAuthPassProperty, CASSANDRA_AUTH_PASS_KEY).
config(cassandraIsSSLEnabledProperty, isSSLEnabled)...
getOrCreate();
下面是編寫DF的代碼:
df.write.cassandraFormat(tableName, keySpaceName)
.mode(SaveMode.Append)
.options(Map(
WriteConf.ParallelismLevelParam.name -> parallelism_Level.toString,
WriteConf.BatchSizeRowsParam.name -> rowsInBatch.toString
))
.save()
我想添加一個重試策略,以便如果其中一個數據中心停機,則將一致性降級寫入 LOCAL_QUORUM。
我知道 datastax 有一個 class MultipleRetryPolicy.scala我應該擴展它,覆蓋添加自定義邏輯的方法並在 cassandraconf 中使用它的實例
如何將此策略應用於我的 sparksession 或保存操作? scala 中是否還有其他方法可以使用或不使用 RetryPolicy 來滿足我的要求?
你不想要MultipleRetryPolicy
,你在DowngradingConsistencyRetryPolicy之后,它不是 spark 驅動程序的一部分,所以除非你將策略移植到 scala,否則作為驅動程序設置的一部分這樣做是不可行的。
您可以做的是將查詢執行包裝在嘗試中並捕獲UnavailableException
,然后通過更改output.consistency.level 參數以較低的一致性重試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.