示例#1
0
void masterconn_metachanges_log(masterconn *eptr,const uint8_t *data,uint32_t length) {
    char line[1024];
    uint64_t version;
    if (length==1 && data[0]==0x55) {
        fs_storeall(1);
        return;
    }
    if (length<10) {
        syslog(LOG_NOTICE,"MATOML_METACHANGES_LOG - wrong size (%"PRIu32"/9+data)",length);
        eptr->mode = KILL;
        return;
    }
    if (data[0]!=0xFF) {
        syslog(LOG_NOTICE,"MATOML_METACHANGES_LOG - wrong packet");
        eptr->mode = KILL;
        return;
    }
    if (data[length-1]!='\0') {
        syslog(LOG_NOTICE,"MATOML_METACHANGES_LOG - invalid string");
        eptr->mode = KILL;
        return;
    }

    data++;
    version = get64bit(&data);

    if (version<currentlogversion) {
        syslog(LOG_WARNING, "get old change: %"PRIu64":%"PRIu64", ignore",currentlogversion,version-1);
        return;
    }
    if (currentlogversion>0 && version>currentlogversion) {
        syslog(LOG_WARNING, "some changes lost: [%"PRIu64"-%"PRIu64"], download metadata again",currentlogversion,version-1);
        masterconn_metadownloadinit();
        return;
    }

    if (version == fs_getversion()) {
        changelog(version, "%s", (const char*)data); 
        currentlogversion = version+1;

        sprintf(line, ": %s\n", data);
        if (restore_line("(live changelog)", version, line)!=STATUS_OK) {
            syslog(LOG_WARNING, "replay change log failed: version=%"PRIu64", download metadata again",version);
            masterconn_metadownloadinit();
        } else if (fs_getversion() != version+1) {
            syslog(LOG_WARNING, "restored version not match: %"PRIu64"!=%"PRIu64", download metadata again",fs_getversion(),version+1);
            masterconn_metadownloadinit();
        }
    } else {
        syslog(LOG_WARNING, "version not match: %"PRIu64"!=%"PRIu64", download metadata again",fs_getversion(),version);
        masterconn_metadownloadinit();
    }
}
示例#2
0
文件: merger.c 项目: bhohbaum/moosefs
int merger_start(uint32_t files,char **filenames,uint64_t maxhole,uint64_t maxlastlv) {
	uint32_t i;
	heapsize = 0;
	heap = (hentry*)malloc(sizeof(hentry)*files);
	if (heap==NULL) {
		return -1;
	}
	for (i=0 ; i<files ; i++) {
		merger_new_entry(filenames[i]);
//		printf("file: %s / firstid: %"PRIu64"\n",filenames[i],heap[heapsize].nextid);
		if (heap[heapsize].nextid<0) {
			merger_delete_entry();
		} else {
			heapsize++;
			merger_heap_sort_up();
		}
	}
	maxidhole = maxhole;
	lastlv = maxlastlv;
	firstlv = fs_getversion();
//	for (i=0 ; i<heapsize ; i++) {
//		printf("heap: %u / firstid: %"PRIu64"\n",i,heap[i].nextid);
//	}
	return 0;
}
示例#3
0
int restore(const char *filename,uint64_t lv,char *ptr) {
	int status;
	if (lastv==0 || v==0) {
		v = fs_getversion();
		lastv = lv-1;
		lastfn = "(no file)";
	}
	if (vlevel>1) {
		printf("filename: %s ; current meta version: %"PRIu64" ; previous changeid: %"PRIu64" ; current changeid: %"PRIu64" ; change data%s",filename,v,lastv,lv,ptr);
	}
	if (lv<lastv) {
		printf("merge error - possibly corrupted input file - ignore entry (filename: %s)\n",filename);
		return 0;
	} else if (lv>=v) {
		if (lv==lastv) {
			if (vlevel>1) {
				printf("duplicated entry: %"PRIu64" (previous file: %s, current file: %s)\n",lv,lastfn,filename);
			}
		} else if (lv>lastv+1) {
			printf("hole in change files (entries from %s:%"PRIu64" to %s:%"PRIu64" are missing) - add more files\n",lastfn,lastv+1,filename,lv-1);
			return -2;
		} else {
			if (vlevel>0) {
				printf("%s: change%s",filename,ptr);
			}
			status = restore_line(filename,lv,ptr);
			if (status<0) { // parse error - just ignore this line
				return 0;
			}
			if (status>0) { // other errors - stop processing data
				return -1;
			}
			v = fs_getversion();
			if (lv+1!=v) {
				printf("%s:%"PRIu64": version mismatch\n",filename,lv);
				return -1;
			}
		}
	}
	lastv = lv;
	lastfn = filename;
	return 0;
}
示例#4
0
int restore(uint64_t lv,char *ptr) {
	if (lastv==0 || v==0) {
		v = fs_getversion();
		lastv = lv-1;
	}
	if (vlevel>1) {
		printf("current meta version: %"PRIu64" ; previous changeid: %"PRIu64" ; current changeid: %"PRIu64" ; change data%s",v,lastv,lv,ptr);
	}
	if (lv<lastv) {
		printf("merge error - possibly corrupted input file - ignore entry\n");
		return 0;
	} else if (lv>=v) {
		if (lv==lastv) {
			if (vlevel>1) {
				printf("duplicated entry: %"PRIu64"\n",lv);
			}
		} else if (lv>lastv+1) {
			printf("hole in change files (entries from %"PRIu64" to %"PRIu64" are missing) - add more files\n",lastv+1,lv-1);
			return -1;
		} else {
			if (vlevel>0) {
				printf("change%s",ptr);
			}
			if (restore_line(lv,ptr)!=STATUS_OK) {
				return -1;
			}
			v = fs_getversion();
			if (lv+1!=v) {
				printf("%"PRIu64": version mismatch\n",lv);
				return -1;
			}
		}
	}
	lastv = lv;
	return 0;
}
示例#5
0
            int masterconn_init(void) {
                uint32_t ReconnectionDelay;
                masterconn *eptr;

                ReconnectionDelay = cfg_getuint32("MASTER_RECONNECTION_DELAY",5);
                MasterHost = cfg_getstr("MASTER_HOST","mfsmaster");
                MasterPort = cfg_getstr("MASTER_PORT","9419");
                BindHost = cfg_getstr("BIND_HOST","*");
                Timeout = cfg_getuint32("MASTER_TIMEOUT",10);
                BackLogsNumber = cfg_getuint32("BACK_LOGS",50);
                BackMetaCopies = cfg_getuint32("BACK_META_KEEP_PREVIOUS",3);

                if (Timeout>65536) {
                    Timeout=65535;
                }
                if (Timeout<10) {
                    Timeout=10;
                }
                if (BackLogsNumber<5) {
                    BackLogsNumber=5;
                }
                if (BackLogsNumber>10000) {
                    BackLogsNumber=10000;
                }
                eptr = masterconnsingleton = malloc(sizeof(masterconn));
                passert(eptr);

                eptr->masteraddrvalid = 0;
                eptr->mode = FREE;
                eptr->pdescpos = -1;
                eptr->metafd = -1;
                eptr->oldmode = 0;

                currentlogversion = fs_getversion();
                if (!fs_ismastermode() && masterconn_initconnect(eptr)<0) {
                    return -1;
                }
                reconnect_hook = main_timeregister(TIMEMODE_RUN_LATE,ReconnectionDelay,0,masterconn_reconnect);
                main_destructregister(masterconn_term);
                main_pollregister(masterconn_desc,masterconn_serve);
                main_reloadregister(masterconn_reload);
                main_timeregister(TIMEMODE_RUN_LATE,60,0,masterconn_sessionsdownloadinit);
                return 0;
            }