예제 #1
0
파일: balance.c 프로젝트: blikjeham/binary
void check_balance(int dir, int max)
{
    int i;
    struct field line[max];
    
    for (i=0; i<max; i++) {
	make_line(i, dir, line);
	countline(dir, line);
	restore_line(i, dir, line);
    }
}
예제 #2
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();
    }
}
예제 #3
0
파일: restore.c 프로젝트: alexmiao/moosefs
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;
}