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

RCORE-2212 Make apply-to-state tool handle all batch states properly #7938

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
23 changes: 21 additions & 2 deletions src/realm/sync/tools/apply_to_state_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ DownloadMessage DownloadMessage::parse(HeaderLineParser& msg, Logger& logger, bo
if (is_flx_sync) {
ret.query_version = msg.read_next<int64_t>();
ret.batch_state = static_cast<sync::DownloadBatchState>(msg.read_next<int>());
switch (ret.batch_state) {
case realm::sync::DownloadBatchState::SteadyState:
case realm::sync::DownloadBatchState::MoreToCome:
case realm::sync::DownloadBatchState::LastInBatch:
break;
default:
throw ProtocolCodecException(
util::format("invalid batch state in download msg: %1", static_cast<int>(ret.batch_state)));
}
}
else {
ret.query_version = 0;
Expand Down Expand Up @@ -294,11 +303,21 @@ int main(int argc, const char** argv)
mpark::visit(realm::util::overload{
[&](const DownloadMessage& download_message) {
realm::sync::VersionInfo version_info;
auto transact = bool(flx_sync_arg) ? local_db->start_write() : local_db->start_read();
TransactionRef tr;
switch (download_message.batch_state) {
case realm::sync::DownloadBatchState::SteadyState:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it OK that these changes aren't backwards compatible with sync messages from before sync protocol version 14? I am assuming so, since the history.integrate_server_changesets() function isn't going to work with older messages since it is explicitly looking for the DownloadBatchState::SteadyState value that was introduced in version 14.

Perhaps we should include the get_current_protocol_version() output in the help text to indicate which protocol version "should" be supported?

tr = local_db->start_read();
break;
case realm::sync::DownloadBatchState::LastInBatch:
[[fallthrough]];
case realm::sync::DownloadBatchState::MoreToCome:
tr = local_db->start_write();
break;
}
history.integrate_server_changesets(download_message.progress,
download_message.downloadable_bytes,
download_message.changesets, version_info,
download_message.batch_state, *logger, transact);
download_message.batch_state, *logger, tr);
},
[&](const UploadMessage& upload_message) {
for (const auto& changeset : upload_message.changesets) {
Expand Down
Loading