Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.

Add support for Weak/Strong links aka Cascading deletes#622

Closed
cmelchior wants to merge 14 commits into
masterfrom
cm/support-link-type
Closed

Add support for Weak/Strong links aka Cascading deletes#622
cmelchior wants to merge 14 commits into
masterfrom
cm/support-link-type

Conversation

@cmelchior
Copy link
Copy Markdown
Contributor

@cmelchior cmelchior commented Jan 12, 2018

This PR exposes cores concept of Weak/Strong links in the Object Store schema using the Relationship::Strong parameter when creating link properties. This can be used to implement cascading deletes.

// New constructor 
Property(std::string name, PropertyType type, std::string object_type, Relationship relationship)

Semantics:

  • Default (and current Linktype) is Weak.
  • Changing the link type is a breaking change
  • Modifying the link type does not clean up the Realm automatically, i.e. changing from weak -> Strong will not automatically remove all objects not connected. This cleanup only happens if a links is actually updated.
  • It is possible to create child objects with no parents, these will not be deleted automatically. This only happens if the parent is created, the link is created, and then removed again.
  • Cascading behaviour is immediate inside a transaction. Rolling back the transaction will undo all deletes.
  • Some corner cases exist for cyclic object graphs, they are documented in core

Java PR using this is here: realm/realm-java#5678

Comment thread src/property.hpp Outdated

#include "util/tagged_bool.hpp"

#include <string>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This include was previously in the correct place.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure why, but If this is not here I get:

In file included from /Users/cm/Realm/realm-object-store/src/property.hpp:24:
/Users/cm/Realm/realm-object-store/CMakeFiles/realm-core-5.0.1/include/realm/data_type.hpp:27:9: error: unknown type name 'int64_t'
typedef int64_t Int;

Copy link
Copy Markdown
Member

@tgoyne tgoyne Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data_types.hpp needs to include <cstdint>

Comment thread src/property.hpp Outdated

// Return the underlying LinkType. Only useful for Object or Array properties.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Giving Relationship a backing type of bool eliminates the need for this.

Comment thread src/property.hpp Outdated
{
}

inline Property::Property(std::string name, PropertyType type,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor is redundant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is being used by tests and not having it results in:

Undefined symbols for architecture x86_64:
  "realm::Property::Property(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, realm::PropertyType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      ____C_A_T_C_H____T_E_S_T____0() in list.cpp.o
      ____C_A_T_C_H____T_E_S_T____3() in migrations.cpp.o
      ____C_A_T_C_H____T_E_S_T____111() in migrations.cpp.o
      ____C_A_T_C_H____T_E_S_T____134() in migrations.cpp.o
      ____C_A_T_C_H____T_E_S_T____0() in object.cpp.o
      ____C_A_T_C_H____T_E_S_T____3() in object_store.cpp.o
      ____C_A_T_C_H____T_E_S_T____102() in results.cpp.o

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is functionally identical to the three-argument version with a default value for the third argument (i.e. what previously existed).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those was changed as well, these constructors have no default values anymore as having two 3-argument constructors with different defaults is ambiguous. So there is now a constructor for creating backlinks (with a string default value) and one for creating normal links (with a relationship default value)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having Property(std::string name, PropertyType type, std::string object_type, std::string link_origin_property_name=""); and Property(std::string name, PropertyType type, std::string object_type, Relationship relationship); is not ambiguous.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, like that. No, your right.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2-arg constructor has been removed

Comment thread src/property.hpp Outdated
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type"
LinkType link_type() const {
switch(relationship) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between keyword and (

Comment thread src/schema.cpp Outdated
else if (current_prop.requires_index()) {
changes.emplace_back(schema_change::RemoveIndex{&existing_schema, &current_prop});
}
if(target_prop->relationship != current_prop.relationship) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between keyword and (

Comment thread tests/link_types.cpp Outdated
// See Descriptor::set_link_type() in Core (descriptor.hpp) for an extended explanation of the exact semantics.

namespace realm {
class TestHelper {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no reason to put these functions in a class.

Comment thread tests/link_types.cpp Outdated
@@ -0,0 +1,303 @@
////////////////////////////////////////////////////////////////////////////
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire file appears to just be testing core functionality, and should be part of core's test suite instead.

Comment thread tests/migrations.cpp Outdated
return schema;
}

Schema set_relationship(Schema schema, StringData object_name, StringData property_name, Relationship new_relationship_type) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline before {

@cmelchior
Copy link
Copy Markdown
Contributor Author

All comments addressed

@cmelchior
Copy link
Copy Markdown
Contributor Author

Currently, Sync will crash with Unsupported operation if you try to change the link type, so merging this PR is probably not a good idea until that has been fixed. Apparently, that will require a protocol upgrade.

@Zhuinden
Copy link
Copy Markdown

Destructive changes always caused "bad changeset received", how is this any different?

@tgoyne
Copy link
Copy Markdown
Member

tgoyne commented Jun 17, 2018

The problem is not that you cannot make existing links strong, but rather that sync does not support strong links at all.

@nirinchev
Copy link
Copy Markdown
Member

Cascading deletes are now (somewhat) supported via embedded objects and it's unlikely sync will ever support strong links, so closing this.

@nirinchev nirinchev closed this Oct 14, 2020
@nirinchev nirinchev deleted the cm/support-link-type branch October 14, 2020 09:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants