You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Yoni Gibbs <yo...@hotmail.com> on 2023/01/05 10:41:38 UTC

Sink to database with multiple statements in a transaction, and with retry

I want to sink some data to a database, but the data needs to go into multiple tables, in a single transaction. Am I right in saying that I cannot use the JDBC Connector for this as it only handles single SQL statements?

Assuming that's right, I believe that I need to write a custom sink, so I need to subclass RichSinkFunction​ and in there write code that writes data to the database. I have some classes that do something similar for getting data out of a database, by subclassing RichAsyncFunction​, and there I use the information here<https://nightlies.apache.org/flink/flink-docs-master/docs/dev/datastream/operators/asyncio/#async-io-api> to have a retry, in case the DB connection has a blip. Is there an equivalent for sinks? Or do I need to do this manually myself in some way?

Thanks!

Re: Sink to database with multiple statements in a transaction, and with retry

Posted by Yoni Gibbs <yo...@hotmail.com>.
Also, it seems that sinks have to be synchronous, I think? (Unless there's some async equivalent of SinkFunction​?) Assuming they're synchronous, if I do the retry strategy manually in the implementation of SinkFunction.invoke​ that means I'll be blocking that thread while waiting to do a retry (e.g. with some back-off strategy), I believe. Is that correct?