Spring-data-aerospike | how to achieve rollback in case whole transaction is rolled back

261 views Asked by At

Use Case :-

We are using Spring-data-aerospike to get and save the aerospike record.

Problem :- We are performing SAVE into two different aerospike sets and both of these SAVES should happen in an transactional manner i.e. if 2nd write fails, then the first write should also get rolled back.

Here is code-snippet looks like :-

@Document(collection = "cust", expiration = 90, expirationUnit = TimeUnit.DAYS)
public class Customer {

   @Id
   @Field(value = "PK")
   private String custId;

   @Field(value = "mobileNumber")
   private String mobileNumber;
}


@Document(collection = "custDetails", expiration = 90, expirationUnit = TimeUnit.DAYS)
public class CustomerDetails {

   @Id
   @Field(value = "PK")
   private String custDetailsId;

   @Field(value = "addnDetails")
   private Map additionalDetails;
}




@Repository
public interface CustomerRepository extends AerospikeRepository<Customer, String> {}

@Repository
public interface CustomerDetailsRepository extends AerospikeRepository<CustomerDetails, String>{}



@Autowired
AerospikeTemplate aerospikeTemplate;

This is what we want to achieve, which is not working right now :--

@Transactional(isolation = Isloation.SERIALIZABLE, rollbackFor=Exception.class)
public ResponseDTO<String> updateCustomer(CustomerUpdateRequest custUpdateReqDTO) {
   Optional<Customer> cust = customerRepository.findById(custUpdateReqDTO.getCustId());
   // Update Business logic of Customer Record.
   aerospikeTemplate.update(cust);

   Optional<CustomerDetails> custDet = customerDetailsRepository.findById(custUpdateReqDTO.getCustDetId());
   // Update Business logic of CustomerDetails Record.
   aerospikeTemplate.update(custDet);

}

Here is dependencies looks like :-

<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>

Questions :-

We are aware that spring transactional annotations works with RDBMS !! Whats the way to get the transactional property working here in this scenario ??

Any help or suggestions shall be highly appreciated !

1

There are 1 answers

0
Anastasiia Smirnova On

Aerospike has transaction support for single record only. You will need to perform insert-rollback logic inside your application for multiple records.