Skip to content

Commit b3039cf

Browse files
committed
Merge branch 'master' into next-major
2 parents 6628c46 + 8f54801 commit b3039cf

File tree

18 files changed

+310
-423
lines changed

18 files changed

+310
-423
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828

2929
### Fixed
3030
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
31-
* None.
31+
* Fix an assertion failure "m_lock_info && m_lock_info->m_file.get_path() == m_filename" that appears to be related to opening a Realm while the file is in the process of being closed on another thread ([Swift #8507](https://github.com/realm/realm-swift/issues/8507)).
32+
* Fixed diverging history due to a bug in the replication code when setting default null values (embedded objects included) ([#7536](https://github.com/realm/realm-core/issues/7536)).
3233

3334
### Breaking changes
34-
* None.
35+
* Updated default base URL to be `https://services.cloud.mongodb.com` to support the new domains (was `https://realm.mongodb.com`). ([PR #7534](https://github.com/realm/realm-core/pull/7534))
3536

3637
### Compatibility
3738
* Fileformat: Generates files with format v24. Reads and automatically upgrade from fileformat v10. If you want to upgrade from an earlier file format version you will have to use RealmCore v13.x.y or earlier.
@@ -41,6 +42,7 @@
4142
### Internals
4243
* Update libuv used in object store tests from v1.35.0 to v1.48.0 ([PR #7508](https://github.com/realm/realm-core/pull/7508)).
4344
* Made `set_default_logger` nullable in the bindgen spec.yml (PR [#7515](https://github.com/realm/realm-core/pull/7515)).
45+
* Added `App::default_base_url()` static accessor for SDKs to retrieve the default base URL from Core. ([PR #7534](https://github.com/realm/realm-core/pull/7534))
4446

4547
----------------------------------------------
4648

src/realm/collection_parent.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ CollectionParent::~CollectionParent() {}
7575

7676
void CollectionParent::check_level() const
7777
{
78-
if (m_level + 1 > s_max_level) {
78+
if (size_t(m_level) + 1 > s_max_level) {
7979
throw LogicError(ErrorCodes::LimitExceeded, "Max nesting level reached");
8080
}
8181
}
8282

8383
template <typename Base, template <typename> typename Collection, typename LinkCol>
84-
std::unique_ptr<Base> create_collection(ColKey col_key, size_t level)
84+
std::unique_ptr<Base> create_collection(ColKey col_key, uint8_t level)
8585
{
8686
bool nullable = col_key.get_attrs().test(col_attr_Nullable);
8787
switch (col_key.get_type()) {
@@ -128,19 +128,19 @@ std::unique_ptr<Base> create_collection(ColKey col_key, size_t level)
128128
}
129129
}
130130

131-
LstBasePtr CollectionParent::get_listbase_ptr(ColKey col_key, size_t level)
131+
LstBasePtr CollectionParent::get_listbase_ptr(ColKey col_key, uint8_t level)
132132
{
133133
REALM_ASSERT(col_key.get_attrs().test(col_attr_List) || col_key.get_type() == col_type_Mixed);
134134
return create_collection<LstBase, Lst, LnkLst>(col_key, level);
135135
}
136136

137-
SetBasePtr CollectionParent::get_setbase_ptr(ColKey col_key, size_t level)
137+
SetBasePtr CollectionParent::get_setbase_ptr(ColKey col_key, uint8_t level)
138138
{
139139
REALM_ASSERT(col_key.get_attrs().test(col_attr_Set));
140140
return create_collection<SetBase, Set, LnkSet>(col_key, level);
141141
}
142142

143-
CollectionBasePtr CollectionParent::get_collection_ptr(ColKey col_key, size_t level)
143+
CollectionBasePtr CollectionParent::get_collection_ptr(ColKey col_key, uint8_t level)
144144
{
145145
if (col_key.is_list()) {
146146
return get_listbase_ptr(col_key, level);

src/realm/collection_parent.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ class CollectionParent : public std::enable_shared_from_this<CollectionParent> {
9999
// a write to mark the already up-to-date parent as still being up-to-date.
100100
virtual void update_content_version() const noexcept = 0;
101101

102-
static LstBasePtr get_listbase_ptr(ColKey col_key, size_t level);
103-
static SetBasePtr get_setbase_ptr(ColKey col_key, size_t level);
104-
static CollectionBasePtr get_collection_ptr(ColKey col_key, size_t level);
102+
static LstBasePtr get_listbase_ptr(ColKey col_key, uint8_t level);
103+
static SetBasePtr get_setbase_ptr(ColKey col_key, uint8_t level);
104+
static CollectionBasePtr get_collection_ptr(ColKey col_key, uint8_t level);
105105

106106
static int64_t generate_key(size_t sz);
107107
static void set_key(BPlusTreeMixed& tree, size_t index);

src/realm/dictionary.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void validate_key_value(const Mixed& key)
4848

4949
/******************************** Dictionary *********************************/
5050

51-
Dictionary::Dictionary(ColKey col_key, size_t level)
51+
Dictionary::Dictionary(ColKey col_key, uint8_t level)
5252
: Base(col_key)
5353
, CollectionParent(level)
5454
{
@@ -433,16 +433,8 @@ void Dictionary::insert_collection(const PathElement& path_elem, CollectionType
433433
if (dict_or_list == CollectionType::Set) {
434434
throw IllegalOperation("Set nested in Dictionary is not supported");
435435
}
436-
437436
check_level();
438-
ensure_created();
439-
Mixed new_val(0, dict_or_list);
440-
auto old_val = try_get(path_elem.get_key());
441-
if (!old_val || *old_val != new_val) {
442-
m_values->ensure_keys();
443-
auto [it, inserted] = insert(path_elem.get_key(), new_val);
444-
set_key(*m_values, it.index());
445-
}
437+
insert(path_elem.get_key(), Mixed(0, dict_or_list));
446438
}
447439

448440
DictionaryPtr Dictionary::get_dictionary(const PathElement& path_elem) const
@@ -549,6 +541,7 @@ std::pair<Dictionary::Iterator, bool> Dictionary::insert(Mixed key, Mixed value)
549541
throw StaleAccessor("Stale dictionary");
550542
}
551543

544+
bool set_nested_collection_key = value.is_type(type_Dictionary, type_List);
552545
bool old_entry = false;
553546
auto [ndx, actual_key] = find_impl(key);
554547
if (actual_key != key) {
@@ -577,16 +570,25 @@ std::pair<Dictionary::Iterator, bool> Dictionary::insert(Mixed key, Mixed value)
577570
repl->dictionary_insert(*this, ndx, key, value);
578571
}
579572
}
580-
581573
bump_content_version();
582574

583575
ObjLink old_link;
584576
if (old_entry) {
585577
Mixed old_value = m_values->get(ndx);
586-
if (old_value.is_type(type_TypedLink)) {
587-
old_link = old_value.get<ObjLink>();
578+
if (!value.is_same_type(old_value) || value != old_value) {
579+
if (old_value.is_type(type_TypedLink)) {
580+
old_link = old_value.get<ObjLink>();
581+
}
582+
m_values->set(ndx, value);
588583
}
589-
m_values->set(ndx, value);
584+
else {
585+
set_nested_collection_key = false;
586+
}
587+
}
588+
589+
if (set_nested_collection_key) {
590+
m_values->ensure_keys();
591+
set_key(*m_values, ndx);
590592
}
591593

592594
if (new_link != old_link) {

src/realm/dictionary.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Dictionary final : public CollectionBaseImpl<DictionaryBase>, public Colle
5151
: Base(parent, index)
5252
{
5353
}
54-
Dictionary(ColKey col_key, size_t level = 1);
54+
Dictionary(ColKey col_key, uint8_t level = 1);
5555
Dictionary(const Dictionary& other)
5656
: Base(static_cast<const Base&>(other))
5757
, CollectionParent(other.get_level())

src/realm/list.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,12 @@ Mixed Lst<Mixed>::set(size_t ndx, Mixed value)
408408
if (Replication* repl = Base::get_replication()) {
409409
repl->list_set(*this, ndx, value);
410410
}
411-
if (!(old.is_same_type(value) && old == value)) {
411+
if (!value.is_same_type(old) || value != old) {
412412
do_set(ndx, value);
413+
if (value.is_type(type_Dictionary, type_List)) {
414+
m_tree->ensure_keys();
415+
set_key(*m_tree, ndx);
416+
}
413417
bump_content_version();
414418
}
415419
return old;
@@ -427,6 +431,10 @@ void Lst<Mixed>::insert(size_t ndx, Mixed value)
427431
repl->list_insert(*this, ndx, value, sz);
428432
}
429433
do_insert(ndx, value);
434+
if (value.is_type(type_Dictionary, type_List)) {
435+
m_tree->ensure_keys();
436+
set_key(*m_tree, ndx);
437+
}
430438
bump_content_version();
431439
}
432440

@@ -529,37 +537,17 @@ void Lst<Mixed>::insert_collection(const PathElement& path_elem, CollectionType
529537
if (dict_or_list == CollectionType::Set) {
530538
throw IllegalOperation("Set nested in List<Mixed> is not supported");
531539
}
532-
533-
ensure_created();
534540
check_level();
535-
m_tree->ensure_keys();
536541
insert(path_elem.get_ndx(), Mixed(0, dict_or_list));
537-
set_key(*m_tree, path_elem.get_ndx());
538-
bump_content_version();
539542
}
540543

541544
void Lst<Mixed>::set_collection(const PathElement& path_elem, CollectionType dict_or_list)
542545
{
543546
if (dict_or_list == CollectionType::Set) {
544547
throw IllegalOperation("Set nested in List<Mixed> is not supported");
545548
}
546-
547-
auto ndx = path_elem.get_ndx();
548-
// get will check for ndx out of bounds
549-
Mixed old_val = do_get(ndx, "set_collection()");
550-
Mixed new_val(0, dict_or_list);
551-
552549
check_level();
553-
554-
if (old_val != new_val) {
555-
m_tree->ensure_keys();
556-
set(ndx, new_val);
557-
int64_t key = m_tree->get_key(ndx);
558-
if (key == 0) {
559-
set_key(*m_tree, path_elem.get_ndx());
560-
}
561-
bump_content_version();
562-
}
550+
set(path_elem.get_ndx(), Mixed(0, dict_or_list));
563551
}
564552

565553
DictionaryPtr Lst<Mixed>::get_dictionary(const PathElement& path_elem) const

src/realm/list.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class Lst<Mixed> final : public CollectionBaseImpl<LstBase>, public CollectionPa
291291
{
292292
this->set_owner(owner, col_key);
293293
}
294-
Lst(ColKey col_key, size_t level = 1)
294+
Lst(ColKey col_key, uint8_t level = 1)
295295
: Base(col_key)
296296
, CollectionParent(level)
297297
{

0 commit comments

Comments
 (0)