In G-WAN's lock free KV Store, when does the node's memory get freed after a kv_del() call?

StackOverflow https://stackoverflow.com/questions/14040153

  •  12-12-2021
  •  | 
  •  

Question

Let's say in G-WAN server thread we looked up an item in the KV Store and got a valid pointer to a "record" struct. (The KV store is attached to G-WAN's persistent pointer.)

record = (record_t*)kv_get(&records, "akey", sizeof("akey") - 1);

I'm assuming we can safely read the contents of the record structure even if it is marked for deletion in another server thread thanks to the lock free design.

My question is when does the actual deletion take place? Are we guaranteed to have access to "record" until the request finally returns?

Was it helpful?

Solution

A marked-for-deletion KV record is valid until all the HTTP requests that fetched it terminate.

In your case, it means that you MUST attach a copy of this VK record to your persistent pointer ONLY IF this data is used beyond the life of the HTTP requests that made use of the said KV record.

If you are sure that your persistent pointer does not keep references after the HTTP requests finished then you don't need to make a copy of the KV record(s) you use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top