Skip to content

Commit

Permalink
Merge pull request #1109 from realm/fsa_fix_handover_tests_2
Browse files Browse the repository at this point in the history
fix for critical bug in query handover and minor bug in TableView::re_sort, and improvements to tests
  • Loading branch information
finnschiermer committed Sep 4, 2015
2 parents c8d1673 + 430257b commit 7e6d895
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
* `Expression` subclasses now update `Query`s current descriptor after setting
the table. This prevents a null dereference when adding further conditions
to the query.
* A bug in `Query` copying has been fixed. The bug could cause references to
Tables which should stay under the supervision of one SharedGroup to leak
to another during handover_export() leading to corruption.

### API breaking changes:

Expand Down
5 changes: 1 addition & 4 deletions src/realm/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ Query::Query(const Query& copy, const TCopyExpressionTag&)

void Query::copy_nodes(const Query& source)
{
m_table = source.m_table;
m_view = source.m_view;
m_source_link_view = source.m_source_link_view;

create();

first = source.first;
Expand Down Expand Up @@ -146,6 +142,7 @@ Query& Query::operator = (const Query& source)
m_view = source.m_view;
m_source_link_view = source.m_source_link_view;
m_source_table_view = source.m_source_table_view;

copy_nodes(source);
}
return *this;
Expand Down
2 changes: 1 addition & 1 deletion src/realm/views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void RowIndexes::sort(Sorter& sorting_predicate)
sorting_predicate.init(this);
std::stable_sort(v.begin(), v.end(), sorting_predicate);
m_row_indexes.clear();
for (size_t t = 0; t < sz; t++)
for (size_t t = 0; t < sz - detached_ref_count; t++)
m_row_indexes.add(v[t]);
for (size_t t = 0; t < detached_ref_count; ++t)
m_row_indexes.add(-1);
Expand Down
3 changes: 2 additions & 1 deletion src/realm/views.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class RowIndexes
struct Sorter
{
Sorter(){}
Sorter(std::vector<size_t> columns, std::vector<bool> ascending) : m_column_indexes(columns), m_ascending(ascending) {}
Sorter(const std::vector<size_t>& columns, const std::vector<bool>& ascending)
: m_column_indexes(columns), m_ascending(ascending) {}
bool operator()(size_t i, size_t j) const
{
for (size_t t = 0; t < m_columns.size(); t++) {
Expand Down
9 changes: 7 additions & 2 deletions test/test_lang_bind_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8188,6 +8188,7 @@ void handover_querier(HandoverControl<SharedGroup::Handover<TableView>>* control
// here we need to allow the reciever to get hold on the proper version before
// we go through the loop again and advance_read().
control->wait_feedback();
sched_yield();

if (table->size() > 0 && table->get_int(0,0) == 0)
break;
Expand All @@ -8206,17 +8207,21 @@ void handover_verifier(HandoverControl<SharedGroup::Handover<TableView>>* contro
std::unique_ptr<SharedGroup::Handover<TableView>> handover;
SharedGroup::VersionID version;
control->get(handover, version);
CHECK_EQUAL(version.version, handover->version.version);
CHECK(version == handover->version);
Group& g = const_cast<Group&>(sg.begin_read(version));
CHECK_EQUAL(version.version, sg.get_version_of_current_transaction().version);
CHECK(version == sg.get_version_of_current_transaction());
control->signal_feedback();
TableRef table = g.get_table("table");
TableView tv = table->where().greater(0,50).find_all();
CHECK(tv.is_in_sync());
std::unique_ptr<TableView> tv2 = sg.import_from_handover(move(handover));
CHECK(tv.is_in_sync());
CHECK(tv2->is_in_sync());
CHECK(tv.size() == tv2->size());
CHECK_EQUAL(tv.size(), tv2->size());
for (std::size_t k=0; k<tv.size(); ++k)
CHECK(tv.get_int(0,k) == tv2->get_int(0,k));
CHECK_EQUAL(tv.get_int(0,k), tv2->get_int(0,k));
if (table->size() > 0 && table->get_int(0,0) == 0)
break;
sg.end_read();
Expand Down

0 comments on commit 7e6d895

Please sign in to comment.