用例:-
我们正在使用 Spring-data-aerospike 来获取和设置 aerospike 记录。同时,我们有多个 Kafka 消费者试图更新单个记录的不同字段。
问题:- 我们正面临着 Dirt-read 问题的挑战。记录正在被覆盖。
At t-0, Consumer-1 reads the Record-1, with intent to update the Field-name(mobileNumber).
Record-1 looks like something :(custId:1, mobileNumber:1234567890, custType:PERMANENT)
At t-1, Consumer-2 reads the Record-1, with intent to update the Field-2(custType).
At t-3, Consumer-2 commits the Record-1, with updated value for custType.
Record-1 looks like something :(custId:1, mobileNumber:1234567890, custType:PERM_CHANGED_2)
At t-4, Consumer-1 commits the Record-1, with updated value for mobileNumber.
Record-1 looks like something :(custId:1, mobileNumber:9988776655, custType:PERMANENNT)
这里的问题是:Consumer-2 更新的 'custType' 值在 t=4 时丢失了。
这是代码片段的样子:-
@Document(collection = "cust", expiration = 90, expirationUnit = TimeUnit.DAYS)
public class Customer {
@Id
@Field(value = "PK")
private String custId;
@Field(value = "mobileNumber")
private String mobileNumber;
@Field(value = "custType")
private String custType;
}
@Repository
public interface CustomerRepository extends AerospikeRepository<Customer, String> {
// Working.
List<Customer> findById(String primaryKeyId);
}
@Autowired
AerospikeTemplate aerospikeTemplate;
@Transactional(isolation = Isloation.SERIALIZABLE, rollbackFor=Exception.class)
public ResponseDTO<String> updateCustomer(CustomerUpdateRequest custUpdateReqDTO) {
Optional<Customer> cust = customerRepository.findById(custUpdateReqDTO.getCustId());
// Update Business logic by consumers.
aerospikeTemplate.update(cust);
}
这是依赖项的样子:-
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-client</artifactId>
<version>4.1.3</version>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>spring-data-aerospike</artifactId>
<version>${aerospike.data.version}</version>
<scope>system</scope>
<systemPath>${basedir}/lib/spring-data-aerospike-2.0.0.RELEASE.jar</systemPath>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-client</artifactId>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-helper-java</artifactId>
<version>1.2.2</version>
</dependency>
问题 :-
我们知道 spring 事务与 RDBMS 一起工作!在这种情况下让事务性属性在这里工作的方法是什么?
任何帮助或建议将不胜感激!