Exemplo n.º 1
0
int my_foreman(int *space, const char *host, int port, time_t stoptime)
{
	int i = 0; //global_catalog iterator
	char full_address[1024];
	if(!domain_name_cache_lookup(host, full_address) || !full_address)
	{
		debug(D_WQ,"Could not resolve %s into an ip address\n",host);
		return 0;
	}
	sprintf(full_address, "%s:%d", full_address, port);

	while(global_catalog[i] != NULL){
		const char *temp_my_master = nvpair_lookup_string(global_catalog[i], "my_master");
		if(temp_my_master && !strcmp(temp_my_master, full_address)){
			char modified_proj[50];
			memset(modified_proj,0,sizeof(modified_proj));
			space_relations(*space, modified_proj); //append '->' for proper recursive depth
			sprintf(modified_proj,"%s%s",modified_proj,nvpair_lookup_string(global_catalog[i], "project")); //prepare modified project name with proper depth
			nvpair_remove(global_catalog[i], nvpair_lookup_string(global_catalog[i], "project")); //remove old project look
			nvpair_insert_string(global_catalog[i], "project", modified_proj); //replace with the modified relation version
			if(resource_mode){
				nvpair_print_table(global_catalog[i], stdout, master_resource_headers);
			}else if(format_mode == FORMAT_TABLE){
				nvpair_print_table(global_catalog[i], stdout, queue_headers);
			}
			int new_space = *space + 1; //so that spaces are preserved in recursive calls
			my_foreman(&new_space,nvpair_lookup_string(global_catalog[i], "name"),atoi(nvpair_lookup_string(global_catalog[i], "port")),stoptime);
		}
		i++;
	}
	
	return 1;
}
Exemplo n.º 2
0
void
nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
{

	NVLIST_ASSERT(nvl);
	NVPAIR_ASSERT(nvp);
	PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);

	nvpair_remove(&nvl->nvl_head, nvp, nvl);
}
Exemplo n.º 3
0
static int log_replay( struct nvpair_database *db, const char *filename, time_t snapshot)
{
	FILE *file = fopen(filename,"r");
	if(!file) return 0;
	
	time_t current = 0;
	struct nvpair *nv;

	char line[NVPAIR_LINE_MAX];
	char key[NVPAIR_LINE_MAX];
	char name[NVPAIR_LINE_MAX];
	char value[NVPAIR_LINE_MAX];
	char oper;
	
	while(fgets(line,sizeof(line),file)) {

		int n = sscanf(line,"%c %s %s %[^\n]",&oper,key,name,value);
		if(n<1) continue;

		switch(oper) {
			case 'C':
				nv = nvpair_create();
				nvpair_parse_stream(nv,file);
				nvpair_delete(hash_table_remove(db->table,name));
				hash_table_insert(db->table,key,nv);
				break;
			case 'D':
				nv = hash_table_remove(db->table,key);
				if(nv) nvpair_delete(nv);
				break;
			case 'U':
				nv = hash_table_lookup(db->table,key);
				if(nv) nvpair_insert_string(nv,name,value);
				break;
			case 'R':
				nv = hash_table_lookup(db->table,key);
				if(nv) nvpair_remove(nv,name);
				break;
			case 'T':
				current = atol(key);
				if(current>snapshot) break;
				break;
			default:
				debug(D_NOTICE,"corrupt log data in %s: %s",filename,line);
				break;
		}
	}
	
	fclose(file);

	return 1;
}
Exemplo n.º 4
0
static int log_play( struct deltadb *db, FILE *stream )
{
	time_t current = 0;
	time_t previous_time = 0;
	int line_number = 0;

	char line[NVPAIR_LINE_MAX];
	char key[NVPAIR_LINE_MAX];
	char name[NVPAIR_LINE_MAX];
	char value[NVPAIR_LINE_MAX];
	char oper;
	
	while(fgets(line,sizeof(line),stream)) {
		//debug(D_NOTICE,"Processed line: %s",line);
		line_number += 1;
		
		if (line[0]=='\n') break;
		
		int n = sscanf(line,"%c %s %s %[^\n]",&oper,key,name,value);
		if(n<1) continue;
		
		struct nvpair *nv;
		
		switch(oper) {
			case 'C':
				nv = nvpair_create();
				int num_pairs = nvpair_parse_stream(nv,stream);
				if(num_pairs>0) {
					nvpair_delete(hash_table_remove(db->table,key));
					hash_table_insert(db->table,key,nv);
				} else if (num_pairs == -1) {
					nvpair_delete(nv);
					break;
				} else {
					nvpair_delete(nv);
				}


				break;
			case 'D':
				nv = hash_table_remove(db->table,key);
				if(nv) nvpair_delete(nv);
				break;
			case 'U':
				nv = hash_table_lookup(db->table,key);
				if(nv) nvpair_insert_string(nv,name,value);
				break;
			case 'R':
				nv = hash_table_lookup(db->table,key);
				if(nv) nvpair_remove(nv,name);
				break;
			case 'T':
				previous_time = current;
				current = atol(key);
				emit_table_values(db,previous_time);
				break;
			default:
				debug(D_NOTICE,"corrupt log data[%i]: %s",line_number,line);
				fflush(stderr);
				break;
		}
	}
	emit_table_values(db,current);
	return 1;
}
/*
Replay a given log file into the hash table, up to the given snapshot time.
Return true if the stoptime was reached.
*/
static int log_play( struct deltadb *db, FILE *stream  )
{
	struct nvpair *nv;

	char line[NVPAIR_LINE_MAX];
	char key[NVPAIR_LINE_MAX];
	char name[NVPAIR_LINE_MAX];
	char value[NVPAIR_LINE_MAX];
	char oper;

	int first_output = 1;

	time_t previous_time = 0;

	while(fgets(line,sizeof(line),stream)) {
		//debug(D_NOTICE,"Processed line: %s",line);

		int n = sscanf(line,"%c %s %s %[^\n]",&oper,key,name,value);
		if(n<1) continue;

		if(line[0]=='\n') break;

		switch(oper) {
			case 'C':
				nv = nvpair_create();
				nvpair_parse_stream(nv,stream);
				nvpair_delete(hash_table_remove(db->table,name));
				hash_table_insert(db->table,key,nv);
				break;
			case 'D':
				nv = hash_table_remove(db->table,key);
				if(nv) nvpair_delete(nv);
				break;
			case 'U':
				nv = hash_table_lookup(db->table,key);
				if(nv) nvpair_insert_string(nv,name,value);
				break;
			case 'R':
				nv = hash_table_lookup(db->table,key);
				if(nv) nvpair_remove(nv,name);
				break;
			case 'T':
				current = atol(key);
				break;
			default:
				debug(D_NOTICE,"corrupt log data: %s",line);
				break;
		}

		if (previous_time==0){
			previous_time = current;
		} else if(previous_time!=current) {
			emit_all_deltadb_reductions(db,previous_time,first_output);
			first_output = 0;
			previous_time = current;
		}
	}
	emit_all_deltadb_reductions(db,previous_time,first_output);

	return 0;
}