简体   繁体   English

在 Spring 批处理应用程序中使用 BufferWriter 处理回滚

[英]Handling rollback using BufferWriter in Spring Batch Applications

In my use case, i would like to use a buffer writer to handle the storing of strings.在我的用例中,我想使用缓冲区编写器来处理字符串的存储。

  • Only when the commit interval has been met, it will flush the writes仅当满足提交间隔时,才会刷新写入

This is to ensure that when there is a error at reading, the buffer writer is able to handle the roll back.这是为了确保当读取出现错误时,缓冲区写入器能够处理回滚。

Are there any examples or help on this, as it is my first time doing spring boot applications.是否有任何示例或帮助,因为这是我第一次做 spring 引导应用程序。

Thanks!谢谢!

Unless you have a transactional file system, you cannot rollback a disk flush operation.除非您有事务文件系统,否则您无法回滚磁盘flush操作。 Transactional file systems have never been mainstream because of the difficulty of the problem.由于问题的难度,事务性文件系统从未成为主流。 Microsoft attempted to provide one , but this was abandoned quickly.微软试图提供一个,但很快就被放弃了。 There used be a couple of APIs for that as well, like Apache commons-transaction in the Java world, but those are not maintained anymore due to the lack of transactional file systems.也有一些 API 用于此目的,例如 Java 世界中的Apache commons-transaction ,但由于缺乏事务文件系统,这些 API 不再维护。

ACID compliant databases are the way to go to add transactional semantics on top of regular file systems.符合 ACID 的数据库是 go 在常规文件系统之上添加事务语义的方式。 SQLite is the most widely used one, which is an amazing piece of engineering IMO. SQLite 是使用最广泛的一个,这是 IMO 工程中的一件了不起的作品。 You can see how SQLite can be used as an application file format .您可以看到 SQLite 如何用作应用程序文件格式

That's why Spring Batch cannot really rollback a flush operation, which brings me to the next point of how it handles rollbacks..这就是为什么 Spring Batch 不能真正回滚刷新操作的原因,这让我想到了它如何处理回滚的下一点。

i would like to use a buffer writer to handle the storing of strings.我想使用缓冲区编写器来处理字符串的存储。 Only when the commit interval has been met, it will flush the writes仅当满足提交间隔时,才会刷新写入

This is already implemented in the FlatFileItemWriter provided by Spring Batch, which uses a TransactionawareBufferedWriter for that by default.这已经在 Spring Batch 提供的FlatFileItemWriter中实现,默认情况下它使用TransactionawareBufferedWriter This buffered writer is aware of the currently active transaction, and buffers items before flushing them to disk when the chunk size is met.这个缓冲的写入器知道当前活动的事务,并在满足块大小时缓冲项目,然后将它们刷新到磁盘。

In the unlikely case where the transaction is rolled back after the buffer is flushed, the job will be marked as failed and you can restart it.在缓冲区刷新事务回滚的不太可能的情况下,作业将被标记为失败,您可以重新启动它。 On the restart, Spring Batch will truncate the corrupted file to the last known "good" byte offset, and restart a clean write of the last failed chunk, then continue from there.在重新启动时,Spring Batch 会将损坏的文件截断到最后一个已知的“良好”字节偏移量,并重新开始对最后一个失败的块进行干净写入,然后从那里继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM