Skip to content

Commit fe1d852

Browse files
committed
Remove ability to synchronize objects without primary key
With the legacy server this was based on GlobalKey, but if we at some point will allow objects without primary key to be synced to MongoDB server, we will probably have to invent a new strategy. As we remove support for GlobalKey we will have to change the way we allocate ObjKeys for tombstones. Beforehand we used a hash of the primary key to construct a GlobalKey and from that an ObjKey. Now we just use the current ObjKey to construct a corresponding unresolved key. But it has the effect that there is not an easy way to come from primary key to potential unresolved key, so we will have to search for a potential tombstone.
1 parent 9c32d56 commit fe1d852

20 files changed

+107
-906
lines changed

src/realm/cluster_tree.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,6 @@ void ClusterTree::erase(ObjKey k, CascadeState& state)
994994
}
995995
}
996996
}
997-
m_owner->free_local_id_after_hash_collision(k);
998997
m_owner->erase_from_search_indexes(k);
999998

1000999
size_t root_size = m_root->erase(k, state);

src/realm/obj.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ Obj::Obj(TableRef table, MemRef mem, ObjKey key, size_t row_ndx)
114114
m_storage_version = get_alloc().get_storage_version();
115115
}
116116

117-
GlobalKey Obj::get_object_id() const
118-
{
119-
return m_table->get_object_id(m_key);
120-
}
121-
122117
ObjLink Obj::get_link() const
123118
{
124119
return ObjLink(m_table->get_key(), m_key);

src/realm/obj.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class ClusterTree;
3434
class TableView;
3535
class CascadeState;
3636
class ObjList;
37-
struct GlobalKey;
3837

3938
template <class>
4039
class Lst;
@@ -114,7 +113,6 @@ class Obj : public CollectionParent {
114113
{
115114
return m_key;
116115
}
117-
GlobalKey get_object_id() const;
118116
ObjLink get_link() const;
119117

120118
/// Check if the object is still alive

src/realm/replication.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ void Replication::erase_column(const Table* t, ColKey col_key)
139139
m_encoder.erase_column(col_key); // Throws
140140
}
141141

142-
void Replication::create_object(const Table* t, GlobalKey id)
142+
void Replication::create_object(const Table* t, ObjKey key)
143143
{
144144
if (auto logger = get_logger()) {
145145
logger->log(util::Logger::Level::debug, "Create object '%1'", t->get_class_name());
146146
}
147147
select_table(t); // Throws
148-
m_encoder.create_object(id.get_local_key(0)); // Throws
148+
m_encoder.create_object(key); // Throws
149149
}
150150

151151
void Replication::create_object_with_primary_key(const Table* t, ObjKey key, Mixed pk)

src/realm/replication.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Replication {
7474
virtual void dictionary_erase(const CollectionBase& dict, size_t dict_ndx, Mixed key);
7575
virtual void dictionary_clear(const CollectionBase& dict);
7676

77-
virtual void create_object(const Table*, GlobalKey);
77+
virtual void create_object(const Table*, ObjKey);
7878
virtual void create_object_with_primary_key(const Table*, ObjKey, Mixed);
7979
virtual void remove_object(const Table*, ObjKey);
8080

src/realm/sync/instruction_applier.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,8 @@ void InstructionApplier::operator()(const Instruction::CreateObject& instr)
226226
}
227227
m_last_object = table->create_object_with_primary_key(id);
228228
},
229-
[&](GlobalKey key) {
230-
if (pk_col) {
231-
bad_transaction_log("CreateObject(GlobalKey) on table with a primary key");
232-
}
233-
m_last_object = table->create_object(key);
229+
[&](GlobalKey) {
230+
bad_transaction_log("CreateObject(GlobalKey) not supported");
234231
},
235232
},
236233
instr.object);
@@ -1682,14 +1679,9 @@ ObjKey InstructionApplier::get_object_key(Table& table, const Instruction::Prima
16821679
ObjKey key = table.get_objkey_from_primary_key(pk);
16831680
return key;
16841681
},
1685-
[&](GlobalKey id) {
1686-
if (pk_col) {
1687-
bad_transaction_log(
1688-
"%1 instruction without primary key, but table '%2' has a primary key column of type %3",
1689-
name, table_name, pk_type);
1690-
}
1691-
ObjKey key = table.get_objkey_from_global_key(id);
1692-
return key;
1682+
[&](GlobalKey) {
1683+
bad_transaction_log("%1 instruction without primary key not supported", name);
1684+
return ObjKey();
16931685
},
16941686
[&](ObjectId pk) {
16951687
if (!pk_col) {

src/realm/sync/instruction_replication.cpp

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -242,26 +242,6 @@ void SyncReplication::add_class_with_primary_key(TableKey tk, StringData name, D
242242
}
243243
}
244244

245-
void SyncReplication::create_object(const Table* table, GlobalKey oid)
246-
{
247-
if (table->is_embedded()) {
248-
unsupported_instruction(); // FIXME: TODO
249-
}
250-
251-
Replication::create_object(table, oid);
252-
if (select_table(*table)) {
253-
if (table->get_primary_key_column()) {
254-
// Trying to create object without a primary key in a table that
255-
// has a primary key column.
256-
unsupported_instruction();
257-
}
258-
Instruction::CreateObject instr;
259-
instr.table = m_last_class_name;
260-
instr.object = oid;
261-
emit(instr);
262-
}
263-
}
264-
265245
Instruction::PrimaryKey SyncReplication::as_primary_key(Mixed value)
266246
{
267247
if (value.is_null()) {
@@ -749,13 +729,7 @@ Instruction::PrimaryKey SyncReplication::primary_key_for_object(const Table& tab
749729
{
750730
bool should_emit = select_table(table);
751731
REALM_ASSERT(should_emit);
752-
753-
if (table.get_primary_key_column()) {
754-
return as_primary_key(table.get_primary_key(key));
755-
}
756-
757-
GlobalKey global_key = table.get_object_id(key);
758-
return global_key;
732+
return as_primary_key(table.get_primary_key(key));
759733
}
760734

761735
void SyncReplication::populate_path_instr(Instruction::PathInstruction& instr, const Table& table, ObjKey key,

src/realm/sync/instruction_replication.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class SyncReplication : public Replication {
4848
void add_class(TableKey tk, StringData table_name, Table::Type table_type = Table::Type::TopLevel) final;
4949
void add_class_with_primary_key(TableKey tk, StringData table_name, DataType pk_type, StringData pk_field,
5050
bool nullable, Table::Type table_type) final;
51-
void create_object(const Table*, GlobalKey) final;
5251
void create_object_with_primary_key(const Table*, ObjKey, Mixed) final;
5352

5453
void erase_class(TableKey table_key, StringData table_name, size_t num_tables) final;

0 commit comments

Comments
 (0)