在 Spring Batch 应用程序中使用 BufferWriter 处理回滚 [英] Handling rollback using BufferWriter in Spring Batch Applications

查看:52
本文介绍了在 Spring Batch 应用程序中使用 BufferWriter 处理回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的用例中,我想使用缓冲区编写器来处理字符串的存储.

In my use case, i would like to use a buffer writer to handle the storing of strings.

  • 只有在达到提交间隔时,才会刷新写入

这是为了确保当读取出错时,缓冲区写入器能够处理回滚.

This is to ensure that when there is a error at reading, the buffer writer is able to handle the roll back.

有没有这方面的例子或帮助,因为这是我第一次做 Spring Boot 应用程序.

Are there any examples or help on this, as it is my first time doing spring boot applications.

谢谢!

推荐答案

除非您有事务文件系统,否则您无法回滚磁盘 flush 操作.由于问题的难度,事务性文件系统从未成为主流.微软试图提供一个,但很快就放弃了.还使用了一些 API,例如 Apache commons-Java 世界中的事务,但由于缺少事务文件系统,它们不再维护.

Unless you have a transactional file system, you cannot rollback a disk flush operation. 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.

符合 ACID 的数据库是在常规文件系统之上添加事务语义的方法.SQLite 是使用最广泛的一个,这是 IMO 的一项了不起的工程.您可以看到如何将 SQLite 用作 应用程序文件格式.

ACID compliant databases are the way to go to add transactional semantics on top of regular file systems. SQLite is the most widely used one, which is an amazing piece of engineering IMO. You can see how SQLite can be used as an application file format.

这就是 Spring Batch 不能真正回滚刷新操作的原因,这让我想到了它如何处理回滚的下一点..

That's why Spring Batch cannot really rollback a flush operation, which brings me to the next point of how it handles rollbacks..

我想使用缓冲区编写器来处理字符串的存储.只有在达到提交间隔时,才会刷新写入

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

这已经在 Spring Batch 提供的 FlatFileItemWriter 中实现了,它使用了一个 TransactionawareBufferedWriter 默认情况下.这个缓冲写入器知道当前活动的事务,并在满足块大小时在将项目刷新到磁盘之前缓冲它们.

This is already implemented in the FlatFileItemWriter provided by Spring Batch, which uses a TransactionawareBufferedWriter for that by default. This buffered writer is aware of the currently active transaction, and buffers items before flushing them to disk when the chunk size is met.

在不太可能的情况下,事务回滚 缓冲区被刷新后,作业将被标记为失败,您可以重新启动它.在重新启动时,Spring Batch 会将损坏的文件截断到最后一个已知的好"文件.字节偏移,并重新开始对最后一个失败块的干净写入,然后从那里继续.

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 应用程序中使用 BufferWriter 处理回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆