Example #1
0
void
cache_fresh_lot_collection(void)
{
	DIR *colls;
	char *coll;
	char path[2048];
	size_t len;
	int i;

	/* We only look at the first 5 lots */
        if ((colls = listAllColl_start()) == NULL) {
		bblog(ERROR, "Can't listAllColl_start()");
                return;
	}

	while ((coll = listAllColl_next(colls))) {
		for (i = 1; i < 6; i++) {
			DIR *dirp;
			struct dirent *de;

			GetFilPathForLot(path, i, coll);
			len = strlen(path);

			dirp = opendir(path);
			if (dirp == NULL)
				continue;
			while ((de = readdir(dirp))) {
				int fd;
				int dw;

				if (de->d_name[0] == '.')
					continue;

				sprintf(path+len, "/%s", de->d_name);
				bblog(DEBUGINFO, "Found file: %s", path);
				fd = open(path, O_RDONLY);
				if (fd == -1)
					continue;
				read(fd, &dw, sizeof(dw));
				close(fd);
			}
			closedir(dirp);
		}
	}
	listAllColl_close(colls);
}
Example #2
0
void
preopen(void)
{
	int i;
        DIR *dirh;
	FILE *FH;
	int count = 0;

	reclose_cache();
	
	if ((dirh = listAllColl_start()) == NULL) {
		bblog(ERROR, "Can't listAllColl_start()");
		return;
	}
 
        char * subname;
	while (((subname = listAllColl_next(dirh)) != NULL) && (count < MAX_PREOPEM_FILE)) {
                bblog(DEBUGINFO, "subname: %s", subname);
		for(i=1;i<maxLots;i++) {
			// vi åpner kun lotter som har DocumentIndex. Dette er spesielt viktig da vi oppretter 
			// filene hvis de ikke finnes.
			if ((FH = lotOpenFileNoCasheByLotNr(i,"DocumentIndex","rb", 'r', subname)) == NULL) {
				continue;
			}
			reopen_cache(i,4, "filtypes",subname,RE_READ_ONLY|RE_STARTS_AT_0|RE_POPULATE|RE_CREATE_AND_STRETCH);
			reopen_cache(i,sizeof(int), "dates",subname,RE_READ_ONLY|RE_STARTS_AT_0|RE_POPULATE|RE_CREATE_AND_STRETCH);
			reopen_cache(i,sizeof(unsigned int), "crc32map",subname,RE_READ_ONLY|RE_POPULATE|RE_CREATE_AND_STRETCH);

			fclose(FH);

			if (count > MAX_PREOPEM_FILE) {
				break;
			}
			// +3 da vi øker med filtypes, dates, og crc32map
			count += 3;
		}	
	}
        listAllColl_close(dirh);


	if (count >= MAX_PREOPEM_FILE) {
		bblog(WARN, "can't preopen any more. Did hit MAX_PREOPEM limit of %d files", MAX_PREOPEM_FILE);
	}
}
Example #3
0
void
cache_indexes_all(void)
{
	DIR *dirp;
	size_t len;
	int i;
	size_t *cached;
	DIR *colls;
	char *coll;
	FILE *fp;
	char collpath[2048];

	lot_get_closed_collections_file(collpath);
	if ((fp = fopen(collpath, "r+")) == NULL) {
		bblog_errno(WARN, "Unable to open collection list: fopen(%s)", collpath);
	} else {
		flock(fileno(fp), LOCK_EX);
		ftruncate(fileno(fp), 0);
		flock(fileno(fp), LOCK_UN);
		/*
		 * Release the lock, so that indexes updated while running the
		 * cache step will not block. We can recache it later.
		 */ 
		fclose(fp);
	}

	cached = indexcachescached;
	indexcachehash = create_hashtable(1023, ht_stringhash, ht_stringcmp);

	cached[0] = cached[1] = 0;

        if ((colls = listAllColl_start()) == NULL) {
		bblog(ERROR, "Can't listAllColl_start()");
                return;
	}

	while ((coll = listAllColl_next(colls))) {
		cache_indexes_collection(coll);
	}

	listAllColl_close(colls);
}
int main(int argc, char *argv[]) {


/*
	Usage:
		-c Vis antall dokumenter
		-f Vi menesklig lesbart format
		-m vi bare collections som inneholder argumentet.
*/

	int optCount = 0;
	int optFormat = 0;
	char *optmatch = NULL;

	extern char *optarg;
        char c;
        while ((c=getopt(argc,argv,"cfm:"))!=-1) {
                        switch (c) {
                                case 'c':
                                        optCount = 1;
                                        break;
                                case 'f':
                                        optFormat = 1;
                                        break;
                                case 'm':
                                        optmatch = optarg;
                                        break;
                                default:
					exit(-1);
                        }
        }

	if (optFormat == 1) {
		printf("|--------------------------------|------------|\n");	
		printf("| Collection                     | Nr of docs |\n");
		printf("|--------------------------------|------------|\n");	
	
	}

	DIR * dirh = listAllColl_start();
	if (dirh == NULL) 
		err(1, "listAllColl_start()");
	
	char * subname;
	int docCount = 0;
	while ((subname = listAllColl_next(dirh)) != NULL) {

		if ( (optmatch != NULL) && (strstr(subname,optmatch) == NULL) ) {
			continue;
		}

		if (optCount == 1) {
			docCount = rLastDocID(subname);
		}

		if ((optCount == 1) && (optFormat == 1)) {
			printf("| %30s | %10u |\n", subname, docCount);
		}
		else if (optCount == 1) {
			printf("subname: %s, docCount: %u\n", subname, docCount);
		}
		else {
			printf("subname: %s\n", subname);
		}
	}

	listAllColl_close(dirh);

	if (optFormat == 1) {
		printf("|--------------------------------|------------|\n");	
	}

	return 0;
}
Example #5
0
int
main(int argc, char **argv)
{

	int i;
	char *subname;
	struct gcaoptFormat gcaopt;

	gcaopt.MaxAgeDiflastSeen  = (86400 * 5); //86400=1 dag
	gcaopt.log = NULL;
	gcaopt.logSummary = NULL;
	gcaopt.lastSeenHack = 0;
	gcaopt.dontcheckok = 0;

        extern char *optarg;
        extern int optind, opterr, optopt;
        char c;
        while ((c=getopt(argc,argv,"t:dlsho"))!=-1) {
                switch (c) {
                        case 'h':
				print_usage();
				break;
                        case 't':
                                gcaopt.MaxAgeDiflastSeen  = atou(optarg);
                                break;
			case 'l':
				if ((gcaopt.log = fopen(bfile("logs/gc"),"ab")) == NULL) {
					perror("logs/gc");
					exit(-1);
				}
				if ((gcaopt.logSummary = fopen(bfile("logs/gcSummary"),"ab")) == NULL) {
					perror("logs/gcSummary");
					exit(-1);
				}

				break;
			case 's':
				gcaopt.lastSeenHack = 1;
				break;
			case 'o':
				gcaopt.dontcheckok = 1;
				break;
                        default:
                                exit(1);
                }

        }
        --optind;



	DIR *ll;


	#ifndef BLACK_BOX
		fprintf("dette fungerer bare med black boks for nå\n");
		exit(1);
	#endif

	if ((argc -optind) == 2) {
		subname = argv[1 +optind];

		gc_coll(subname, &gcaopt);


	}
	else if ((argc -optind) == 1) {

		ll = listAllColl_start();

		while((subname = listAllColl_next(ll)) != NULL) {
			printf("indexing collection \"%s\"\n",subname);

			gc_coll(subname, &gcaopt);

		}

		listAllColl_close(ll);

	}
	else {
		print_usage();
	}



	return 0;
}