201
143 using value_vector = pmem::obj::vector;
144 using key_vector = pmem::obj::vector;
145
146 /* values and keys are stored in separate vectors to optimize
147 * snapshotting. If they were stored as a pair in single vector
148 * entire pair would have to be snapshotted in case of value update */
149 value_vector values;
150 key_vector keys;
151
152 simple_kv_runtime
153 get_runtime()
154 {
155
return simple_kv_runtime(this);
156 }
157 };
• Line 67: We define the data types residing in volatile memory. These
are very similar to the types used in the persistent version in “Hash
Table with Transactions.” The only difference is that here we use std
containers instead of pmem::obj.
• Line 72: We declare the volatile buckets array.
• Line 73: We declare the pointer to persistent data (simple_kv_
persistent structure).
• Lines 75-88: In the simple_kv_runtime constructor, we rebuild the
bucket’s array by iterating over keys and values in persistent memory.
In volatile memory, we store both the keys, which are a copy of the
persistent data and the index for the values vector in persistent
memory.
• Lines 90-101: The get() function looks for an element reference in
the volatile buckets array. There is only one reference to persistent
memory when we read the actual value on line 97.
• Lines 113-121: Similar to the get() function, we search for an
element using the volatile data structure and, when found, update
the value in a transaction.
Chapter 11 Designing Data struCtures for persistent MeMory
Précédent

- 225/457

Suivant