Skip to content

Commit

Permalink
Merge pull request #104 from basho/mv-prefetch-race
Browse files Browse the repository at this point in the history
correct prefetch race condition.
  • Loading branch information
Matthew Von-Maszewski committed Mar 13, 2014
2 parents c91408c + 0af027d commit 639f69c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions c_src/eleveldb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// eleveldb: Erlang Wrapper for LevelDB (http://code.google.com/p/leveldb/)
//
// Copyright (c) 2011-2013 Basho Technologies, Inc. All Rights Reserved.
// Copyright (c) 2011-2014 Basho Technologies, Inc. All Rights Reserved.
//
// This file is provided to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file
Expand Down Expand Up @@ -738,7 +738,7 @@ async_iterator_move(
const ERL_NIF_TERM& action_or_target = argv[2];
ERL_NIF_TERM ret_term;

bool submit_new_request(true);
bool submit_new_request(true), prefetch_state;

ReferencePtr<ItrObject> itr_ptr;

Expand Down Expand Up @@ -768,6 +768,11 @@ async_iterator_move(
// debug syslog(LOG_ERR, "move state: %d, %d, %d",
// action, itr_ptr->m_Iter->m_PrefetchStarted, itr_ptr->m_Iter->m_HandoffAtomic);

// must set this BEFORE call to compare_and_swap ... or have potential
// for an "extra" message coming out of prefetch
prefetch_state = itr_ptr->m_Iter->m_PrefetchStarted;
itr_ptr->m_Iter->m_PrefetchStarted = prefetch_state && (eleveldb::MoveTask::PREFETCH_STOP != action );

//
// Three situations:
// #1 not a PREFETCH next call
Expand Down Expand Up @@ -802,7 +807,7 @@ async_iterator_move(
// leave m_HandoffAtomic as 1 so first response is via message

// is this truly a wait for prefetch ... or actually the first prefetch request
if (!itr_ptr->m_Iter->m_PrefetchStarted)
if (!prefetch_state)
{
submit_new_request=true;
itr_ptr->ReleaseReuseMove();
Expand All @@ -814,6 +819,7 @@ async_iterator_move(
submit_new_request=false;
} // else

// redundant ... but clarifying where it really belongs in logic pattern
itr_ptr->m_Iter->m_PrefetchStarted=(eleveldb::MoveTask::PREFETCH_STOP != action );
} // else if

Expand Down
2 changes: 1 addition & 1 deletion test/eleveldb_schema_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ basic_schema_test() ->
["../priv/eleveldb.schema"], [], context(), predefined_schema()),

cuttlefish_unit:assert_config(Config, "eleveldb.data_root", "./data/leveldb"),
cuttlefish_unit:assert_config(Config, "eleveldb.total_leveldb_mem_percent", 80),
cuttlefish_unit:assert_config(Config, "eleveldb.total_leveldb_mem_percent", 70),
cuttlefish_unit:assert_not_configured(Config, "eleveldb.total_leveldb_mem"),
cuttlefish_unit:assert_config(Config, "eleveldb.sync", false),
cuttlefish_unit:assert_config(Config, "eleveldb.limited_developer_mem", false),
Expand Down

0 comments on commit 639f69c

Please sign in to comment.