From 453e4d8277f503c14583d51596095a9d73111c48 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Mon, 3 Aug 2015 10:11:43 -0700 Subject: [PATCH 1/4] Fix crash when adding a property to a model without updating the schema version. --- object_store.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/object_store.cpp b/object_store.cpp index cf3dd2ed..3d1ec9c3 100644 --- a/object_store.cpp +++ b/object_store.cpp @@ -232,9 +232,10 @@ void ObjectStore::update_column_mapping(Group *group, ObjectSchema &target_schem ObjectSchema table_schema(group, target_schema.name); for (auto& target_prop : target_schema.properties) { auto table_prop = table_schema.property_for_name(target_prop.name); - REALM_ASSERT_DEBUG(table_prop); - - target_prop.table_column = table_prop->table_column; + if (table_prop) { + // Update target property column to match what's in the realm if it exists + target_prop.table_column = table_prop->table_column; + } } } From 8712c8bc2cd1f2dd41384ddf49afa372de8975d7 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Mon, 10 Aug 2015 10:49:59 -0700 Subject: [PATCH 2/4] fixes for latest object store changes --- shared_realm.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shared_realm.cpp b/shared_realm.cpp index 9704b58e..bd489b0f 100644 --- a/shared_realm.cpp +++ b/shared_realm.cpp @@ -17,6 +17,8 @@ //////////////////////////////////////////////////////////////////////////// #include "shared_realm.hpp" +#include +#include #include #include From cb8364c2554029287f8e3cd7bb7520c63e17845c Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Wed, 12 Aug 2015 11:07:06 -0700 Subject: [PATCH 3/4] property copy schema from cached realms --- shared_realm.cpp | 22 +++++++++------------- shared_realm.hpp | 1 - 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/shared_realm.cpp b/shared_realm.cpp index bd489b0f..10c09f6c 100644 --- a/shared_realm.cpp +++ b/shared_realm.cpp @@ -65,11 +65,6 @@ Realm::Realm(Config &config) : m_config(config), m_thread_id(std::this_thread::g } } -Realm::~Realm() -{ - s_global_cache.remove(m_config.path, m_thread_id); -} - Group *Realm::read_group() { if (!m_group) { @@ -110,7 +105,12 @@ SharedRealm Realm::get_shared_realm(Config &config) std::lock_guard lock(s_init_mutex); uint64_t old_version = ObjectStore::get_schema_version(realm->read_group()); - if (!realm->m_config.schema) { + if (auto existing = s_global_cache.get_any_realm(realm->config().path)) { + // if there is an existing realm at the current path steal its schema/column mapping + // FIXME - need to validate that schemas match + realm->m_config.schema = std::make_unique(*existing->m_config.schema); + } + else if (!realm->m_config.schema) { // get schema from group and skip validation realm->m_config.schema_version = old_version; realm->m_config.schema = std::make_unique(ObjectStore::schema_from_group(realm->read_group())); @@ -121,11 +121,6 @@ SharedRealm Realm::get_shared_realm(Config &config) } ObjectStore::verify_schema(realm->read_group(), *realm->m_config.schema, true); } - else if(auto existing = s_global_cache.get_any_realm(realm->config().path)) { - // if there is an existing realm at the current path steal its schema/column mapping - // FIXME - need to validate that schemas match - realm->m_config.schema = std::make_unique(*existing->m_config.schema); - } else { // its a non-cached realm so update/migrate if needed realm->update_schema(*realm->m_config.schema, realm->m_config.schema_version); @@ -357,11 +352,12 @@ SharedRealm RealmCache::get_any_realm(const std::string &path) return SharedRealm(); } - for (auto thread_iter = path_iter->second.begin(); thread_iter != path_iter->second.end(); thread_iter++) { + auto thread_iter = path_iter->second.begin(); + while (thread_iter != path_iter->second.end()) { if (auto realm = thread_iter->second.lock()) { return realm; } - path_iter->second.erase(thread_iter); + path_iter->second.erase(thread_iter++); } return SharedRealm(); diff --git a/shared_realm.hpp b/shared_realm.hpp index 2807549d..e2640386 100644 --- a/shared_realm.hpp +++ b/shared_realm.hpp @@ -120,7 +120,6 @@ namespace realm { static RealmCache s_global_cache; public: - ~Realm(); ExternalNotificationFunction m_external_notifier; // FIXME private From b0843356dc39135ac0fec21e8a2e97cbc325a894 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Wed, 12 Aug 2015 12:02:56 -0700 Subject: [PATCH 4/4] clear Realm cache between tests --- shared_realm.cpp | 7 +++++++ shared_realm.hpp | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/shared_realm.cpp b/shared_realm.cpp index 10c09f6c..a7269591 100644 --- a/shared_realm.cpp +++ b/shared_realm.cpp @@ -395,3 +395,10 @@ void RealmCache::cache_realm(SharedRealm &realm, std::thread::id thread_id) } } +void RealmCache::clear() +{ + std::lock_guard lock(m_mutex); + + m_cache.clear(); +} + diff --git a/shared_realm.hpp b/shared_realm.hpp index e2640386..af8b774a 100644 --- a/shared_realm.hpp +++ b/shared_realm.hpp @@ -117,13 +117,13 @@ namespace realm { Group *m_group; static std::mutex s_init_mutex; - static RealmCache s_global_cache; public: ExternalNotificationFunction m_external_notifier; // FIXME private Group *read_group(); + static RealmCache s_global_cache; }; class RealmCache @@ -133,6 +133,7 @@ namespace realm { SharedRealm get_any_realm(const std::string &path); void remove(const std::string &path, std::thread::id thread_id); void cache_realm(SharedRealm &realm, std::thread::id thread_id = std::this_thread::get_id()); + void clear(); private: std::map> m_cache;