Spring repository save to the disk storage


#1

Hi All,
I encounter 2 methods from CouchbasePagingAndSortingRepository to save as below.

  • save(object)

  • repository.getCouchbaseOperations().save(object,PersistTo pto,ReplicaTo rto)

This means if we simply perform save it does neither persist nor replica.It only writes object to the memory of primary node.
If we want to ensure object to persist to at least to the primary node we should use
repository.getCouchbaseOperations().save(object,PersistTo pto,ReplicaTo rto) with persistto parameter?

Please clarify the above

Thanks
Isuru


#2

@iisuru to be clear: the server will always persist and replicate in the background, even if you use save(object). the other overload allows the client to assert that the replication and/or persistence happened (so it polls the server for its state internally). So your data is “safe” both ways, its just one moves on quickly, the other allows you to assert a certain state before moving on.


#3

So save(obj) will simply put the object into the memory of couchbase cluster and return.Does it put the object to memory of multiple nodes or simply only to the leader node’s memory and return?
So if it is put only to only leaders node memory there is a possibility of complete data loss upon leader node crash.Please calrify

other overload gurantees that object is written to the disk of persist and replica nodes before return to user.


#4

So save(obj) will simply put the object into the memory of couchbase cluster and return. Does it put the object to memory of multiple nodes or simply only to the leader node’s memory and return?

save(obj) waits for the document to be written to memory in one place (the node hosting the active partition… the “leader” if you like). As daschl mentioned, Couchbase will still write the document to disk and replicate it, but you will not receive confirmation when the persistence and replication are complete.

So if it is put only to only leaders node memory there is a possibility of complete data loss upon leader node crash.

Correct. If the Couchbase node hosting the active partition fails before the document is written to disk or replicated to another node, the document is lost.

other overload guarantees that object is written to the disk of persist and replica nodes before return to user.

Right. ReplicateTo lets you wait for confirmation that the document is in memory on the specified number of replicas. PersistTo lets you wait for confirmation that the document has been written to disk on the specified number of nodes. The overloaded method lets you control whether to wait for replication, persistence, or both.

Sandhya Krishnamurthy wrote an interesting blog post on the subject: Choosing the right fit – Immediate or Eventual Persistence?


#5

Thanks David for the succinct explanation