Hi Guys,
what you think should be appropriate structure for asynchronous key/value store implementation, basically i want to be able to allow multiple reads/single writer per KEY...
Example below
Operation; Key; Value
GET; counter;
SET; counter; 1
SET; counter; 10
GET; counter;
GET; counter;
SET; counter_xx; 11
GET; counter_u
SET: counter_u; ABC
GET; counter;
So how it should work...
Thread 1 will read counter
Thread 2 will write counter_xx
Thread 3 will read counter_u
---- SYNCHRONIZATION POINT
Thread 1 will write counter = 1
Thread 2 will write counter_u = ABC
---- SYNCHRONIZATION POINT
Thread 1 will write counter = 10
---- SYNCHRONIZATION POINT
Thread 1 will read counter
Thread 2 will read counter
Thread 3 will read counter
... basicall reading and writing of one key cannot occur at the same time...
I have 2 ideas...
1. Implement named RW mutex, so it'll be some pseudo-code like this
if is_writing(operation) {
lock_for_writing(key);
....
unlock_w(key)
} else {
lock_for_reading(key);
....
unlock_r(key)
}
2. Second idea is to start eg. 20 go threads, with 20 channels, and send key to one of the threads, by MODULO of CRC of name... but then reads for hot keys would become single threaded.
Any more go-like concurrency pattern that's appropriate for this case. What you think?
Thanks.