Merge pull request #3 from realm/al-bugfixes
Bugfixes from the cocoa branch
This commit is contained in:
commit
0700428945
|
@ -232,11 +232,12 @@ void ObjectStore::update_column_mapping(Group *group, ObjectSchema &target_schem
|
||||||
ObjectSchema table_schema(group, target_schema.name);
|
ObjectSchema table_schema(group, target_schema.name);
|
||||||
for (auto& target_prop : target_schema.properties) {
|
for (auto& target_prop : target_schema.properties) {
|
||||||
auto table_prop = table_schema.property_for_name(target_prop.name);
|
auto table_prop = table_schema.property_for_name(target_prop.name);
|
||||||
REALM_ASSERT_DEBUG(table_prop);
|
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;
|
target_prop.table_column = table_prop->table_column;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set references to tables on targetSchema and create/update any missing or out-of-date tables
|
// set references to tables on targetSchema and create/update any missing or out-of-date tables
|
||||||
// if update existing is true, updates existing tables, otherwise validates existing tables
|
// if update existing is true, updates existing tables, otherwise validates existing tables
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "shared_realm.hpp"
|
#include "shared_realm.hpp"
|
||||||
|
#include <realm/group_shared.hpp>
|
||||||
|
#include <realm/lang_bind_helper.hpp>
|
||||||
#include <realm/commit_log.hpp>
|
#include <realm/commit_log.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
@ -63,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()
|
Group *Realm::read_group()
|
||||||
{
|
{
|
||||||
if (!m_group) {
|
if (!m_group) {
|
||||||
|
@ -108,7 +105,12 @@ SharedRealm Realm::get_shared_realm(Config &config)
|
||||||
std::lock_guard<std::mutex> lock(s_init_mutex);
|
std::lock_guard<std::mutex> lock(s_init_mutex);
|
||||||
|
|
||||||
uint64_t old_version = ObjectStore::get_schema_version(realm->read_group());
|
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<Schema>(*existing->m_config.schema);
|
||||||
|
}
|
||||||
|
else if (!realm->m_config.schema) {
|
||||||
// get schema from group and skip validation
|
// get schema from group and skip validation
|
||||||
realm->m_config.schema_version = old_version;
|
realm->m_config.schema_version = old_version;
|
||||||
realm->m_config.schema = std::make_unique<Schema>(ObjectStore::schema_from_group(realm->read_group()));
|
realm->m_config.schema = std::make_unique<Schema>(ObjectStore::schema_from_group(realm->read_group()));
|
||||||
|
@ -119,11 +121,6 @@ SharedRealm Realm::get_shared_realm(Config &config)
|
||||||
}
|
}
|
||||||
ObjectStore::verify_schema(realm->read_group(), *realm->m_config.schema, true);
|
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<Schema>(*existing->m_config.schema);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
// its a non-cached realm so update/migrate if needed
|
// its a non-cached realm so update/migrate if needed
|
||||||
realm->update_schema(*realm->m_config.schema, realm->m_config.schema_version);
|
realm->update_schema(*realm->m_config.schema, realm->m_config.schema_version);
|
||||||
|
@ -355,11 +352,12 @@ SharedRealm RealmCache::get_any_realm(const std::string &path)
|
||||||
return SharedRealm();
|
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()) {
|
if (auto realm = thread_iter->second.lock()) {
|
||||||
return realm;
|
return realm;
|
||||||
}
|
}
|
||||||
path_iter->second.erase(thread_iter);
|
path_iter->second.erase(thread_iter++);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SharedRealm();
|
return SharedRealm();
|
||||||
|
@ -397,3 +395,10 @@ void RealmCache::cache_realm(SharedRealm &realm, std::thread::id thread_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RealmCache::clear()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
|
m_cache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,14 +117,13 @@ namespace realm {
|
||||||
Group *m_group;
|
Group *m_group;
|
||||||
|
|
||||||
static std::mutex s_init_mutex;
|
static std::mutex s_init_mutex;
|
||||||
static RealmCache s_global_cache;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~Realm();
|
|
||||||
ExternalNotificationFunction m_external_notifier;
|
ExternalNotificationFunction m_external_notifier;
|
||||||
|
|
||||||
// FIXME private
|
// FIXME private
|
||||||
Group *read_group();
|
Group *read_group();
|
||||||
|
static RealmCache s_global_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RealmCache
|
class RealmCache
|
||||||
|
@ -134,6 +133,7 @@ namespace realm {
|
||||||
SharedRealm get_any_realm(const std::string &path);
|
SharedRealm get_any_realm(const std::string &path);
|
||||||
void remove(const std::string &path, std::thread::id thread_id);
|
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 cache_realm(SharedRealm &realm, std::thread::id thread_id = std::this_thread::get_id());
|
||||||
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::map<std::thread::id, WeakRealm>> m_cache;
|
std::map<std::string, std::map<std::thread::id, WeakRealm>> m_cache;
|
||||||
|
|
Loading…
Reference in New Issue