void print_result(){ if(FIXAGE_MODE == FALSE){ if(EDGE_LENS_ARE_INTEGERS == FALSE) { dprint(RES_FILE,"\nWarning -- not every edge len was an integer -- no statistical test could be performed."); dprint(RES_FILE,"\n %s indicates non computable statistical data.\n\n\n", STAT_MISSING); dprint(RES_FILE,"Clock test confidence: %s\n", STAT_MISSING); dprint(RES_FILE,"Clock tests : %s\n", STAT_MISSING); dprint(RES_FILE,"Accepted : %s\n", STAT_MISSING); dprint(RES_FILE,"Rejected : %s\n", STAT_MISSING); } else { dprint(RES_FILE,"Clock test confidence: %f\n", PROB_LIMIT); dprint(RES_FILE,"Clock tests : %d (one for each node)\n",T->num_of_rejected+T->num_of_accepted); dprint(RES_FILE,"Accepted : %d\n",T->num_of_accepted); dprint(RES_FILE,"Rejected : %d\n",T->num_of_rejected); } } else{ dprint(RES_FILE,"Number of informative fixnodes: %3d\n", NUM_FIX); dprint(RES_FILE,"Number of informative minnodes: %3d\n", NUM_MIN); dprint(RES_FILE,"Number of informative maxnodes: %3d\n", NUM_MAX); } dprint(RES_FILE,"\n"); if( PRINT_NEWICK == TRUE ){ if(FIXAGE_MODE == FALSE){ //dprint(RES_FILE,"Input tree : "); print_nodes(T->root,PM_INPUT); // Internal name is mpl_pos, external name mpl //dprint(RES_FILE,"MPL tree %-2.2s: ",MPL_TREE_FOOTNOTE_MARK); print_nodes(T->root,PM_MPLPOS); dprint(RES_FILE,"MPL tree : "); print_nodes(T->root,PM_MPLPOS); } else { dprint(RES_FILE,"d8 tree : "); print_nodes(T->root,PM_MPLD8); } dprint(RES_FILE,"\n"); } if(PRINT_ANCESTOR == TRUE ){ if( FIXAGE_MODE == FALSE){ print_ancestor(T->root); // printf("\n\n"); //printf("%3s) %s\n","*","Tree is build with mean path len. If child is older than mother, then child's age is replaced with mother's." } else{ print_ancestor_age(T->root); dprint(RES_FILE , "\n\n"); dprint(RES_FILE , "%3s) %s\n","*","Rate = MPL / Age"); } } }
int main(void) { // offer the user two options while (true) { printf("Please choose an option (0, 1, 2): "); int option = GetInt(); switch (option) { // quit case 0: free_nodes(head); printf("Goodbye!\n"); return 0; // insert int into linked list case 1: printf("Please enter an int: "); int v = GetInt(); char* success = insert_node(v) ? "was" : "was not"; printf("The insert %s successful.\n", success); break; // print all ints case 2: print_nodes(head); break; default: printf("Not a valid option.\n"); break; } } }
static void test_parse_nodestring(const char *nodestring_s, const char *dd_ok_s) { const char *nodestring; bool dd_ok; struct ctdb_context *ctdb; uint32_t *nodes; uint32_t pnn_mode; nodestring = strcmp("", nodestring_s) == 0 ? NULL : nodestring_s; if (strcasecmp(dd_ok_s, "yes") == 0 || strcmp(dd_ok_s, "true") == 0) { dd_ok = true; } else { dd_ok = false; } ctdb = talloc_zero(NULL, struct ctdb_context); ctdb_test_stubs_read_nodemap(ctdb); if (parse_nodestring(ctdb, NULL, nodestring, CTDB_CURRENT_NODE, dd_ok, &nodes, &pnn_mode)) { print_nodes(nodes, pnn_mode); } talloc_free(ctdb); }
int main( int argc,char** argv ) { int arr[] = { 1,2,3,4,5 } ; node* head;// = (node*)0;//= ( node* )malloc( sizeof( node ) ) ; head = initialize_list( head,arr,5 ) ; print_nodes( head ) ; return 0 ; }
void print_node_sets(nodemetaset_t const* node_metaset) { for(nodemetaset_it i = node_metaset->begin(); i != node_metaset->end(); i++) { printf("\t"); print_nodes(&(*i)); printf("\n"); } }
static void lockspace_status(struct lockspace *ls, const char *status) { if (debug) { printf("Lockspace %s %s: stopping=", ls->name, status); print_nodes(stdout, ls->stopping); printf(", stopped="); print_nodes(stdout, ls->stopped); printf(", joining="); print_nodes(stdout, ls->joining); printf(", leaving="); print_nodes(stdout, ls->leaving); printf(", members="); print_nodes(stdout, ls->members); printf("\n"); fflush(stdout); } }
int main (int argc, char **argv) { options opts; prog_name = basename (argv[0]); int check = 1; scan_options(argc, argv, &opts); if(opts.print_debug == true) check = 2; if(argc == check){ scanString(); print_nodes(head, &opts); } return exit_status; }
int main() { insert_node("10.0.0.13", "Casper"); insert_node("192.168.2.13", "Maria"); insert_node("10.0.0.17", "Bertram"); insert_node("10.0.0.19", "Harald"); insert_node("10.0.0.13", "Casper"); print_nodes(); return 0; }
int main() { int N; int Q; int i; str_lst_t *strings; char **queries; fprintf(stderr, "Let's begin\n"); scanf("%d\n", &N); fprintf(stderr, "N=%d\n", N); strings = malloc(sizeof(*strings)); memset(strings, 0, sizeof(*strings)); for (i = 0; i < N; i++) { char str[STR_MAX]; scanf("%20s\n", str); strings->next = add_inc_str(strings->next, str); } scanf("%d\n", &Q); fprintf(stderr, "Q=%d\n", Q); queries = calloc(Q, sizeof(char*)); if (queries == 0) { perror("Query array allocation failed\n"); } for (i = 0; i < Q; i++) { queries[i] = (char*)malloc(sizeof(char) * STR_MAX); scanf("%20s\n", queries[i]); } for (i = 0; i < Q; i++) { str_lst_t *found = find_node(strings->next, queries[i]); if (found) { fprintf(stdout, "%d\n", found->count); } else { fprintf(stdout, "%d\n", 0); } } print_nodes(strings->next); /* cleanup */ while (strings) { str_lst_t *next = strings->next; free(strings); strings = next; } for (i = 0; i < Q; i++) { free(queries[i]); } free(queries); return 0; }
static void mesh_generate(){ // double ppwl = param->factor / param->freq; // double myfactor = param->factor; Octree tree = octor_newtree(); tree.root = refine_tree(&tree.root, &toexpand, &query_model); vector<Element> elements; unordered_map<int , Node> nodes; elements = traverse_tree(&tree.root, elements); print_vector(elements, "/Users/kelicheng/Desktop/mymesh.txt"); nodes = extract_mesh(elements); print_nodes(nodes, "/Users/kelicheng/Desktop/mynodes.txt"); }
/* * Find ID in p, and assign q to all matching values */ void _union(int p, int q, int *nodes, int size) { int pid = nodes[p]; int qid = nodes[q]; printf("Union P(%d,%d) Q(%d,%d) ", p, pid, q, qid); for(int i = 0; i < size; i++) { if(*(nodes + i) == pid) { *(nodes + i) = qid; } } print_nodes(nodes, size); }
int main(void) { int nodes[10]; printf("Node count: %d\n", NODE_COUNT); initialize_nodes(nodes, NODE_COUNT); print_nodes(nodes, NODE_COUNT); _union(3, 4, nodes, NODE_COUNT); _union(4, 1, nodes, NODE_COUNT); printf("%d\n", connected(1, 3, nodes)); printf("%d\n", connected(1, 7, nodes)); return 0; }
int main (int argc, char **argv) { options opts; prog_name = basename (argv[0]); int check = 1; scan_options(argc, argv, &opts); if(opts.print_debug == true) check = 2; if(argc == check){ scanNum(); print_nodes(head, &opts); } else{ for (int argi = check; argi < argc; ++argi) { char *filename = argv[argi]; if (strcmp (filename, STDIN_NAME) == 0) { scanNum(); print_nodes(head, &opts); }else { FILE *input = fopen (filename, "r"); if (input != NULL) { scanNum(); print_nodes(head, &opts); fclose (input); }else { //If the file is empty //Print error message exit_status = EXIT_FAILURE; fflush (NULL); fprintf (stderr, "%s: %s: %s\n", prog_name, filename, strerror (errno)); fflush (NULL); } } } } return exit_status; }
static int getj(int16_t id) { int myj; for(myj = 0; myj < totalNodes; myj++){ if(topo_array[myj].id == id) break; } if( myj == totalNodes ){ fprintf(stderr, "myj is not found\n"); fprintf(stderr, "nid = %d\n", id); print_nodes(); exit(1); } return myj; }
int main (int argc, char *argv[]) { struct wifi_interface wi; if (argc != 3) return usage(argv[0]); if (wifi_interface(&wi, argv[1])) return 2; if (!strcmp("scan", argv[2])) { int err = 0; err |= wifi_scan(&wi); print_nodes(&wi); err |= wifi_interface_close(&wi); return err; } return 0; }
/** * Pretty formatting of a binary tree to the output stream * * Parameters: * fp FILE * to print to. Just use 'stdout' if you are unsure. * root Root of Huffman Coding Tree that we're printing * level Control how wide you want the tree to sparse (eg, level 1 has * the minimum space between nodes, while level 2 has a larger * space between nodes) * indent Change this to add some indent space to the left (eg, * indent of 0 means the lowest level of the left node will * stick to the left margin) */ static void HuffNode_printPretty_Worker(FILE * fp, HuffNode * root, int level, int indent) { int r, i; // for-loop indices int h = HuffNode_height(root); // eq of the length of branch for each node of each level int branch_sz = 2*((1 << h) - 1) - (3-level)*(1 << (h-1)); // distance between left neighbor node's right arm and right neighbor // node's left arm int node_spacing_sz = 2 + (level+1)*(1 << h); // starting space to the first node to print of each level // (for the left most node of each level only) int start_sz = branch_sz + (3-level) + indent; Queue * Q = Queue_create(); Queue_pushBack(Q, root); int curr_tree_width = 1; for (r = 1; r < h; r++) { print_branches(fp, Q, branch_sz, node_spacing_sz, start_sz, curr_tree_width); branch_sz = branch_sz / 2 - 1; node_spacing_sz = node_spacing_sz / 2 + 1; start_sz = branch_sz + (3-level) + indent; print_nodes(fp, Q, branch_sz, node_spacing_sz, start_sz, curr_tree_width); for (i = 0; i < curr_tree_width; i++) { HuffNode * currNode = Queue_popFront(Q); if(currNode) { Queue_pushBack(Q, currNode->left); Queue_pushBack(Q, currNode->right); } else { Queue_pushBack(Q, NULL); Queue_pushBack(Q, NULL); } } curr_tree_width *= 2; } print_branches(fp, Q, branch_sz, node_spacing_sz, start_sz, curr_tree_width); print_leaves(fp, Q, indent, level, curr_tree_width); Queue_destroy(Q); }
void CloudBus::send_node_info() { size_t buf_len = calculate_node_info_length(node_info_); try { char* buffer = new char[4+4+buf_len]; *((uint32_t*)buffer) = buf_len+4; *((uint32_t*)(buffer + 4)) = GADGETRON_CLOUDBUS_NODE_INFO; if (connected_) { serialize(node_info_,buffer + 8,buf_len); this->peer().send_n(buffer,buf_len+8); } delete [] buffer; } catch (...) { GERROR("Failed to send gadgetron node info\n"); throw; } print_nodes(); }
/** * @brief PROCESS_THREAD */ PROCESS_THREAD(output_process, ev, data){ PROCESS_BEGIN(); while(1){ PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE); char *cmd_str = (char*)data; if(cmd_str == NULL){ //if(list_access_flag == 0){ // list_access_flag = 1; COOJA_DEBUG_PRINTF(">:%d,%d,%u,%u,%u,%u,%u,%u\n", rounds_counter, rimeaddr_node_addr.u8[0], CHANNEL_SIZE, curr_frac_nodes/*neighs_xhops(1)*/, curr_frac_nodes,get_discovery_time(), energy_usage(),period_length); list_access_flag = 0; //} }else{ if(!strcmp(cmd_str, "energyPrint")){ //if(list_access_flag == 0){ // list_access_flag = 1; //print_nodes(1); // list_access_flag = 0; //} COOJA_DEBUG_PRINTF("EN>:%d,%d,%u,%u,%u,%u,%u,%u,%u,%u\n", rounds_counter, rimeaddr_node_addr.u8[0], CHANNEL_SIZE, curr_frac_nodes, curr_frac_nodes,get_discovery_time(), energy_usage(),energy_usage_period(), get_node_period(), curr_frac_nodes); energy_per_period = 0; extra_probe_per_period = 0; } if(!strcmp(cmd_str, "h2_output")){ print_nodes(0); } } } //END WHILE(1) PROCESS_END(); }
int main() { lnode *node; pthread_t tid1, tid2; int i; gettimeofday(&begintime, NULL); node = (lnode *)malloc(sizeof(lnode)); node->next = NULL; node->tid = -1; pthread_create(&tid1, NULL, browse_nodes, node); pthread_create(&tid2, NULL, browse_nodes, node); pthread_mutex_lock(&mutex); for(i = 0; i < 2; i++) { insert_node(node, tid1); insert_node(node, tid2); } insert_node(node, tid1); pthread_mutex_unlock(&mutex); pthread_mutex_lock(&mutex); insert_node(node, tid2); pthread_mutex_unlock(&mutex); pthread_join(tid1, NULL); pthread_join(tid2, NULL); pthread_mutex_destroy(&mutex); print_nodes(node); printf("main thread done\n"); return 0; }
/* * Request to add / join a lockspace. * * This event is triggered by DLM_USER_CREATE_LOCKSPACE requests by the user * (via libdlm). * * Stop the lockspace on all nodes in the cluster, join the lockspace, and * start the lockspace locally with: * * echo 1 > /sys/kernel/dlm/<name>/control * * Complete the uevent with: * * echo 0 > /sys/kernel/dlm/<name>/event_done */ static void lockspace_online_uevent(const char *name) { struct lockspace *ls; struct node *node; bool sent = false; ls = find_lockspace(name); if (!ls) ls = new_lockspace(name); if (connected_nodes != all_nodes) { /* Refuse to create lockspaces when not fully connected. */ fprintf(stderr, "Not joining lockspace '%s': " "not connected to node(s) ", name); print_nodes(stderr, all_nodes & ~connected_nodes); fprintf(stderr, "\n"); fflush(stderr); printf_pathf("%d", "%s/%s/event_done", EBUSY, DLM_SYSFS_DIR, ls->name); return; } if (ls->members & node_mask(local_node)) { fprintf(stderr, "Already in lockspace '%s'\n", name); fflush(stderr); printf_pathf("%d", "%s/%s/event_done", 0, DLM_SYSFS_DIR, ls->name); return; } printf("Joining lockspace '%s' [%04x]\n", ls->name, ls->global_id); fflush(stdout); /* (Lockspace not started, yet.) */ ls->joining |= node_mask(local_node); for (node = nodes; node; node = node->next) { if (node == local_node) continue; sent |= send_msg(node, MSG_STOP_LOCKSPACE, name); } if (!sent) update_lockspace(ls); }
static int be_do_list(int argc, char **argv) { be_node_list_t *be_nodes = NULL; boolean_t all = B_FALSE; boolean_t dsets = B_FALSE; boolean_t snaps = B_FALSE; boolean_t parsable = B_FALSE; int err = 1; int c = 0; char *be_name = NULL; be_sort_t order = BE_SORT_UNSPECIFIED; while ((c = getopt(argc, argv, "adk:svHK:")) != -1) { switch (c) { case 'a': all = B_TRUE; break; case 'd': dsets = B_TRUE; break; case 'k': case 'K': if (order != BE_SORT_UNSPECIFIED) { (void) fprintf(stderr, _("Sort key can be " "specified only once.\n")); usage(); return (1); } if (strcmp(optarg, "date") == 0) { if (c == 'k') order = BE_SORT_DATE; else order = BE_SORT_DATE_REV; break; } if (strcmp(optarg, "name") == 0) { if (c == 'k') order = BE_SORT_NAME; else order = BE_SORT_NAME_REV; break; } if (strcmp(optarg, "space") == 0) { if (c == 'k') order = BE_SORT_SPACE; else order = BE_SORT_SPACE_REV; break; } (void) fprintf(stderr, _("Unknown sort key: %s\n"), optarg); usage(); return (1); case 's': snaps = B_TRUE; break; case 'v': libbe_print_errors(B_TRUE); break; case 'H': parsable = B_TRUE; break; default: usage(); return (1); } } if (all) { if (dsets) { (void) fprintf(stderr, _("Invalid options: -a and %s " "are mutually exclusive.\n"), "-d"); usage(); return (1); } if (snaps) { (void) fprintf(stderr, _("Invalid options: -a and %s " "are mutually exclusive.\n"), "-s"); usage(); return (1); } dsets = B_TRUE; snaps = B_TRUE; } argc -= optind; argv += optind; if (argc == 1) be_name = argv[0]; err = be_list(be_name, &be_nodes); switch (err) { case BE_SUCCESS: /* the default sort is ascending date, no need to sort twice */ if (order == BE_SORT_UNSPECIFIED) order = BE_SORT_DATE; if (order != BE_SORT_DATE) { err = be_sort(&be_nodes, order); if (err != BE_SUCCESS) { (void) fprintf(stderr, _("Unable to sort Boot " "Environment\n")); (void) fprintf(stderr, "%s\n", be_err_to_str(err)); break; } } print_nodes(be_name, dsets, snaps, parsable, be_nodes); break; case BE_ERR_BE_NOENT: if (be_name == NULL) (void) fprintf(stderr, _("No boot environments found " "on this system.\n")); else { (void) fprintf(stderr, _("%s does not exist or appear " "to be a valid BE.\nPlease check that the name of " "the BE provided is correct.\n"), be_name); } break; default: (void) fprintf(stderr, _("Unable to display Boot " "Environment\n")); (void) fprintf(stderr, "%s\n", be_err_to_str(err)); } if (be_nodes != NULL) be_free_list(be_nodes); return (err); }
int main(int argc, char *argv[]) { librdf_world* world; librdf_parser* parser; librdf_serializer* serializer; librdf_storage *storage; librdf_model* model; librdf_node *source, *arc, *target, *node; librdf_node *subject, *predicate, *object; librdf_node* context_node=NULL; librdf_stream* stream; librdf_iterator* iterator; librdf_uri *uri; librdf_uri *base_uri=NULL; librdf_query *query; librdf_query_results *results; librdf_hash *options; int count; int rc; int transactions=0; const char* storage_name; const char* storage_options; const char* context; const char* identifier; const char* results_format; librdf_statement* statement=NULL; char* query_cmd=NULL; char* s; /* * Initialize */ storage_name="virtuoso"; results_format="xml"; context=DEFAULT_CONTEXT; identifier=DEFAULT_IDENTIFIER; /* * Get connection options */ if(argc == 2 && argv[1][0] != '\0') storage_options=argv[1]; else if((s=getenv ("VIRTUOSO_STORAGE_OPTIONS")) != NULL) storage_options=s; else storage_options=DEFAULT_STORAGE_OPTIONS; world=librdf_new_world(); librdf_world_set_logger(world, world, log_handler); librdf_world_open(world); options=librdf_new_hash(world, NULL); librdf_hash_open(options, NULL, 0, 1, 1, NULL); librdf_hash_put_strings(options, "contexts", "yes"); transactions=1; librdf_hash_from_string(options, storage_options); storage=librdf_new_storage_with_options(world, storage_name, identifier, options); if(!storage) { fprintf(stderr, ": Failed to open %s storage '%s'\n", storage_name, identifier); return(1); } model=librdf_new_model(world, storage, NULL); if(!model) { fprintf(stderr, ": Failed to create model\n"); return(1); } if(transactions) librdf_model_transaction_start(model); /* Do this or gcc moans */ stream=NULL; iterator=NULL; parser=NULL; serializer=NULL; source=NULL; arc=NULL; target=NULL; subject=NULL; predicate=NULL; object=NULL; uri=NULL; node=NULL; query=NULL; results=NULL; context_node=librdf_new_node_from_uri_string(world, (const unsigned char *)context); /**** Test 1 *******/ startTest(1, " Remove all triples in <%s> context\n", context); { rc=librdf_model_context_remove_statements(model, context_node); if(rc) endTest(0, " failed to remove context triples from the graph\n"); else endTest(1, " removed context triples from the graph\n"); } /**** Test 2 *******/ startTest(2, " Add triples to <%s> context\n", context); { rc=0; rc |= add_triple(world, context_node, model, "aa", "bb", "cc"); rc |= add_triple(world, context_node, model, "aa", "bb1", "cc"); rc |= add_triple(world, context_node, model, "aa", "a2", "_:cc"); rc |= add_triple_typed(world, context_node, model, "aa", "a2", "cc"); rc |= add_triple_typed(world, context_node, model, "mm", "nn", "Some long literal with language@en"); rc |= add_triple_typed(world, context_node, model, "oo", "pp", "12345^^<http://www.w3.org/2001/XMLSchema#int>"); if(rc) endTest(0, " failed add triple\n"); else endTest(1, " add triple to context\n"); } /**** Test 3 *******/ startTest(3, " Print all triples in <%s> context\n", context); { raptor_iostream* iostr = raptor_new_iostream_to_file_handle(librdf_world_get_raptor(world), stdout); librdf_model_write(model, iostr); raptor_free_iostream(iostr); endTest(1, "\n"); } /***** Test 4 *****/ startTest(4, " Count of triples in <%s> context\n", context); { count=librdf_model_size(model); if(count >= 0) endTest(1, " graph has %d triples\n", count); else endTest(0, " graph has unknown number of triples\n"); } /***** Test 5 *****/ startTest(5, " Exec: ARC aa bb \n"); { subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa"); predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb"); node=librdf_model_get_target(model, subject, predicate); librdf_free_node(subject); librdf_free_node(predicate); if(!node) { endTest(0, " Failed to get arc\n"); } else { print_node(stdout, node); librdf_free_node(node); endTest(1, "\n"); } } /***** Test 6 *****/ startTest(6, " Exec: ARCS aa cc \n"); { subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa"); object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc"); iterator=librdf_model_get_arcs(model, subject, object); librdf_free_node(subject); librdf_free_node(object); if(!iterator) { endTest(0, " Failed to get arcs\n"); } else { print_nodes(stdout, iterator); endTest(1, "\n"); } } /***** Test 7 *****/ startTest(7, " Exec: ARCS-IN cc \n"); { object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc"); iterator=librdf_model_get_arcs_in(model, object); librdf_free_node(object); if(!iterator) { endTest(0, " Failed to get arcs in\n"); } else { int ok=1; count=0; while(!librdf_iterator_end(iterator)) { context_node=(librdf_node*)librdf_iterator_get_context(iterator); node=(librdf_node*)librdf_iterator_get_object(iterator); /*returns SHARED pointer */ if(!node) { ok=0; endTest(ok, " librdf_iterator_get_next returned NULL\n"); break; } fputs("Matched arc: ", stdout); librdf_node_print(node, stdout); if(context_node) { fputs(" with context ", stdout); librdf_node_print(context_node, stdout); } fputc('\n', stdout); count++; librdf_iterator_next(iterator); } librdf_free_iterator(iterator); endTest(ok, " matching arcs: %d\n", count); } } /***** Test 8 *****/ startTest(8, " Exec: ARCS-OUT aa \n"); { subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa"); iterator=librdf_model_get_arcs_out(model, subject); librdf_free_node(subject); if(!iterator) endTest(0, " Failed to get arcs out\n"); else { int ok=1; count=0; while(!librdf_iterator_end(iterator)) { context_node=(librdf_node*)librdf_iterator_get_context(iterator); node=(librdf_node*)librdf_iterator_get_object(iterator); if(!node) { ok=0; endTest(ok, " librdf_iterator_get_next returned NULL\n"); break; } fputs("Matched arc: ", stdout); librdf_node_print(node, stdout); if(context_node) { fputs(" with context ", stdout); librdf_node_print(context_node, stdout); } fputc('\n', stdout); count++; librdf_iterator_next(iterator); } librdf_free_iterator(iterator); endTest(ok, " matching arcs: %d\n", count); } } /***** Test 9 *****/ startTest(9, " Exec: CONTAINS aa bb1 cc \n"); { subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa"); predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb1"); object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc"); statement=librdf_new_statement(world); librdf_statement_set_subject(statement, subject); librdf_statement_set_predicate(statement, predicate); librdf_statement_set_object(statement, object); if(librdf_model_contains_statement(model, statement)) endTest(1, " the graph contains the triple\n"); else endTest(0, " the graph does not contain the triple\n"); librdf_free_statement(statement); } /***** Test 10 *****/ startTest(10, " Exec: FIND aa - - \n"); { subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa"); statement=librdf_new_statement(world); librdf_statement_set_subject(statement, subject); stream=librdf_model_find_statements_in_context(model, statement, context_node); if(!stream) { endTest(0, " FIND returned no results (NULL stream)\n"); } else { librdf_node* ctxt_node=NULL; int ok=1; count=0; while(!librdf_stream_end(stream)) { librdf_statement *stmt=librdf_stream_get_object(stream); ctxt_node=(librdf_node*)librdf_stream_get_context(stream); if(!stmt) { ok=0; endTest(ok, " librdf_stream_next returned NULL\n"); break; } fputs("Matched triple: ", stdout); librdf_statement_print(stmt, stdout); if(context) { fputs(" with context ", stdout); librdf_node_print(ctxt_node, stdout); } fputc('\n', stdout); count++; librdf_stream_next(stream); } librdf_free_stream(stream); endTest(ok, " matching triples: %d\n", count); } librdf_free_statement(statement); } /***** Test 11 *****/ startTest(11, " Exec: HAS-ARC-IN cc bb \n"); { predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb"); object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc"); if(librdf_model_has_arc_in(model, object, predicate)) endTest(1, " the graph contains the arc\n"); else endTest(0, " the graph does not contain the arc\n"); librdf_free_node(predicate); librdf_free_node(object); } /***** Test 12 *****/ startTest(12, " Exec: HAS-ARC-OUT aa bb \n"); { subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa"); predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb"); if(librdf_model_has_arc_out(model, subject, predicate)) endTest(1, " the graph contains the arc\n"); else endTest(0, " the graph does not contain the arc\n"); librdf_free_node(predicate); librdf_free_node(subject); } /***** Test 13 *****/ startTest(13, " Exec: SOURCE aa cc \n"); { predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb"); object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc"); node=librdf_model_get_source(model, predicate, object); librdf_free_node(predicate); librdf_free_node(object); if(!node) { endTest(0, " Failed to get source\n"); } else { print_node(stdout, node); librdf_free_node(node); endTest(1, "\n"); } } /***** Test 14 *****/ startTest(14, " Exec: SOURCES bb cc \n"); { predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb"); object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc"); iterator=librdf_model_get_sources(model, predicate, object); librdf_free_node(predicate); librdf_free_node(object); if(!iterator) { endTest(0, " Failed to get sources\n"); } else { print_nodes(stdout, iterator); endTest(1, "\n"); } } /***** Test 15 *****/ startTest(15, " Exec: TARGET aa bb \n"); { subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa"); predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb"); node=librdf_model_get_target(model, subject, predicate); librdf_free_node(subject); librdf_free_node(predicate); if(!node) { endTest(0, " Failed to get target\n"); } else { print_node(stdout, node); librdf_free_node(node); endTest(1, "\n"); } } /***** Test 16 *****/ startTest(16, " Exec: TARGETS aa bb \n"); { subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa"); predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb"); iterator=librdf_model_get_targets(model, subject, predicate); librdf_free_node(subject); librdf_free_node(predicate); if(!iterator) { endTest(0, " Failed to get targets\n"); } else { print_nodes(stdout, iterator); endTest(1, "\n"); } } /***** Test 17 *****/ startTest(17, " Exec: REMOVE aa bb1 cc \n"); { subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa"); predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb1"); object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc"); statement=librdf_new_statement(world); librdf_statement_set_subject(statement, subject); librdf_statement_set_predicate(statement, predicate); librdf_statement_set_object(statement, object); if(librdf_model_context_remove_statement(model, context_node, statement)) endTest(0, " failed to remove triple from the graph\n"); else endTest(1, " removed triple from the graph\n"); librdf_free_statement(statement); } /***** Test 18 *****/ query_cmd=(char *)"CONSTRUCT {?s ?p ?o} FROM <http://red> WHERE {?s ?p ?o}"; startTest(18, " Exec: QUERY \"%s\" \n", query_cmd); { query=librdf_new_query(world, (char *)"vsparql", NULL, (const unsigned char *)query_cmd, NULL); if(!(results=librdf_model_query_execute(model, query))) { endTest(0, " Query of model with '%s' failed\n", query_cmd); librdf_free_query(query); query=NULL; } else { stream=librdf_query_results_as_stream(results); if(!stream) { endTest(0, " QUERY returned no results (NULL stream)\n"); } else { librdf_node* ctxt=NULL; count=0; while(!librdf_stream_end(stream)) { librdf_statement *stmt=librdf_stream_get_object(stream); /*returns SHARED pointer */ ctxt=(librdf_node*)librdf_stream_get_context(stream); if(!stmt) { endTest(0, " librdf_stream_next returned NULL\n"); break; } fputs("Matched triple: ", stdout); librdf_statement_print(stmt, stdout); if(ctxt) { fputs(" with context ", stdout); librdf_node_print(ctxt, stdout); } fputc('\n', stdout); count++; librdf_stream_next(stream); } librdf_free_stream(stream); endTest(1, " matching triples: %d\n", count); librdf_free_query_results(results); } } librdf_free_query(query); } /***** Test 19 *****/ query_cmd=(char *)"SELECT * WHERE {graph <http://red> { ?s ?p ?o }}"; startTest(19, " Exec1: QUERY_AS_BINDINGS \"%s\" \n", query_cmd); { query=librdf_new_query(world, (char *)"vsparql", NULL, (const unsigned char *)query_cmd, NULL); if(!(results=librdf_model_query_execute(model, query))) { endTest(0, " Query of model with '%s' failed\n", query_cmd); librdf_free_query(query); query=NULL; } else { raptor_iostream *iostr; librdf_query_results_formatter *formatter; fprintf(stderr, "**: Formatting query result as '%s':\n", results_format); iostr = raptor_new_iostream_to_file_handle(librdf_world_get_raptor(world), stdout); formatter = librdf_new_query_results_formatter2(results, results_format, NULL /* mime type */, NULL /* format_uri */); base_uri = librdf_new_uri(world, (const unsigned char*)"http://example.org/"); librdf_query_results_formatter_write(iostr, formatter, results, base_uri); librdf_free_query_results_formatter(formatter); raptor_free_iostream(iostr); librdf_free_uri(base_uri); endTest(1, "\n"); librdf_free_query_results(results); } librdf_free_query(query); } /***** Test 20 *****/ query_cmd=(char *)"SELECT * WHERE {graph <http://red> { ?s ?p ?o }}"; startTest(20, " Exec2: QUERY_AS_BINDINGS \"%s\" \n", query_cmd); { query=librdf_new_query(world, (char *)"vsparql", NULL, (const unsigned char *)query_cmd, NULL); if(!(results=librdf_model_query_execute(model, query))) { endTest(0, " Query of model with '%s' failed\n", query_cmd); librdf_free_query(query); query=NULL; } else { if(print_query_results(world, model, results)) endTest(0, "\n"); else endTest(1, "\n"); librdf_free_query_results(results); } librdf_free_query(query); } getTotal(); if(transactions) librdf_model_transaction_commit(model); librdf_free_node(context_node); librdf_free_node(context_node); librdf_free_hash(options); librdf_free_model(model); librdf_free_storage(storage); librdf_free_world(world); #ifdef LIBRDF_MEMORY_DEBUG librdf_memory_report(stderr); #endif /* keep gcc -Wall happy */ return(0); }
/* * The main event loop. */ static void event_loop(void) { node_mask_t old_connected_nodes = 0; int old_shut_down = 0; while (!old_shut_down || joined_lockspaces || !list_empty(&aio_pending) || !list_empty(&aio_completed)) { int ret, n; if (connected_nodes != old_connected_nodes) { if (verbose) { print_nodes(stdout, connected_nodes); printf("\n"); fflush(stdout); } if (connected_nodes == all_nodes) { printf("DLM ready\n"); fflush(stdout); } else if (old_connected_nodes == all_nodes) { printf("DLM not ready\n"); fflush(stdout); } old_connected_nodes = connected_nodes; } if (old_shut_down != shut_down) { switch(shut_down) { case 1: printf("Shutting down (press ^C to enforce)\n"); break; case 2: printf("Shutting down\n"); break; default: printf("Aborting\n"); break; } fflush(stdout); close_all_connections(); if (joined_lockspaces && shut_down <= 2) release_lockspaces(shut_down > 1); else break; old_shut_down = shut_down; continue; } if (!list_empty(&aio_completed)) { while (!list_empty(&aio_completed)) { struct aio_request *req = list_first_entry(&aio_completed, struct aio_request, list); int err; list_del(&req->list); err = aio_error(&req->aiocb); if (err > 0) errno = err; req->complete(req); } continue; } ret = poll(cbs.pollfds, cbs.num, -1); if (ret == -1) { if (errno == EINTR) continue; fail(NULL); } for (n = 0; n < cbs.num; n++) { struct pollfd *pfd = &cbs.pollfds[n]; if (pfd->revents) { struct poll_callback *pcb = &cbs.callbacks[n]; pcb->callback(pfd->fd, pfd->revents, pcb->arg); } } } }
void ClusterMgr::configure(Uint32 nodeId, const ndb_mgm_configuration* config) { ndb_mgm_configuration_iterator iter(* config, CFG_SECTION_NODE); for(iter.first(); iter.valid(); iter.next()){ Uint32 nodeId = 0; if(iter.get(CFG_NODE_ID, &nodeId)) continue; // Check array bounds + don't allow node 0 to be touched assert(nodeId > 0 && nodeId < MAX_NODES); trp_node& theNode = theNodes[nodeId]; theNode.defined = true; unsigned type; if(iter.get(CFG_TYPE_OF_SECTION, &type)) continue; switch(type){ case NODE_TYPE_DB: theNode.m_info.m_type = NodeInfo::DB; break; case NODE_TYPE_API: theNode.m_info.m_type = NodeInfo::API; break; case NODE_TYPE_MGM: theNode.m_info.m_type = NodeInfo::MGM; break; default: type = type; break; } } /* Mark all non existing nodes as not defined */ for(Uint32 i = 0; i<MAX_NODES; i++) { if (iter.first()) continue; if (iter.find(CFG_NODE_ID, i)) theNodes[i]= Node(); } #if 0 print_nodes("init"); #endif // Configure arbitrator Uint32 rank = 0; iter.first(); iter.find(CFG_NODE_ID, nodeId); // let not found in config mean rank=0 iter.get(CFG_NODE_ARBIT_RANK, &rank); if (rank > 0) { // The arbitrator should be active if (!theArbitMgr) theArbitMgr = new ArbitMgr(* this); theArbitMgr->setRank(rank); Uint32 delay = 0; iter.get(CFG_NODE_ARBIT_DELAY, &delay); theArbitMgr->setDelay(delay); } else if (theArbitMgr) { // No arbitrator should be started theArbitMgr->doStop(NULL); delete theArbitMgr; theArbitMgr= NULL; } }
static int be_do_list(int argc, char **argv) { be_node_list_t *be_nodes = NULL; boolean_t all = B_FALSE; boolean_t dsets = B_FALSE; boolean_t snaps = B_FALSE; boolean_t parsable = B_FALSE; int err = 1; int c = 0; char *be_name = NULL; while ((c = getopt(argc, argv, "nadsH")) != -1) { switch (c) { case 'a': all = B_TRUE; break; case 'd': dsets = B_TRUE; break; case 's': snaps = B_TRUE; break; case 'H': parsable = B_TRUE; break; default: usage(); return (1); } } if (all) { if (dsets) { (void) fprintf(stderr, _("Invalid options: -a and %s " "are mutually exclusive.\n"), "-d"); usage(); return (1); } if (snaps) { (void) fprintf(stderr, _("Invalid options: -a and %s " "are mutually exclusive.\n"), "-s"); usage(); return (1); } dsets = B_TRUE; snaps = B_TRUE; } argc -= optind; argv += optind; if (argc == 1) be_name = argv[0]; err = be_list(be_name, &be_nodes); switch (err) { case BE_SUCCESS: print_nodes(be_name, dsets, snaps, parsable, be_nodes); break; case BE_ERR_BE_NOENT: if (be_name == NULL) (void) fprintf(stderr, _("No boot environments found " "on this system.\n")); else { (void) fprintf(stderr, _("%s does not exist or appear " "to be a valid BE.\nPlease check that the name of " "the BE provided is correct.\n"), be_name); } break; default: (void) fprintf(stderr, _("Unable to display Boot " "Environment\n")); (void) fprintf(stderr, "%s\n", be_err_to_str(err)); } if (be_nodes != NULL) be_free_list(be_nodes); return (err); }
void print_itinerary(itinerary_t const* it) { print_nodes(&(it->first)); printf(" to %d", it->second); }
int main(int argc, char **argv) { sxi_hdist_t *hdist = NULL, *hdist2 = NULL; unsigned int i, j, cfg_len; sx_uuid_t uuid; const sx_nodelist_t *nodelist; const sx_node_t *node; const void *cfg; int ret = 1; sxc_client_t *sx = server_init(NULL, NULL, NULL, 0, argc, argv); if(argc == 2 && !strcmp(argv[1], "--debug")) { log_setminlevel(sx, SX_LOG_DEBUG); dbg = 1; } if(!(hdist = sxi_hdist_new(1337, MAXBUILDS, NULL))) { CRIT("Can't build hdist"); return 1; } for(i = 0; i < 5; i++) { uuid_from_string(&uuid, nodes[i].uuid); if(sxi_hdist_addnode(hdist, &uuid, nodes[i].addr, nodes[i].int_addr, nodes[i].capacity)) { CRIT("addnode failed (1)"); goto main_err; } } if(sxi_hdist_build(hdist) != OK) { CRIT("Can't build distribution model (1)"); goto main_err; } if(sxi_hdist_newbuild(hdist) != OK) { CRIT("Can't create new build (1)"); goto main_err; } /* get nodes from build 1 (previous 0) */ nodelist = sxi_hdist_nodelist(hdist, 1); if(!nodelist) { CRIT("sxi_hdist_nodelist failed"); goto main_err; } DEBUG("Re-adding %d nodes from previous build", sx_nodelist_count(nodelist)); for(i = 0; i < sx_nodelist_count(nodelist); i++) { node = sx_nodelist_get(nodelist, i); if(sxi_hdist_addnode(hdist, sx_node_uuid(node), sx_node_addr(node), sx_node_internal_addr(node), sx_node_capacity(node))) { CRIT("addnode failed (2)"); goto main_err; } } DEBUG("Adding 3 new nodes"); /* add 3 new nodes */ for(i = 5; i < 8; i++) { uuid_from_string(&uuid, nodes[i].uuid); if(sxi_hdist_addnode(hdist, &uuid, nodes[i].addr, nodes[i].int_addr, nodes[i].capacity)) { CRIT("addnode failed (3)"); goto main_err; } } if(sxi_hdist_build(hdist) != OK) { CRIT("Can't build distribution model (2)"); goto main_err; } DEBUG("Number of builds: %d", sxi_hdist_buildcnt(hdist)); DEBUG("Assuming the cluster was rebalanced"); if(sxi_hdist_rebalanced(hdist) != OK) { CRIT("sxi_hdist_rebalanced failed"); goto main_err; } DEBUG("Creating new build"); if(sxi_hdist_newbuild(hdist) != OK) { CRIT("Can't create new build (2)"); goto main_err; } /* get nodes from build 1 (previous 0) */ nodelist = sxi_hdist_nodelist(hdist, 1); if(!nodelist) { CRIT("sxi_hdist_nodelist failed"); goto main_err; } DEBUG("Re-adding %d nodes from previous build", sx_nodelist_count(nodelist)); for(i = 0; i < sx_nodelist_count(nodelist); i++) { node = sx_nodelist_get(nodelist, i); if(sxi_hdist_addnode(hdist, sx_node_uuid(node), sx_node_addr(node), sx_node_internal_addr(node), sx_node_capacity(node))) { CRIT("addnode failed (4)"); goto main_err; } } DEBUG("Adding 2 new nodes"); /* add 2 new nodes */ for(i = 8; i < 10; i++) { uuid_from_string(&uuid, nodes[i].uuid); if(sxi_hdist_addnode(hdist, &uuid, nodes[i].addr, nodes[i].int_addr, nodes[i].capacity)) { CRIT("addnode failed (4)"); goto main_err; } } if(sxi_hdist_build(hdist) != OK) { CRIT("Can't build distribution model (3)"); goto main_err; } DEBUG("Number of builds: %d", sxi_hdist_buildcnt(hdist)); if(dbg) { print_nodes(hdist, 0); print_nodes(hdist, 1); } if((uint64_t) FINAL_CHECKSUM != sxi_hdist_checksum(hdist)) { CRIT("Unexpected checksum: %lld", (long long int) sxi_hdist_checksum(hdist)); goto main_err; } DEBUG("*** Creating exact copy of HDIST based on existing config ***"); if(sxi_hdist_get_cfg(hdist, &cfg, &cfg_len)) { CRIT("Can't get config"); goto main_err; } else { DEBUG("Compressed config size: %u", (unsigned int) cfg_len); } if(!(hdist2 = sxi_hdist_from_cfg(cfg, cfg_len))) { CRIT("Can't build HDIST from config"); goto main_err; } if(!sxi_hdist_same_origin(hdist, hdist2)) { CRIT("UUIDs are different for old and new model"); goto main_err; } if(sxi_hdist_checksum(hdist) != sxi_hdist_checksum(hdist2)) { CRIT("Checksums don't match for original and copied build"); goto main_err; } else { DEBUG("Models' checksums OK"); } /* test bidx 0 (10 nodes) */ for(i = 0; i < sizeof(hashes) / 8; i++) for(j = 1; j <= 10; j++) if(locate_cmp(hdist, hdist2, hashes[i], j, 0)) goto main_err; /* test bidx 1 (8 nodes) */ for(i = 0; i < sizeof(hashes) / 8; i++) for(j = 1; j <= 8; j++) if(locate_cmp(hdist, hdist2, hashes[i], j, 1)) goto main_err; ret = 0; main_err: sxi_hdist_free(hdist); sxi_hdist_free(hdist2); server_done(&sx); return ret; }
void sim_radio_init() { //! initialize node id and location FILE *fid; char line_buf[LINE_BUF_SIZE]; // line buffer int j = 0; if((fid = fopen(topofile, "r")) == NULL){ char* sosrootdir; char newtopofile[256]; sosrootdir = getenv("SOSROOT"); strcpy(newtopofile, sosrootdir); printf("Unable to open %s\n", topofile); strcat(newtopofile, "/platform/sim/topo.def\0"); if((fid = fopen(newtopofile, "r")) == NULL){ printf("Unable to open %s\n", newtopofile); exit(1); } else topofile = newtopofile; } printf("Using topology file %s\n", topofile); // remove comments do{ fgets(line_buf, LINE_BUF_SIZE, fid); } while(line_buf[0] == '#'); if(sscanf(line_buf, "%d", &totalNodes) != 1){ fprintf(stderr, "no data in %s\n", topofile); exit(1); } topo_array = (Topology*)malloc((totalNodes + 1) * sizeof(Topology)); if (topo_array == NULL){ fprintf(stderr, "not enough memory\n"); exit(1); } for(j = 0; j < totalNodes; j++){ do{ // remove comments fgets(line_buf, LINE_BUF_SIZE, fid); }while(line_buf[0] == '#'); if(sscanf(line_buf, "%d %d %d %d %d %u", &topo_array[j].id, &topo_array[j].unit, &topo_array[j].x, &topo_array[j].y, &topo_array[j].z, &topo_array[j].r2) != 6){ fprintf(stderr, "not enough definitions in %s: %s\n", topofile, line_buf); exit(1); } //topo_array[j].id = j; topo_array[j].type = TOPO_TYPE_OTHER; topo_array[j].sock = -1; } #if 0 print_nodes(); exit(1); #endif if(fclose(fid) != 0){ perror("fclose"); exit(1); } // finding node id by finding available port //for(j = 1; j <= totalNodes; j++) { int sock; int myj = getj(ker_id()); struct sockaddr_in name; sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { perror("opening datagram socket"); exit(1); } /* Create name with wildcards. */ name.sin_family = AF_INET; name.sin_addr.s_addr = INADDR_ANY; // name.sin_port = htons(20000 + ker_id()); name.sin_port = htons( get_sin_port(ker_id()) ); if (bind(sock, (struct sockaddr *)&name, sizeof(name)) == 0) { //node_address = j; // successfully get an id topo_array[myj].sock = sock; topo_array[myj].type = TOPO_TYPE_SELF; topo_self = topo_array[myj]; //! assign sos_info node_loc.x = topo_self.x; node_loc.y = topo_self.y; node_loc.z = topo_self.z; node_loc.unit = topo_self.unit; }else{ fprintf(stderr, "Unable to allocate UDP for this node!\n"); fprintf(stderr, "Perhaps you are using the same node ID\n"); fprintf(stderr, "Use -n <node address> to specify different address\n\n"); exit(1); } } { uint16_t id; node_loc_t self; id = ker_id(); self = ker_loc(); if((id != topo_self.id) || (self.x != topo_self.x) || (self.y != topo_self.y) || (self.z != topo_self.z) || (self.unit != topo_self.unit)){ fprintf(stderr, "topo file and self settings do not agree.\n"); fprintf(stderr, "ker_id() = %d : topo_self.id = %d\n", id, topo_self.id); fprintf(stderr, "self.unit = %d : topo_self.unit = %d\n", self.unit, topo_self.unit); fprintf(stderr, "self.x = %d : topo_self.x = %d\n", self.x, topo_self.x); fprintf(stderr, "self.y = %d : topo_self.y = %d\n", self.y, topo_self.y); fprintf(stderr, "self.z = %d : topo_self.z = %d\n", self.z, topo_self.z); exit(1); } } for(j = 0; j < totalNodes; j++){ uint32_t r2; uint16_t id; node_loc_t self, neighbor; id = ker_id(); self = ker_loc(); if(topo_array[j].type == TOPO_TYPE_SELF) continue; neighbor.unit = topo_array[j].unit; neighbor.x = topo_array[j].x; neighbor.y = topo_array[j].y; neighbor.z = topo_array[j].z; r2 = ker_loc_r2(&self,&neighbor); if(r2 < 0){ fprintf(stderr, "units for neighbor do not agree.\n"); fprintf(stderr, "self.unit = %d : neighbor.unit = %d.\n", self.unit, neighbor.unit); exit(1); } DEBUG("neighbor %d r2 = %d, self r2 = %d\n", topo_array[j].id, r2, topo_self.r2); if(r2 <= topo_self.r2){ topo_array[j].type = TOPO_TYPE_NEIGHBOR; DEBUG("node %d is reachable\n", topo_array[j].id); } } { struct hostent *hostptr; char theHost [MAXLENHOSTNAME]; unsigned long hostaddress; /* find out who I am */ if ((gethostname(theHost, MAXLENHOSTNAME))<0) { perror ("could not get hostname"); exit(1); } //DEBUG("-- found host name = %s\n", theHost); if ((hostptr = gethostbyname (theHost)) == NULL) { perror ("could not get host by name, use 127.0.0.1"); if(( hostptr = gethostbyname ("127.0.0.1") ) == NULL ) { perror ("Cannot get host 127.0.0.1"); exit(1); } } hostaddress = *((unsigned long *) hostptr->h_addr); /* init the address structure */ sockaddr.sin_family = AF_INET; sockaddr.sin_port = htons( get_sin_port(ker_id()) ); sockaddr.sin_addr.s_addr = hostaddress; } //! assign locations //node_loc.x = (uint16_t)(topo_self.x); //node_loc.y = (uint16_t)(topo_self.y); //print_nodes(); }
/** * This method is called from start of cluster connection instance and * before we have started any socket services and thus it needs no * mutex protection since the ClusterMgr object isn't known by any other * thread at this point in time. */ void ClusterMgr::configure(Uint32 nodeId, const ndb_mgm_configuration* config) { ndb_mgm_configuration_iterator iter(* config, CFG_SECTION_NODE); for(iter.first(); iter.valid(); iter.next()) { Uint32 nodeId = 0; if(iter.get(CFG_NODE_ID, &nodeId)) continue; // Check array bounds + don't allow node 0 to be touched assert(nodeId > 0 && nodeId < MAX_NODES); trp_node& theNode = theNodes[nodeId]; theNode.defined = true; unsigned type; if(iter.get(CFG_TYPE_OF_SECTION, &type)) continue; switch(type) { case NODE_TYPE_DB: theNode.m_info.m_type = NodeInfo::DB; break; case NODE_TYPE_API: theNode.m_info.m_type = NodeInfo::API; break; case NODE_TYPE_MGM: theNode.m_info.m_type = NodeInfo::MGM; break; default: break; } } /* Mark all non existing nodes as not defined */ for(Uint32 i = 0; i<MAX_NODES; i++) { if (iter.first()) continue; if (iter.find(CFG_NODE_ID, i)) theNodes[i]= Node(); } #if 0 print_nodes("init"); #endif // Configure arbitrator Uint32 rank = 0; iter.first(); iter.find(CFG_NODE_ID, nodeId); // let not found in config mean rank=0 iter.get(CFG_NODE_ARBIT_RANK, &rank); if (rank > 0) { // The arbitrator should be active if (!theArbitMgr) theArbitMgr = new ArbitMgr(* this); theArbitMgr->setRank(rank); Uint32 delay = 0; iter.get(CFG_NODE_ARBIT_DELAY, &delay); theArbitMgr->setDelay(delay); } else if (theArbitMgr) { // No arbitrator should be started theArbitMgr->doStop(NULL); delete theArbitMgr; theArbitMgr= NULL; } // Configure heartbeats. unsigned hbFrequency = 0; iter.get(CFG_MGMD_MGMD_HEARTBEAT_INTERVAL, &hbFrequency); m_hbFrequency = static_cast<Uint32>(hbFrequency); // Configure max backoff time for connection attempts to first // data node. Uint32 backoff_max_time = 0; iter.get(CFG_START_CONNECT_BACKOFF_MAX_TIME, &backoff_max_time); start_connect_backoff_max_time = backoff_max_time; // Configure max backoff time for connection attempts to data // nodes. backoff_max_time = 0; iter.get(CFG_CONNECT_BACKOFF_MAX_TIME, &backoff_max_time); connect_backoff_max_time = backoff_max_time; theFacade.get_registry()->set_connect_backoff_max_time_in_ms( start_connect_backoff_max_time); }