function main($server_cfg) { $options = get_options(); if (isset($options['g']) && $options['g'] !== '') { $game_names = explode(",", $options['g']); } else { $game_names = $server_cfg['game_list']; } $time_slots = null; if (!empty($options['t'])) { $time_slots = $options['t']; } $timestamp = $_SERVER['REQUEST_TIME']; $current_time_slot = (int) ($timestamp / (30 * 60)); foreach ($game_names as $game_name) { zpm_preamble($game_name); // MODIFIED!!!! Create and mount next two timeslots !!! $game_cfg = load_game_config($game_name); if (!$game_cfg) { error_log("configuration for " . $game_name . " is not loaded\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); continue; } $target_dir = sprintf($server_cfg['root_upload_directory'], $game_cfg["name"]); $target_dir = $target_dir . "/%s/" . $server_cfg["profile_upload_directory"]; $dir_name_array = create_directory($target_dir, $current_time_slot, $server_cfg, $game_cfg); if ($dir_name_array === null) { error_log("Directory creation failed for the game " . $game_cfg['name'], 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); continue; } if ($dir_name_array === 0) { error_log("No Ram disk Exist!!!" . $game_cfg['name'], 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); } //creating new games and getting the list of web arrays to process data for $rs = new RightScale($server_cfg, load_game_config($game_name)); $rs->make_array_games(); $array_ids = $rs->get_arrays_to_serve(); // // Wrap processing for each game inside a file lock // $game_lock_file = sprintf($server_cfg["zperfmon_lock_file"], $game_name); $game_lock_handle = grab_lock($game_lock_file, $server_cfg, $game_cfg); if (!$game_lock_handle) { error_log("Could not get exclusive lock for \"{$game_name}\"\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); delete_ramdisk_data($game_name, $time_slots, $timestamp, $server_cfg, $game_cfg); continue; } //processing parent game try { // // process uploaded data // run_cron_for_game($server_cfg, $game_cfg, $time_slots); } catch (Exception $e) { error_log("Upload processing for {$game_name} failed\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); error_log("Exception says: " . $e->getMessage() . "\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); } // loop to process data for each web array foreach ($array_ids as $array) { try { $game_cfg = load_game_config($game_name, $array); if (!$game_cfg) { error_log("configuration for " . $game_name . " is not loaded\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); continue; } // // process uploaded data // run_cron_for_game($server_cfg, $game_cfg, $time_slots); } catch (Exception $e) { error_log("Upload processing for {$game_name} failed\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); error_log("Exception says: " . $e->getMessage() . "\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name'])); } } // compress for parent game // This implementation forces us to always pass a timeslot // while calling this script. otherwise compression will fail. $game_cfg = load_game_config($game_name); compress_unziped_profiles($server_cfg, $game_cfg, $time_slots); // Now compress the array games foreach ($array_ids as $array) { $game_cfg = load_game_config($game_name, $array); compress_unziped_profiles($server_cfg, $game_cfg, $time_slots); } // cleanup the lock drop_lock($game_lock_handle, $game_lock_file); zpm_postamble($game_name); //MODIFIED!!!! if ($dir_name_array != 0) { delete_ramdisk_data($game_name, $time_slots, $timestamp, $server_cfg, $game_cfg); } } }
function partition_dynamics($game_names, $server_cfg, $con, $log_file) { //Month to Partition map $partition_drop_map = array('p001', 'p002', 'p003', 'p004', 'p005', 'p006', 'p001', 'p002', 'p003', 'p004', 'p005', 'p006'); //Current month to retention month p_tag map. $cursor_retain_months = array(11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $month_index = date('m') - 1; $array_drop_index = $month_index - 2; //If array drop index is negative go to the end of array if ($array_drop_index < 0) { $array_drop_index = 12 + $array_drop_index; } $partition_drop_array_games = $partition_drop_map[$array_drop_index]; foreach ($game_names as $game) { $db = "zprf_" . $game; report_partitions_state($db, $con, $log_file); $cursor_retain = $cursor_retain_months[$month_index]; $cursor_delete = 0 - $cursor_retain; //Deleting rows in the ratio 1:4 delete_rows($cursor_delete, $db, $con, $log_file); //Doing an alter table crunch_space($db, $con, $log_file); //Fetching the retention time from game_cfg file $game_cfg = load_game_config($game); $retention_time = $game_cfg["xhprof_retention_time"]; //Maximum retention time = 4 months //If retention time not specified setting the default retention time as 4 months if ($retention_time == NULL or $retention_time > 4) { $retention_time = 4; } $partition_drop_index = $month_index - $retention_time - 1; if ($partition_drop_index < 0) { $partition_drop_index = 12 + $partition_drop_index; } $partition_drop = $partition_drop_map[$partition_drop_index]; $rs = new RightScale($server_cfg, load_game_config($game)); $array_ids = $rs->get_arrays_to_serve(); drop_partition_data($partition_drop, $partition_drop_array_games, $array_ids, $db, $con, $log_file); } }