1 create or replace function merge_servers(p_winner_server_id servers.server_id%TYPE, p_loser_server_id servers.server_id%TYPE)
9 raise notice 'Merging servers % and %', p_winner_server_id, p_loser_server_id;
11 select * into w_server from servers where server_id = p_winner_server_id;
12 select * into l_server from servers where server_id = p_loser_server_id;
14 -- hashkey check: if both have hashkeys and they are different, we
15 -- shouldn't merge them!
16 if w_server.hashkey is not null and l_server.hashkey is not null and w_server.hashkey != l_server.hashkey then
17 raise exception 'Both servers have hashkeys and they are different! Not merging.';
20 -- fill in the hashkey (everything else will be handled by xonstat)
21 if w_server.hashkey is null and l_server.hashkey is not null then
22 w_server.hashkey := l_server.hashkey;
25 -- games get moved to the new server
26 update games set server_id = p_winner_server_id where server_id = p_loser_server_id;
28 get diagnostics rowcount = ROW_COUNT;
29 raise notice '% game rows updated.', rowcount;
31 -- update attributes rescued from the losing server
33 ip_addr = w_server.ip_addr,
34 hashkey = w_server.hashkey,
35 revision = w_server.revision
36 where server_id = p_winner_server_id;
38 -- now deactivate the old server
39 update servers set active_ind = false where server_id = p_loser_server_id;
41 raise notice 'Server #% deactivated.', p_loser_server_id;
43 insert into merged_servers(winning_server_id, losing_server_id) values(p_winner_server_id, p_loser_server_id);