Skip to content

Commit fc5ee2a

Browse files
committed
Remove ClientHistory::fix_up_client_file_ident_in_stored_changesets() and friends
1 parent fe1d852 commit fc5ee2a

10 files changed

+11
-125
lines changed

src/realm/sync/client_base.hpp

-8
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,6 @@ struct ClientConfig {
209209
///
210210
/// Testing/debugging feature. Should never be enabled in production.
211211
bool disable_sync_to_disk = false;
212-
213-
/// The sync client supports tables without primary keys by synthesizing a
214-
/// pk using the client file ident, which means that all changesets waiting
215-
/// to be uploaded need to be rewritten with the correct ident the first time
216-
/// we connect to the server. The modern server doesn't support this and
217-
/// requires pks for all tables, so this is now only applicable to old sync
218-
/// tests and so is disabled by default.
219-
bool fix_up_object_ids = false;
220212
};
221213

222214
/// \brief Information about an error causing a session to be temporarily

src/realm/sync/noinst/client_history_impl.cpp

+1-97
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ void ClientHistory::get_status(version_type& current_client_version, SaltedFileI
270270
}
271271

272272

273-
void ClientHistory::set_client_file_ident(SaltedFileIdent client_file_ident, bool fix_up_object_ids)
273+
void ClientHistory::set_client_file_ident(SaltedFileIdent client_file_ident)
274274
{
275275
REALM_ASSERT(client_file_ident.ident != 0);
276276

@@ -287,10 +287,6 @@ void ClientHistory::set_client_file_ident(SaltedFileIdent client_file_ident, boo
287287
root.set(s_progress_download_client_version_iip, RefOrTagged::make_tagged(0));
288288
root.set(s_progress_upload_client_version_iip, RefOrTagged::make_tagged(0));
289289

290-
if (fix_up_object_ids) {
291-
fix_up_client_file_ident_in_stored_changesets(*wt, client_file_ident.ident); // Throws
292-
}
293-
294290
// Note: This transaction produces an empty changeset. Empty changesets are
295291
// not uploaded to the server.
296292
wt->commit(); // Throws
@@ -1024,98 +1020,6 @@ void ClientHistory::do_trim_sync_history(std::size_t n)
10241020
}
10251021
}
10261022

1027-
void ClientHistory::fix_up_client_file_ident_in_stored_changesets(Transaction& group,
1028-
file_ident_type client_file_ident)
1029-
{
1030-
// Must be in write transaction!
1031-
1032-
REALM_ASSERT(client_file_ident != 0);
1033-
auto promote_global_key = [client_file_ident](GlobalKey* oid) {
1034-
if (oid->hi() == 0) {
1035-
// client_file_ident == 0
1036-
*oid = GlobalKey{uint64_t(client_file_ident), oid->lo()};
1037-
return true;
1038-
}
1039-
return false;
1040-
};
1041-
1042-
Group::TableNameBuffer buffer;
1043-
auto get_table_for_class = [&](StringData class_name) -> ConstTableRef {
1044-
REALM_ASSERT(class_name.size() < Group::max_table_name_length - 6);
1045-
return group.get_table(Group::class_name_to_table_name(class_name, buffer));
1046-
};
1047-
1048-
util::compression::CompressMemoryArena arena;
1049-
util::AppendBuffer<char> compressed;
1050-
1051-
// Fix up changesets.
1052-
Array& root = m_arrays->root;
1053-
uint64_t uploadable_bytes = root.get_as_ref_or_tagged(s_progress_uploadable_bytes_iip).get_as_int();
1054-
for (size_t i = 0; i < sync_history_size(); ++i) {
1055-
// We could have opened a pre-provisioned realm file. In this case we can skip the entries downloaded
1056-
// from the server.
1057-
if (m_arrays->origin_file_idents.get(i) != 0)
1058-
continue;
1059-
1060-
ChunkedBinaryData changeset{m_arrays->changesets, i};
1061-
ChunkedBinaryInputStream is{changeset};
1062-
size_t decompressed_size;
1063-
auto decompressed = util::compression::decompress_nonportable_input_stream(is, decompressed_size);
1064-
if (!decompressed)
1065-
continue;
1066-
Changeset log;
1067-
parse_changeset(*decompressed, log);
1068-
1069-
bool did_modify = false;
1070-
auto last_class_name = InternString::npos;
1071-
ConstTableRef selected_table;
1072-
for (auto instr : log) {
1073-
if (!instr)
1074-
continue;
1075-
1076-
if (auto obj_instr = instr->get_if<Instruction::ObjectInstruction>()) {
1077-
// Cache the TableRef
1078-
if (obj_instr->table != last_class_name) {
1079-
StringData class_name = log.get_string(obj_instr->table);
1080-
last_class_name = obj_instr->table;
1081-
selected_table = get_table_for_class(class_name);
1082-
}
1083-
1084-
// Fix up instructions using GlobalKey to identify objects.
1085-
if (auto global_key = mpark::get_if<GlobalKey>(&obj_instr->object)) {
1086-
did_modify = promote_global_key(global_key);
1087-
}
1088-
1089-
// Fix up the payload for Set and ArrayInsert.
1090-
Instruction::Payload* payload = nullptr;
1091-
if (auto set_instr = instr->get_if<Instruction::Update>()) {
1092-
payload = &set_instr->value;
1093-
}
1094-
else if (auto list_insert_instr = instr->get_if<Instruction::ArrayInsert>()) {
1095-
payload = &list_insert_instr->value;
1096-
}
1097-
1098-
if (payload && payload->type == Instruction::Payload::Type::Link) {
1099-
if (auto global_key = mpark::get_if<GlobalKey>(&payload->data.link.target)) {
1100-
did_modify = promote_global_key(global_key);
1101-
}
1102-
}
1103-
}
1104-
}
1105-
1106-
if (did_modify) {
1107-
ChangesetEncoder::Buffer modified;
1108-
encode_changeset(log, modified);
1109-
util::compression::allocate_and_compress_nonportable(arena, modified, compressed);
1110-
m_arrays->changesets.set(i, BinaryData{compressed.data(), compressed.size()}); // Throws
1111-
1112-
uploadable_bytes += modified.size() - decompressed_size;
1113-
}
1114-
}
1115-
1116-
root.set(s_progress_uploadable_bytes_iip, RefOrTagged::make_tagged(uploadable_bytes));
1117-
}
1118-
11191023
void ClientHistory::set_group(Group* group, bool updated)
11201024
{
11211025
_impl::History::set_group(group, updated);

src/realm/sync/noinst/client_history_impl.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class ClientHistory final : public _impl::History, public TransformHistory {
160160
/// synchronization proper, and it must store the identifier and use it to
161161
/// reestablish the connection between the client file and the server file
162162
/// when engaging in future synchronization sessions.
163-
void set_client_file_ident(SaltedFileIdent client_file_ident, bool fix_up_object_ids);
163+
void set_client_file_ident(SaltedFileIdent client_file_ident);
164164

165165
/// Stores the synchronization progress in the associated Realm file in a
166166
/// way that makes it available via get_status() during future
@@ -428,7 +428,6 @@ class ClientHistory final : public _impl::History, public TransformHistory {
428428
void do_trim_sync_history(std::size_t n);
429429
void clamp_sync_version_range(version_type& begin, version_type& end) const noexcept;
430430
Transformer& get_transformer();
431-
void fix_up_client_file_ident_in_stored_changesets(Transaction&, file_ident_type);
432431
void record_current_schema_version();
433432
static void record_current_schema_version(Array& schema_versions, version_type snapshot_version);
434433
void compress_stored_changesets();

src/realm/sync/noinst/client_impl_base.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ ClientImpl::ClientImpl(ClientConfig config)
149149
, m_dry_run{config.dry_run}
150150
, m_enable_default_port_hack{config.enable_default_port_hack}
151151
, m_disable_upload_compaction{config.disable_upload_compaction}
152-
, m_fix_up_object_ids{config.fix_up_object_ids}
153152
, m_roundtrip_time_handler{std::move(config.roundtrip_time_handler)}
154153
, m_socket_provider{std::move(config.socket_provider)}
155154
, m_client_protocol{} // Throws
@@ -2333,8 +2332,7 @@ Status Session::receive_ident_message(SaltedFileIdent client_file_ident)
23332332
return Status::OK();
23342333
}
23352334
if (!did_client_reset) {
2336-
repl.get_history().set_client_file_ident(client_file_ident,
2337-
m_fix_up_object_ids); // Throws
2335+
repl.get_history().set_client_file_ident(client_file_ident); // Throws
23382336
m_progress.download.last_integrated_client_version = 0;
23392337
m_progress.upload.client_version = 0;
23402338
m_last_version_selected_for_upload = 0;

src/realm/sync/noinst/client_impl_base.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ class ClientImpl {
250250
const bool m_dry_run; // For testing purposes only
251251
const bool m_enable_default_port_hack;
252252
const bool m_disable_upload_compaction;
253-
const bool m_fix_up_object_ids;
254253
const std::function<RoundtripTimeHandler> m_roundtrip_time_handler;
255254
const std::string m_user_agent_string;
256255
std::shared_ptr<SyncSocketProvider> m_socket_provider;
@@ -1050,8 +1049,6 @@ class ClientImpl::Session {
10501049

10511050
bool m_is_flx_sync_session = false;
10521051

1053-
bool m_fix_up_object_ids = false;
1054-
10551052
// These are reset when the session is activated, and again whenever the
10561053
// connection is lost or the rebinding process is initiated.
10571054
bool m_enlisted_to_send;
@@ -1464,7 +1461,6 @@ inline ClientImpl::Session::Session(SessionWrapper& wrapper, Connection& conn, s
14641461
, m_ident{ident}
14651462
, m_try_again_delay_info(conn.get_client().m_reconnect_backoff_info, conn.get_client().get_random())
14661463
, m_is_flx_sync_session(conn.is_flx_sync_connection())
1467-
, m_fix_up_object_ids(get_client().m_fix_up_object_ids)
14681464
, m_wrapper{wrapper}
14691465
{
14701466
if (get_client().m_disable_upload_activation_delay)

src/realm/sync/tools/apply_to_state_command.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ int main(int argc, const char** argv)
314314
}
315315
},
316316
[&](const ServerIdentMessage& ident_message) {
317-
history.set_client_file_ident(ident_message.file_ident, true);
317+
history.set_client_file_ident(ident_message.file_ident);
318318
}},
319319
message);
320320
}

test/object-store/util/test_file.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void on_change_but_no_notify(realm::Realm& realm);
102102
#if TEST_ENABLE_LOGGING
103103
#define TEST_LOGGING_LEVEL all
104104
#else
105-
#define TEST_LOGGING_LEVEL off
105+
#define TEST_LOGGING_LEVEL debug
106106
#endif // TEST_ENABLE_LOGGING
107107
#endif // TEST_LOGGING_LEVEL
108108

test/sync_fixtures.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ class MultiClientServerFixture {
550550
config_2.disable_upload_compaction = config.disable_upload_compaction;
551551
config_2.one_connection_per_session = config.one_connection_per_session;
552552
config_2.disable_upload_activation_delay = config.disable_upload_activation_delay;
553-
config_2.fix_up_object_ids = true;
554553
m_clients[i] = std::make_unique<Client>(std::move(config_2));
555554
}
556555

test/test_instruction_replication.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ struct Fixture {
3131
, sg_1(DB::create(*history_1, path_1))
3232
, sg_2(DB::create(*history_2, path_2))
3333
{
34-
// This is to ensure that peer IDs in Object IDs are populated.
35-
bool fix_up_object_ids = true;
36-
history_1->get_history().set_client_file_ident({1, 123}, fix_up_object_ids);
34+
history_1->get_history().set_client_file_ident({1, 123});
3735
}
3836

3937
void replay_transactions()

test/test_sync.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -6578,7 +6578,7 @@ TEST(Sync_DanglingLinksCountInPriorSize)
65786578
ClientReplication repl;
65796579
auto local_db = realm::DB::create(repl, path);
65806580
auto& history = repl.get_history();
6581-
history.set_client_file_ident(sync::SaltedFileIdent{1, 123456}, true);
6581+
history.set_client_file_ident(sync::SaltedFileIdent{1, 123456});
65826582

65836583
version_type last_version, last_version_observed = 0;
65846584
auto dump_uploadable = [&] {
@@ -6853,7 +6853,7 @@ TEST(Sync_NonIncreasingServerVersions)
68536853
TEST_CLIENT_DB(db);
68546854

68556855
auto& history = get_history(db);
6856-
history.set_client_file_ident(SaltedFileIdent{2, 0x1234567812345678}, false);
6856+
history.set_client_file_ident(SaltedFileIdent{2, 0x1234567812345678});
68576857
timestamp_type timestamp{1};
68586858
history.set_local_origin_timestamp_source([&] {
68596859
return ++timestamp;
@@ -6926,7 +6926,7 @@ TEST(Sync_InvalidChangesetFromServer)
69266926
TEST_CLIENT_DB(db);
69276927

69286928
auto& history = get_history(db);
6929-
history.set_client_file_ident(SaltedFileIdent{2, 0x1234567812345678}, false);
6929+
history.set_client_file_ident(SaltedFileIdent{2, 0x1234567812345678});
69306930

69316931
instr::CreateObject bad_instr;
69326932
bad_instr.object = InternString{1};
@@ -7004,7 +7004,7 @@ TEST(Sync_SetAndGetEmptyReciprocalChangeset)
70047004
TEST_CLIENT_DB(db);
70057005

70067006
auto& history = get_history(db);
7007-
history.set_client_file_ident(SaltedFileIdent{1, 0x1234567812345678}, false);
7007+
history.set_client_file_ident(SaltedFileIdent{1, 0x1234567812345678});
70087008
timestamp_type timestamp{1};
70097009
history.set_local_origin_timestamp_source([&] {
70107010
return ++timestamp;
@@ -7173,7 +7173,7 @@ TEST(Sync_ServerVersionsSkippedFromDownloadCursor)
71737173
TEST_CLIENT_DB(db);
71747174

71757175
auto& history = get_history(db);
7176-
history.set_client_file_ident(SaltedFileIdent{2, 0x1234567812345678}, false);
7176+
history.set_client_file_ident(SaltedFileIdent{2, 0x1234567812345678});
71777177
timestamp_type timestamp{1};
71787178
history.set_local_origin_timestamp_source([&] {
71797179
return ++timestamp;

0 commit comments

Comments
 (0)