Skip to content
Snippets Groups Projects
Commit 399d0026 authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Vladimir Davydov
Browse files

memtx: rename MemtxAllocator::snapshot_version to read_view_version

Because we will use this version for user read views, not just
snapshots. Comments are updated as well.

NO_DOC=refactoring
NO_TEST=refactoring
NO_CHANGELOG=refactoring
parent 08070d45
No related branches found
No related tags found
No related merge requests found
......@@ -40,14 +40,17 @@
*/
struct memtx_tuple {
/*
* sic: the header of the tuple is used
* to store a free list pointer in smfree_delayed.
* Please don't change it without understanding
* how smfree_delayed and snapshotting COW works.
* Sic: The header of the tuple is used to store a link in
* a tuple garbage collection list. Please don't change it
* without understanding how tuple garbage collection and
* copy-on-write mechanisms work.
*/
union {
struct {
/** Snapshot generation version. */
/**
* Most recent read view's version at the time
* when the tuple was allocated.
*/
uint32_t version;
/** Base tuple class. */
struct tuple base;
......@@ -93,7 +96,7 @@ class MemtxAllocator {
static ReadView *open_read_view(struct memtx_read_view_opts opts)
{
(void)opts;
snapshot_version++;
read_view_version++;
delayed_free_mode++;
return nullptr;
}
......@@ -119,23 +122,23 @@ class MemtxAllocator {
(struct memtx_tuple *)alloc(total);
if (memtx_tuple == NULL)
return NULL;
memtx_tuple->version = snapshot_version;
memtx_tuple->version = read_view_version;
return &memtx_tuple->base;
}
/**
* Free a tuple allocated with alloc_tuple().
*
* The tuple is freed immediately if there's no snapshot that may use
* The tuple is freed immediately if there's no read view that may use
* it. Otherwise, it's put in the garbage collection list to be free as
* soon as the last snapshot using it is destroyed.
* soon as the last read view using it is destroyed.
*/
static void free_tuple(struct tuple *tuple)
{
struct memtx_tuple *memtx_tuple = container_of(
tuple, struct memtx_tuple, base);
if (delayed_free_mode == 0 ||
memtx_tuple->version == snapshot_version ||
memtx_tuple->version == read_view_version ||
tuple_has_flag(tuple, TUPLE_IS_TEMPORARY)) {
immediate_free_tuple(memtx_tuple);
} else {
......@@ -182,7 +185,7 @@ class MemtxAllocator {
/**
* Tuple garbage collection list. Contains tuples that were not freed
* immediately because they are currently in use by a snapshot.
* immediately because they are currently in use by a read view.
*/
static struct stailq gc;
/**
......@@ -190,8 +193,12 @@ class MemtxAllocator {
* open_read_view() is delayed until close_read_view() is called.
*/
static uint32_t delayed_free_mode;
/** Incremented with each next snapshot. */
static uint32_t snapshot_version;
/**
* Most recent read view's version.
*
* Incremented with each open read view. Not supposed to wrap around.
*/
static uint32_t read_view_version;
};
template<class Allocator>
......@@ -201,7 +208,7 @@ template<class Allocator>
uint32_t MemtxAllocator<Allocator>::delayed_free_mode;
template<class Allocator>
uint32_t MemtxAllocator<Allocator>::snapshot_version;
uint32_t MemtxAllocator<Allocator>::read_view_version;
void
memtx_allocators_init(struct allocator_settings *settings);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment