Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNET-6] Add support for client resync #1901

Merged
merged 2 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Realm/Realm/Configurations/FullSyncConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public class FullSyncConfiguration : SyncConfigurationBase
{
internal override bool IsFullSync => true;

internal override ClientResyncMode ResyncMode => ClientResyncMode;

/// <summary>
/// Gets or sets a value controlling the behavior in case of a Client Resync. Default is <see cref="ClientResyncMode.RecoverLocalRealm"/>
/// </summary>
public ClientResyncMode ClientResyncMode { get; set; } = ClientResyncMode.RecoverLocalRealm;

/// <summary>
/// Initializes a new instance of the <see cref="FullSyncConfiguration"/> class.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Realm/Realm/Configurations/QueryBasedSyncConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class QueryBasedSyncConfiguration : SyncConfigurationBase
{
internal override bool IsFullSync => false;

internal override ClientResyncMode ResyncMode => ClientResyncMode.Manual;

internal static readonly Type[] _queryBasedPermissionTypes =
{
typeof(ClassPermission),
Expand Down
5 changes: 4 additions & 1 deletion Realm/Realm/Configurations/SyncConfigurationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public abstract class SyncConfigurationBase : RealmConfigurationBase
/// </summary>
public Action<SyncProgress> OnProgress { get; set; }

internal abstract ClientResyncMode ResyncMode { get; }

/// <summary>
/// Gets or sets a value indicating how detailed the sync client's logs will be.
/// </summary>
Expand Down Expand Up @@ -302,7 +304,8 @@ internal Native.SyncConfiguration ToNative()
client_validate_ssl = EnableSSLValidation,
TrustedCAPath = TrustedCAPath,
is_partial = !IsFullSync,
PartialSyncIdentifier = null
PartialSyncIdentifier = null,
client_resync_mode = ResyncMode,
};
}

Expand Down
6 changes: 6 additions & 0 deletions Realm/Realm/Native/SyncConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal SyncUserHandle SyncUserHandle

[MarshalAs(UnmanagedType.LPWStr)]
private string url;

private IntPtr url_len;

internal string Url
Expand All @@ -54,6 +55,7 @@ internal string Url

[MarshalAs(UnmanagedType.LPWStr)]
private string trusted_ca_path;

private IntPtr trusted_ca_path_len;

internal string TrustedCAPath
Expand All @@ -70,6 +72,7 @@ internal string TrustedCAPath

[MarshalAs(UnmanagedType.LPWStr)]
private string partial_sync_identifier;

private IntPtr partial_sync_identifier_len;

internal string PartialSyncIdentifier
Expand All @@ -80,5 +83,8 @@ internal string PartialSyncIdentifier
partial_sync_identifier_len = (IntPtr)(value?.Length ?? 0);
}
}

[MarshalAs(UnmanagedType.U1)]
internal ClientResyncMode client_resync_mode;
}
}
45 changes: 45 additions & 0 deletions Realm/Realm/Sync/ClientResyncMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Realms.Sync.Exceptions;

namespace Realms.Sync
{
/// <summary>
/// Enum describing what should happen in case of a Client Resync.
/// </summary>
/// <remarks>
/// A Client Resync is triggered if the device and server cannot agree on a common shared history
/// for the Realm file, thus making it impossible for the device to upload or receive any changes.
/// This can happen if the server is rolled back or restored from backup.
/// <br/>
/// IMPORTANT: Just having the device offline will not trigger a Client Resync.
/// </remarks>
public enum ClientResyncMode : byte
{
/// <summary>
/// Realm will compare the local Realm with the Realm on the server and automatically transfer
/// any changes from the local Realm that makes sense to the Realm provided by the server.
/// <br/>
/// This is the default mode for fully synchronized Realms. It is not yet supported by
/// Query-based Realms.
/// </summary>
RecoverLocalRealm = 0,

/// <summary>
/// The local Realm will be discarded and replaced with the server side Realm.
/// All local changes will be lost.
/// <br/>
/// This mode is not yet supported by Query-based Realms.
/// </summary>
DiscardLocalRealm = 1,

/// <summary>
/// A manual Client Resync is also known as a Client Reset.
/// <br/>
/// A <see cref="ClientResetException"/> will be sent to <see cref="Session.Error"/>,
/// triggering a Client Reset. Doing this provides a handle to both the old and new Realm file, enabling
/// full control over which changes to move, if any.
/// <br/>
/// This is the only supported mode for Query-based Realms.
/// </summary>
Manual = 2,
}
}
4 changes: 2 additions & 2 deletions wrappers/dependencies.list
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
REALM_CORE_VERSION=5.23.1
REALM_SYNC_VERSION=4.7.1
REALM_CORE_VERSION=5.23.3
REALM_SYNC_VERSION=4.7.5
ANDROID_OPENSSL_VERSION=1.0.2k
1 change: 1 addition & 0 deletions wrappers/src/sync_manager_cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Realm::Config get_shared_realm_config(Configuration configuration, SyncConfigura
config.sync_config = std::make_shared<SyncConfig>(*sync_configuration.user, realm_url);
config.sync_config->bind_session_handler = bind_session;
config.sync_config->error_handler = handle_session_error;
config.sync_config->client_resync_mode = sync_configuration.client_resync_mode;
config.path = Utf16StringAccessor(configuration.path, configuration.path_len);

// by definition the key is only allowed to be 64 bytes long, enforced by C# code
Expand Down
8 changes: 4 additions & 4 deletions wrappers/src/sync_manager_cs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#pragma once

#include "realm_export_decls.hpp"
#include "sync/sync_config.hpp"

using namespace realm;

namespace realm {
class SyncUser;
Expand All @@ -38,9 +41,6 @@ namespace realm {
bool is_partial;
uint16_t* partial_sync_identifier;
size_t partial_sync_identifier_len;
realm::ClientResyncMode client_resync_mode;
};

namespace binding {
REALM_EXPORT bool has_feature(StringData feature);
}
}