Commit 95070bf9 authored by Sergey Vojtovich's avatar Sergey Vojtovich

MVCC simplifications

Simplified away MVCC::get_oldest_view()
Simplified away MVCC::get_view()
Removed unused MVCC::view_release()
parent 90bf5567
......@@ -54,12 +54,6 @@ class MVCC {
@param own_mutex true if caller owns trx_sys_t::mutex */
void view_close(ReadView*& view, bool own_mutex);
/**
Release a view that is inactive but not closed. Caller must own
the trx_sys_t::mutex.
@param view View to release */
void view_release(ReadView*& view);
/** Clones the oldest view and stores it in view. No need to
call view_close(). The caller owns the view that is passed in.
It will also move the closed views from the m_views list to the
......@@ -86,20 +80,6 @@ class MVCC {
Validates a read view list. */
bool validate() const;
/**
Find a free view from the active list, if none found then allocate
a new view. This function will also attempt to move delete marked
views from the active list to the freed list.
@return a view to use */
inline ReadView* get_view();
/**
Get the oldest view in the system. It will also move the delete
marked read views from the views list to the freed list.
@return oldest view if found or NULL */
inline ReadView* get_oldest_view() const;
private:
typedef UT_LIST_BASE_NODE_T(ReadView) view_list_t;
/** Free views ready for reuse. */
......
......@@ -492,62 +492,6 @@ ReadView::complete()
m_closed = false;
}
/**
Find a free view from the active list, if none found then allocate
a new view.
@return a view to use */
ReadView*
MVCC::get_view()
{
ut_ad(mutex_own(&trx_sys.mutex));
ReadView* view;
if (UT_LIST_GET_LEN(m_free) > 0) {
view = UT_LIST_GET_FIRST(m_free);
UT_LIST_REMOVE(m_free, view);
} else {
view = UT_NEW_NOKEY(ReadView());
if (view == NULL) {
ib::error() << "Failed to allocate MVCC view";
}
}
return(view);
}
/**
Release a view that is inactive but not closed. Caller must own
the trx_sys_t::mutex.
@param view View to release */
void
MVCC::view_release(ReadView*& view)
{
ut_ad(!srv_read_only_mode);
ut_ad(mutex_own(&trx_sys.mutex));
uintptr_t p = reinterpret_cast<uintptr_t>(view);
ut_a(p & 0x1);
view = reinterpret_cast<ReadView*>(p & ~1);
ut_ad(view->m_closed);
/** RW transactions should not free their views here. Their views
should freed using view_close() */
ut_ad(view->m_creator_trx_id == 0);
UT_LIST_REMOVE(m_views, view);
UT_LIST_ADD_LAST(m_free, view);
view = NULL;
}
/**
Allocate and create a view.
@param view view owned by this class created for the
......@@ -593,8 +537,11 @@ MVCC::view_open(ReadView*& view, trx_t* trx)
} else {
mutex_enter(&trx_sys.mutex);
view = get_view();
if ((view = UT_LIST_GET_FIRST(m_free))) {
UT_LIST_REMOVE(m_free, view);
} else if (!(view = UT_NEW_NOKEY(ReadView()))) {
ib::error() << "Failed to allocate MVCC view";
}
}
if (view != NULL) {
......@@ -613,29 +560,6 @@ MVCC::view_open(ReadView*& view, trx_t* trx)
mutex_exit(&trx_sys.mutex);
}
/**
Get the oldest (active) view in the system.
@return oldest view if found or NULL */
ReadView*
MVCC::get_oldest_view() const
{
ReadView* view;
ut_ad(mutex_own(&trx_sys.mutex));
for (view = UT_LIST_GET_LAST(m_views);
view != NULL;
view = UT_LIST_GET_PREV(m_view_list, view)) {
if (!view->is_closed()) {
break;
}
}
return(view);
}
/**
Copy state from another view. Must call copy_complete() to finish.
@param other view to copy from */
......@@ -696,18 +620,23 @@ void
MVCC::clone_oldest_view(ReadView* view)
{
mutex_enter(&trx_sys.mutex);
ReadView* oldest_view = get_oldest_view();
if (oldest_view == NULL) {
view->prepare(0);
mutex_exit(&trx_sys.mutex);
view->complete();
} else {
view->copy_prepare(*oldest_view);
mutex_exit(&trx_sys.mutex);
view->copy_complete();
/* Find oldest view. */
for (ReadView *oldest_view = UT_LIST_GET_LAST(m_views);
oldest_view != NULL;
oldest_view = UT_LIST_GET_PREV(m_view_list, oldest_view))
{
if (!oldest_view->is_closed())
{
view->copy_prepare(*oldest_view);
mutex_exit(&trx_sys.mutex);
view->copy_complete();
return;
}
}
/* No views in the list: snapshot current state. */
view->prepare(0);
mutex_exit(&trx_sys.mutex);
view->complete();
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment