@@ -163,6 +163,12 @@ fn merge_games(curr_game_id: GameId, prev_game_id: Option<GameId>, state: &mut S
163
163
164
164
let server_id = match prev_game_id {
165
165
Some ( prev_game_id) if prev_game_id < curr_game_id => {
166
+ println ! (
167
+ "[info] [updater] merging games {} and {} (`{}` and `{}`)" ,
168
+ prev_game_id, curr_game_id,
169
+ state. get_game_name( prev_game_id) , state. get_game_name( curr_game_id)
170
+ ) ;
171
+
166
172
let prev_game = state. get_game_mut ( prev_game_id) ;
167
173
assert ! ( prev_game. time_end. is_some( ) ) ;
168
174
// todo: что если prev_game.next_game_id != None (мб такое возможно при приостановке)
@@ -173,7 +179,7 @@ fn merge_games(curr_game_id: GameId, prev_game_id: Option<GameId>, state: &mut S
173
179
let server_id = state. game_ids . iter ( )
174
180
. position ( |& game_id| game_id == prev_game_id)
175
181
// prev_game_id был добавлен в state.game_ids когда происходило объединение множеств {...} и {..., prev_game_id}
176
- . unwrap ( ) ;
182
+ . unwrap_or_else ( || panic ! ( "Can't find prev game: prev_game_id={}, curr_game_id={}" , prev_game_id , curr_game_id ) ) ;
177
183
state. game_ids [ server_id] = curr_game_id;
178
184
server_id
179
185
}
@@ -251,9 +257,10 @@ fn try_merge_host(prev_game_ids_host: &[GameId], curr_game_ids_host: &[GameId],
251
257
} else {
252
258
let get_game_name = |& game_id: & GameId , state : & State | state. get_game_name ( game_id) . to_owned ( ) ;
253
259
let get_game_host = |& game_id: & GameId , state : & State | state. get_game_host ( game_id) . unwrap ( ) . to_owned ( ) ;
254
- let matched_by_name = try_match_by_property ( & prev_game_ids_host, & curr_game_ids_host, state, get_game_name) ;
255
- let matched_by_host = try_match_by_property ( & prev_game_ids_host, & curr_game_ids_host, state, get_game_host) ;
256
- let matched = matched_by_name || matched_by_host;
260
+ // It is extremely important that we call second [try_match_by_property] only if first returns false
261
+ let matched = false
262
+ || try_match_by_property ( & prev_game_ids_host, & curr_game_ids_host, state, get_game_name)
263
+ || try_match_by_property ( & prev_game_ids_host, & curr_game_ids_host, state, get_game_host) ;
257
264
if !matched {
258
265
eprintln ! ( "[warn] [updater] can't match games: {:?} with {:?}" , prev_game_ids_host, curr_game_ids_host) ;
259
266
for game_id in curr_game_ids_host {
@@ -278,11 +285,17 @@ pub fn try_merge_host_ids(updater_state: &mut UpdaterState, state: &mut State, t
278
285
let curr_game_ids_host = curr_game_ids_by_host. get ( & host_id) ;
279
286
if curr_game_ids_host. is_none ( ) {
280
287
// новых game_id не появилось: нечего объединять
288
+ println ! ( "[info] [updater] host {}: merge failed - no new games" , base64:: encode( host_id) ) ;
281
289
return None ;
282
290
}
283
291
let curr_game_ids_host = curr_game_ids_host. unwrap ( ) ;
284
292
293
+ println ! (
294
+ "[info] [updater] host {}: merging games {:?} and {:?}" ,
295
+ base64:: encode( host_id) , prev_game_ids_host, curr_game_ids_host
296
+ ) ;
285
297
if try_merge_host ( prev_game_ids_host, curr_game_ids_host, state) {
298
+ println ! ( "[info] [updater] host {}: merge successful" , base64:: encode( host_id) ) ;
286
299
if time. get ( ) - merge_info. time_begin . get ( ) > 24 * 60 /* 1 day */ {
287
300
eprintln ! ( "[error] [updater] host {} waited merge too long: {:?}-{:?}" ,
288
301
base64:: encode( host_id) , merge_info. time_begin, merge_info. time_end) ;
0 commit comments