summaryrefslogtreecommitdiff
path: root/src/support/hazard.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/support/hazard.c')
-rw-r--r--src/support/hazard.c57
1 files changed, 26 insertions, 31 deletions
diff --git a/src/support/hazard.c b/src/support/hazard.c
index 27508bbdece..b0fa7e129bb 100644
--- a/src/support/hazard.c
+++ b/src/support/hazard.c
@@ -26,7 +26,6 @@ __wt_hazard_set(WT_SESSION_IMPL *session, WT_REF *ref, bool *busyp
WT_BTREE *btree;
WT_CONNECTION_IMPL *conn;
WT_HAZARD *hp;
- WT_PAGE *page;
int restarts = 0;
btree = S2BT(session);
@@ -38,11 +37,11 @@ __wt_hazard_set(WT_SESSION_IMPL *session, WT_REF *ref, bool *busyp
return (0);
/*
- * If there isn't a valid page pointer, we're done. This read can race
- * with eviction and splits, we re-check it after a barrier to make
- * sure we have a valid pointer.
+ * If there isn't a valid page, we're done. This read can race with
+ * eviction and splits, we re-check it after a barrier to make sure
+ * we have a valid reference.
*/
- if (ref->state != WT_REF_MEM || (page = ref->page) == NULL) {
+ if (ref->state != WT_REF_MEM) {
*busyp = true;
return (0);
}
@@ -90,10 +89,10 @@ __wt_hazard_set(WT_SESSION_IMPL *session, WT_REF *ref, bool *busyp
conn->hazard_max));
}
- if (hp->page != NULL)
+ if (hp->ref != NULL)
continue;
- hp->page = page;
+ hp->ref = ref;
#ifdef HAVE_DIAGNOSTIC
hp->file = file;
hp->line = line;
@@ -103,21 +102,17 @@ __wt_hazard_set(WT_SESSION_IMPL *session, WT_REF *ref, bool *busyp
/*
* Check if the page state is still valid, where valid means a
- * state of WT_REF_MEM and the pointer is unchanged. (The
- * pointer can change, it means the page was evicted between
- * the time we set our hazard pointer and the publication. It
- * would theoretically be possible for the page to be evicted
- * and a different page read into the same memory, so the
- * pointer hasn't changed but the contents have. That's OK, we
- * found this page using the tree's key space, whatever page we
- * find here is the page for us to use.)
+ * state of WT_REF_MEM.
*/
if (ref->state == WT_REF_MEM) {
+ ++session->nhazard;
+
+ /*
+ * Callers require a barrier here so operations holding
+ * the hazard pointer see consistent data.
+ */
WT_READ_BARRIER();
- if (ref->page == page) {
- ++session->nhazard;
- return (0);
- }
+ return (0);
}
/*
@@ -130,7 +125,7 @@ __wt_hazard_set(WT_SESSION_IMPL *session, WT_REF *ref, bool *busyp
* We don't bother publishing this update: the worst case is we
* prevent some random page from being evicted.
*/
- hp->page = NULL;
+ hp->ref = NULL;
*busyp = true;
return (0);
}
@@ -147,7 +142,7 @@ __wt_hazard_set(WT_SESSION_IMPL *session, WT_REF *ref, bool *busyp
* Clear a hazard pointer.
*/
int
-__wt_hazard_clear(WT_SESSION_IMPL *session, WT_PAGE *page)
+__wt_hazard_clear(WT_SESSION_IMPL *session, WT_REF *ref)
{
WT_BTREE *btree;
WT_HAZARD *hp;
@@ -165,7 +160,7 @@ __wt_hazard_clear(WT_SESSION_IMPL *session, WT_PAGE *page)
for (hp = session->hazard + session->hazard_size - 1;
hp >= session->hazard;
--hp)
- if (hp->page == page) {
+ if (hp->ref == ref) {
/*
* We don't publish the hazard pointer clear in the
* general case. It's not required for correctness;
@@ -174,7 +169,7 @@ __wt_hazard_clear(WT_SESSION_IMPL *session, WT_PAGE *page)
* generation number was just set, it's unlikely the
* page will be selected for eviction.
*/
- hp->page = NULL;
+ hp->ref = NULL;
/*
* If this was the last hazard pointer in the session,
@@ -191,7 +186,7 @@ __wt_hazard_clear(WT_SESSION_IMPL *session, WT_PAGE *page)
*/
WT_PANIC_RET(session, EINVAL,
"session %p: clear hazard pointer: %p: not found",
- (void *)session, (void *)page);
+ (void *)session, (void *)ref);
}
/*
@@ -211,7 +206,7 @@ __wt_hazard_close(WT_SESSION_IMPL *session)
*/
for (found = false, hp = session->hazard;
hp < session->hazard + session->hazard_size; ++hp)
- if (hp->page != NULL) {
+ if (hp->ref != NULL) {
found = true;
break;
}
@@ -239,8 +234,8 @@ __wt_hazard_close(WT_SESSION_IMPL *session)
*/
for (hp = session->hazard;
hp < session->hazard + session->hazard_size; ++hp)
- if (hp->page != NULL) {
- hp->page = NULL;
+ if (hp->ref != NULL) {
+ hp->ref = NULL;
--session->nhazard;
}
@@ -256,7 +251,7 @@ __wt_hazard_close(WT_SESSION_IMPL *session)
* Count how many hazard pointers this session has on the given page.
*/
u_int
-__wt_hazard_count(WT_SESSION_IMPL *session, WT_PAGE *page)
+__wt_hazard_count(WT_SESSION_IMPL *session, WT_REF *ref)
{
WT_HAZARD *hp;
u_int count;
@@ -264,7 +259,7 @@ __wt_hazard_count(WT_SESSION_IMPL *session, WT_PAGE *page)
for (count = 0, hp = session->hazard + session->hazard_size - 1;
hp >= session->hazard;
--hp)
- if (hp->page == page)
+ if (hp->ref == ref)
++count;
return (count);
@@ -282,10 +277,10 @@ __hazard_dump(WT_SESSION_IMPL *session)
for (hp = session->hazard;
hp < session->hazard + session->hazard_size; ++hp)
- if (hp->page != NULL)
+ if (hp->ref != NULL)
__wt_errx(session,
"session %p: hazard pointer %p: %s, line %d",
(void *)session,
- (void *)hp->page, hp->file, hp->line);
+ (void *)hp->ref, hp->file, hp->line);
}
#endif