qioerr hdfs_locales_for_range(void* file, off_t start_byte, off_t end_byte, const char*** loc_names_out, int* num_locs_out, void* fs) { int i = 0; int j = 0; char*** info = NULL; info = hdfsGetHosts(to_hdfs_fs(fs)->hfs, to_hdfs_file(file)->pathnm, start_byte, end_byte); // unable to get hosts for this byte range if (!info || !info[0]) { *num_locs_out = 0; hdfsFreeHosts(info); QIO_RETURN_CONSTANT_ERROR(EREMOTEIO, "Unable to get owners for byterange"); } while(info[0][i]) { info[0][i] = get_locale_name(info[0][i]); i++; } *num_locs_out = i - 1; *loc_names_out = (const char**)info[0]; // Free the other hosts that we don't need for (i = 1; info[i]; i++) { for (j = 0; info[i][j]; j++) qio_free(info[i][j]); qio_free(info[i]); } return 0; }
qioerr hdfs_get_owners_for_bytes(qio_file_t* file, hdfs_block_byte_map_t** locs, int* out_num_blocks, char** locale_array, int num_locales, off_t start_byte, off_t len) { int i; int j = 0; int k; qioerr err = 0; char* tmp; int rnd; int block_count = 0; hdfs_block_byte_map_t* loc = NULL; char*** info = NULL; hdfsFileInfo* f_info = hdfsGetPathInfo(to_hdfs_fs(file->fs_info)->hfs, to_hdfs_file(file->file_info)->pathnm); if (start_byte == 0 && len == -1) // We want the whole thing info = hdfsGetHosts(to_hdfs_fs(file->fs_info)->hfs, to_hdfs_file(file->file_info)->pathnm, start_byte, f_info->mSize); else info = hdfsGetHosts(to_hdfs_fs(file->fs_info)->hfs, to_hdfs_file(file->file_info)->pathnm, start_byte, start_byte + len); while(info[block_count] != NULL) { // Get the number of blocks that we have block_count++; } loc = (hdfs_block_byte_map_t*)qio_calloc(sizeof(hdfs_block_byte_map_t), block_count); CREATE_ERROR((!info), err, EREMOTEIO, "Unable to get host for HDFS", end); for (i = 0; info[i] != NULL; i++) { // Assign block owners rnd = rand() % f_info->mReplication; // pick an owner if (info[i][rnd]) {// Valid access tmp = get_locale_name(info[i][rnd]); // strip off .___ for (k = 0; k < num_locales; k++) { // Now find the owner if (strcmp(tmp, locale_array[k]) == 0) { loc[i].locale_id = k; // return locale ID for that name break; } } loc[i].start_byte = (off_t)(i*f_info->mBlockSize); loc[i].len = (off_t)(f_info->mBlockSize); j++; } else { QIO_GET_CONSTANT_ERROR(err, EINVAL, "Unable to find address for blocks in hdfs_get_owners_for_bytes"); qio_free(loc); *locs = NULL; *out_num_blocks = 0; goto end; } } *locs = loc; *out_num_blocks = j; end: return err; }
static void ls_build_menu (GOLocaleSel *ls) { GtkWidget *item; GtkMenu *menu; LGroupInfo const *lgroup = lgroups; gint lg_cnt = 0; menu = GTK_MENU (gtk_menu_new ()); while (lgroup->group_name) { LocaleInfo const *locale_trans; GtkMenu *submenu = NULL; locale_trans = locale_trans_array; while (locale_trans->lgroup != LG_LAST) { if (locale_trans->lgroup == lgroup->lgroup && locale_trans->available) { GtkWidget *subitem= gtk_check_menu_item_new_with_label (_(locale_trans->locale_title)); if (!submenu) submenu = GTK_MENU (gtk_menu_new ()); gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (subitem), TRUE); gtk_widget_show (subitem); gtk_menu_shell_append (GTK_MENU_SHELL (submenu), subitem); g_object_set_data (G_OBJECT (subitem), LOCALE_NAME_KEY, (locale_trans->actual_locale)); } locale_trans++; } if (submenu) { GtkWidget *item = gtk_menu_item_new_with_label (_(lgroup->group_name)); gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), GTK_WIDGET (submenu)); gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); lg_cnt++; } lgroup++; } item = gtk_separator_menu_item_new (); gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); lg_cnt++; { char *locale_name = get_locale_name (ls); char *locale_menu_title = g_strconcat (_("Current Locale: "), locale_name, NULL); g_free (locale_name); item = gtk_check_menu_item_new_with_label (locale_menu_title); gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (item), TRUE); g_free (locale_menu_title); gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); lg_cnt++; } go_option_menu_set_menu (ls->locales, GTK_WIDGET (menu)); ls->locales_menu = menu; set_menu_to_default (ls, lg_cnt); }