Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/exception-u…
Browse files Browse the repository at this point in the history
…nification

* origin/master:
  Stop forcing enums to be 64 bits unnecessarily
  clean up documentation of internal fields in config structs
  SyncConfig should be default constructible
  Traversal functions use IteratorControl values rather than true/false which is more expressive (#5857)
  Fix handling of 4-byte UTF8 values on Windows (#5803)
  Encode links in a way the server can understand (#5835)
  expose `Group::remove_table` in the C API (#5860)
  Disable auto refresh for old realm during migration (#5856)
  Expose `list_find` in the c api (#5848)
  Do not allow asymmetric tables in pbs (#5853)
  Refactor link tracing code (#5796)
  Expose `Obj::get_parent_object` in the C API (#5851)
  Update app.hpp (#5854)
  Fix appending to list ignores existing query (#5850)
  • Loading branch information
tgoyne committed Sep 16, 2022
2 parents 87acb34 + 22dc5db commit f51ef63
Show file tree
Hide file tree
Showing 74 changed files with 2,376 additions and 1,580 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
### Enhancements
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* Convert object_store::Collection types into Results (PR [#5845](https://github.com/realm/realm-core/pull/5845))
* Expose `realm_object_get_parent` in the C API (PR [#5851](https://github.com/realm/realm-core/pull/5851))
* Expose `realm_list_find` in the C API (PR [#5848](https://github.com/realm/realm-core/pull/5848))
* Expose `Group::remove_table` in the C API (PR [#5860](https://github.com/realm/realm-core/pull/5860))

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* Prevent migrations to an embedded object type when there are incoming links from Mixed/TypedLink properties until we can support them. ([#5796](https://github.com/realm/realm-core/pull/5796))
* Fix a data race on RealmCoordinator::m_sync_session which could occur if multiple threads performed the initial open of a Realm at once. (since v11.8.0).
* If a SyncSession outlived the parent Realm and then was adopted by a new Realm for the same file, other processes would not get notified for sync writes on that file.
* Fix one cause of QoS inversion warnings when performing writes on the main thread on Apple platforms. Waiting for async notifications to be ready is now done in a QoS-aware ways.
* `Realm::refresh()` did not actually advance to the latest version in some cases. If there was a version newer than the current version which did not require blocking it would advance to that instead, contrary to the documented behavior.
* If you set a subscription on a link in flexible sync, the server would not know how to handle it ([#5409](https://github.com/realm/realm-core/issues/5409))
* Fixed `realm_query_parse_for_results` ignoring query for `query_result_t` passed as parameter ([#5841](https://github.com/realm/realm-core/pull/5841)).
* The C API type `realm_sync_error_code_t` did not include a textural representation of the underlying category. ([#5399](https://github.com/realm/realm-core/issues/5399)),
* Calling Results::sum/min/max on a RealmList field returns its memory address. ([#5137](https://github.com/realm/realm-core/issues/5137))
* Calling Results::sum/min/max on a collection field throws an exception rather than aggregating on the underlying memory addresses. ([#5137](https://github.com/realm/realm-core/issues/5137))
* Fixed `realm_query_parse_for_list` ignoring existing query ([#5850](https://github.com/realm/realm-core/pull/5850)).
* Fixed not allowing asymmetric tables in partition based sync ([#5691](https://github.com/realm/realm-core/issues/5691)).
* Disable auto refresh for old realm instance passed to migration callbacks. ([#5856](https://github.com/realm/realm-core/pull/5856)).
* If a case insensitive query searched for a string including an 4-byte UTF8 character, the program would crash ([#5825](https://github.com/realm/realm-core/issues/5825), since v2.3.0)

### Breaking changes
* All exceptions thrown out of Core are now of type 'Exception'. All use of std::runtime_error and std::logical_error etc. has stopped and the specialized error classes that beforehand were based on these are now based on Exception.
Expand All @@ -23,7 +32,7 @@
-----------

### Internals
* None.
* Traversal functions use a typed IteratorControl value rather than true/false. ([#5857](https://github.com/realm/realm-core/issues/5857))

----------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ let notSyncServerSources: [String] = [
"realm/history.cpp",
"realm/impl",
"realm/index_string.cpp",
"realm/link_translator.cpp",
"realm/list.cpp",
"realm/mixed.cpp",
"realm/node.cpp",
Expand Down Expand Up @@ -119,6 +120,7 @@ let notSyncServerSources: [String] = [
"realm/table_cluster_tree.cpp",
"realm/table_ref.cpp",
"realm/table_view.cpp",
"realm/transaction.cpp",
"realm/unicode.cpp",
"realm/util",
"realm/utilities.cpp",
Expand Down
28 changes: 26 additions & 2 deletions src/realm.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ typedef enum realm_value_type {

typedef enum realm_schema_validation_mode {
RLM_SCHEMA_VALIDATION_BASIC = 0,
RLM_SCHEMA_VALIDATION_SYNC = 1,
RLM_SCHEMA_VALIDATION_REJECT_EMBEDDED_ORPHANS = 2
RLM_SCHEMA_VALIDATION_SYNC_PBS = 1,
RLM_SCHEMA_VALIDATION_REJECT_EMBEDDED_ORPHANS = 2,
RLM_SCHEMA_VALIDATION_SYNC_FLX = 4
} realm_schema_validation_mode_e;

/**
Expand Down Expand Up @@ -1076,6 +1077,14 @@ RLM_API realm_t* realm_freeze(const realm_t*);
*/
RLM_API bool realm_compact(realm_t*, bool* did_compact);

/**
* Find and delete the table passed as parementer for the realm instance passed to this function.
* @param table_name for the table the user wants to delete
* @param table_deleted in order to indicate if the table was actually deleted from realm
* @return true if no error has occured, false otherwise
*/
RLM_API bool realm_remove_table(realm_t*, const char* table_name, bool* table_deleted);

/**
* Create a new schema from classes and their properties.
*
Expand Down Expand Up @@ -1350,6 +1359,12 @@ RLM_API bool realm_get_num_versions(const realm_t*, uint64_t* out_versions_count
*/
RLM_API realm_object_t* realm_get_object(const realm_t*, realm_class_key_t class_key, realm_object_key_t obj_key);

/**
* Get the parent object for the object passed as argument. Only works for embedded objects.
* @return true, if no errors occurred.
*/
RLM_API bool realm_object_get_parent(const realm_object_t* object, realm_object_t* parent);

/**
* Find an object with a particular primary key value.
*
Expand Down Expand Up @@ -1638,6 +1653,15 @@ RLM_API bool realm_list_get_property(const realm_list_t*, realm_property_info_t*
*/
RLM_API bool realm_list_get(const realm_list_t*, size_t index, realm_value_t* out_value);

/**
* Find the value in the list passed as parameter.
* @param value to search in the list
* @param out_index the index in the list where the value has been found or realm::not_found.
* @param out_found boolean that indicates whether the value is found or not
* @return true if no exception occurred.
*/
RLM_API bool realm_list_find(const realm_list_t*, const realm_value_t* value, size_t* out_index, bool* out_found);

/**
* Set the value at @a index.
*
Expand Down
1 change: 1 addition & 0 deletions src/realm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ set(REALM_SOURCES
impl/simulated_failure.cpp
impl/transact_log.cpp
index_string.cpp
link_translator.cpp
list.cpp
node.cpp
mixed.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/realm/bplustree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ size_t BPlusTreeLeaf::bptree_erase(size_t ndx, EraseFunc func)

bool BPlusTreeLeaf::bptree_traverse(TraverseFunc func)
{
return func(this, 0);
return func(this, 0) == IteratorControl::Stop;
}

/****************************** BPlusTreeInner *******************************/
Expand Down Expand Up @@ -465,7 +465,7 @@ bool BPlusTreeInner::bptree_traverse(TraverseFunc func)
bool child_is_leaf = !Array::get_is_inner_bptree_node_from_header(child_header);
if (child_is_leaf) {
auto leaf = cache_leaf(mem, i, child_offset + m_my_offset);
done = func(leaf, child_offset + m_my_offset);
done = (func(leaf, child_offset + m_my_offset) == IteratorControl::Stop);
}
else {
BPlusTreeInner node(m_tree);
Expand Down
18 changes: 9 additions & 9 deletions src/realm/bplustree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class BPlusTreeNode {
// Erase element at erase_pos. May cause nodes to be merged
using EraseFunc = util::FunctionRef<size_t(BPlusTreeNode*, size_t erase_pos)>;
// Function to be called for all leaves in the tree until the function
// returns 'true'. 'offset' gives index of the first element in the leaf.
using TraverseFunc = util::FunctionRef<bool(BPlusTreeNode*, size_t offset)>;
// returns 'IteratorControl::Stop'. 'offset' gives index of the first element in the leaf.
using TraverseFunc = util::FunctionRef<IteratorControl(BPlusTreeNode*, size_t offset)>;

BPlusTreeNode(BPlusTreeBase* tree)
: m_tree(tree)
Expand Down Expand Up @@ -392,7 +392,7 @@ class BPlusTree : public BPlusTreeBase {
for (size_t i = 0; i < sz; i++) {
all_values.push_back(leaf->get(i));
}
return false;
return IteratorControl::AdvanceToNext;
};

m_root->bptree_traverse(func);
Expand Down Expand Up @@ -497,9 +497,9 @@ class BPlusTree : public BPlusTreeBase {
auto i = leaf->find_first(value, 0, sz);
if (i < sz) {
result = i + offset;
return true;
return IteratorControl::Stop;
}
return false;
return IteratorControl::AdvanceToNext;
};

m_root->bptree_traverse(func);
Expand All @@ -516,7 +516,7 @@ class BPlusTree : public BPlusTreeBase {
while ((i = leaf->find_first(value, i + 1, sz)) < sz) {
callback(i + offset);
}
return false;
return IteratorControl::AdvanceToNext;
};

m_root->bptree_traverse(func);
Expand All @@ -532,7 +532,7 @@ class BPlusTree : public BPlusTreeBase {
for (size_t i = 0; i < sz; i++) {
o << indent << leaf->get(i) << std::endl;
}
return false;
return IteratorControl::AdvanceToNext;
};

m_root->bptree_traverse(func);
Expand Down Expand Up @@ -593,7 +593,7 @@ typename SumAggType<T>::ResultType bptree_sum(const BPlusTree<T>& tree, size_t*
auto val = leaf->get(i);
agg.accumulate(val);
}
return false;
return IteratorControl::AdvanceToNext;
};

tree.traverse(func);
Expand Down Expand Up @@ -625,7 +625,7 @@ util::Optional<typename util::RemoveOptional<T>::type> bptree_min_max(const BPlu
*return_ndx = i + offset;
}
}
return false;
return IteratorControl::AdvanceToNext;
};

tree.traverse(func);
Expand Down
31 changes: 15 additions & 16 deletions src/realm/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void Cluster::create()
arr.create();
arr.set_parent(this, col_ndx.val + s_first_col_index);
arr.update_parent();
return false;
return IteratorControl::AdvanceToNext;
}
switch (type) {
case col_type_Int:
Expand Down Expand Up @@ -192,7 +192,7 @@ void Cluster::create()
default:
REALM_UNREACHABLE();
}
return false;
return IteratorControl::AdvanceToNext;
};
m_tree_top.for_each_and_every_column(column_initialize);

Expand Down Expand Up @@ -373,7 +373,7 @@ void Cluster::insert_row(size_t ndx, ObjKey k, const FieldValues& init_values)
arr.set_parent(this, col_ndx.val + s_first_col_index);
arr.init_from_parent();
arr.insert(ndx, 0);
return false;
return IteratorControl::AdvanceToNext;
}

bool nullable = attr.test(col_attr_Nullable);
Expand Down Expand Up @@ -434,7 +434,7 @@ void Cluster::insert_row(size_t ndx, ObjKey k, const FieldValues& init_values)
REALM_ASSERT(false);
break;
}
return false;
return IteratorControl::AdvanceToNext;
};
m_tree_top.for_each_and_every_column(insert_in_column);
}
Expand Down Expand Up @@ -464,7 +464,7 @@ void Cluster::move(size_t ndx, ClusterNode* new_node, int64_t offset)

if (attr.test(col_attr_Collection)) {
do_move<ArrayRef>(ndx, col_key, new_leaf);
return false;
return IteratorControl::AdvanceToNext;
}

switch (type) {
Expand Down Expand Up @@ -523,7 +523,7 @@ void Cluster::move(size_t ndx, ClusterNode* new_node, int64_t offset)
REALM_ASSERT(false);
break;
}
return false;
return IteratorControl::AdvanceToNext;
};
m_tree_top.for_each_and_every_column(move_from_column);
for (size_t i = ndx; i < m_keys.size(); i++) {
Expand Down Expand Up @@ -878,7 +878,7 @@ size_t Cluster::erase(ObjKey key, CascadeState& state)

values.erase(ndx);

return false;
return IteratorControl::AdvanceToNext;
}

switch (col_type) {
Expand Down Expand Up @@ -942,7 +942,7 @@ size_t Cluster::erase(ObjKey key, CascadeState& state)
REALM_ASSERT(false);
break;
}
return false;
return IteratorControl::AdvanceToNext;
};
m_tree_top.for_each_and_every_column(erase_in_column);

Expand Down Expand Up @@ -1003,7 +1003,7 @@ void Cluster::nullify_incoming_links(ObjKey key, CascadeState& state)
values.copy_on_write();
values.nullify_fwd_links(ndx, state);

return false;
return IteratorControl::AdvanceToNext;
};

m_tree_top.get_owning_table()->for_each_backlink_column(nullify_fwd_links);
Expand Down Expand Up @@ -1165,7 +1165,7 @@ void Cluster::verify() const
// FIXME: Nullable primitives
break;
}
return false;
return IteratorControl::AdvanceToNext;
}
else if (attr.test(col_attr_Dictionary)) {
ArrayRef arr(get_alloc());
Expand All @@ -1186,7 +1186,7 @@ void Cluster::verify() const
cluster.verify();
}
}
return false;
return IteratorControl::AdvanceToNext;
}
else if (attr.test(col_attr_Set)) {
ArrayRef arr(get_alloc());
Expand Down Expand Up @@ -1242,7 +1242,7 @@ void Cluster::verify() const
// FIXME: Nullable primitives
break;
}
return false;
return IteratorControl::AdvanceToNext;
}

switch (col_type) {
Expand Down Expand Up @@ -1293,7 +1293,7 @@ void Cluster::verify() const
default:
break;
}
return false;
return IteratorControl::AdvanceToNext;
};

m_tree_top.for_each_and_every_column(verify_column);
Expand Down Expand Up @@ -1339,7 +1339,7 @@ void Cluster::dump_objects(int64_t key_offset, std::string lead) const
}
}
std::cout << "}";
return false;
return IteratorControl::AdvanceToNext;
}

switch (col.get_type()) {
Expand Down Expand Up @@ -1392,7 +1392,6 @@ void Cluster::dump_objects(int64_t key_offset, std::string lead) const
else
std::cout << ", null";
break;
break;
}
case col_type_String: {
ArrayString arr(m_alloc);
Expand Down Expand Up @@ -1477,7 +1476,7 @@ void Cluster::dump_objects(int64_t key_offset, std::string lead) const
std::cout << ", Error";
break;
}
return false;
return IteratorControl::AdvanceToNext;
});
std::cout << std::endl;
}
Expand Down
6 changes: 3 additions & 3 deletions src/realm/cluster_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ bool ClusterNodeInner::traverse(ClusterTree::TraverseFunction func, int64_t key_
if (child_is_leaf) {
Cluster leaf(offs, m_alloc, m_tree_top);
leaf.init(mem);
if (func(&leaf)) {
if (func(&leaf) == IteratorControl::Stop) {
return true;
}
}
Expand Down Expand Up @@ -994,7 +994,7 @@ bool ClusterTree::get_leaf(ObjKey key, ClusterNode::IteratorState& state) const
bool ClusterTree::traverse(TraverseFunction func) const
{
if (m_root->is_leaf()) {
return func(static_cast<Cluster*>(m_root.get()));
return func(static_cast<Cluster*>(m_root.get())) == IteratorControl::Stop;
}
else {
return static_cast<ClusterNodeInner*>(m_root.get())->traverse(func, 0);
Expand All @@ -1016,7 +1016,7 @@ void ClusterTree::verify() const
#ifdef REALM_DEBUG
traverse([](const Cluster* cluster) {
cluster->verify();
return false;
return IteratorControl::AdvanceToNext;
});
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions src/realm/cluster_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class Cluster;
class ClusterTree {
public:
class Iterator;
using TraverseFunction = util::FunctionRef<bool(const Cluster*)>;
using TraverseFunction = util::FunctionRef<IteratorControl(const Cluster*)>;
using UpdateFunction = util::FunctionRef<void(Cluster*)>;
using ColIterateFunction = util::FunctionRef<bool(ColKey)>;
using ColIterateFunction = util::FunctionRef<IteratorControl(ColKey)>;

ClusterTree(Allocator& alloc);
virtual ~ClusterTree();
Expand Down Expand Up @@ -146,7 +146,7 @@ class ClusterTree {
size_t get_ndx(ObjKey k) const noexcept;
// Find the leaf containing the requested object
bool get_leaf(ObjKey key, ClusterNode::IteratorState& state) const noexcept;
// Visit all leaves and call the supplied function. Stop when function returns true.
// Visit all leaves and call the supplied function. Stop when function returns IteratorControl::Stop.
// Not allowed to modify the tree
bool traverse(TraverseFunction func) const;
// Visit all leaves and call the supplied function. The function can modify the leaf.
Expand Down
Loading

0 comments on commit f51ef63

Please sign in to comment.