comparison audioDB.cpp @ 129:f7eba8eb272c

Variable size databases, part 2: new --size argument on database creation; use it for the dbSize field. (Note that maximum use of this can be obtained on 32-bit platforms only by compiling with -D_FILE_OFFSET_BITS=64 or similar, otherwise 2^31 is an upper exclusive limit for off_t and hence for the lseek() call)
author mas01cr
date Fri, 19 Oct 2007 14:41:54 +0000
parents f789aa32382f
children 3d931368fab3
comparison
equal deleted inserted replaced
128:f789aa32382f 129:f7eba8eb272c
150 cerr << "Warning: verbosity out of range, setting to 1" << endl; 150 cerr << "Warning: verbosity out of range, setting to 1" << endl;
151 verbosity=1; 151 verbosity=1;
152 } 152 }
153 } 153 }
154 154
155 if(args_info.size_given) {
156 if (args_info.size_arg < 250 || args_info.size_arg > 4000) {
157 error("Size out of range", "");
158 }
159 size = args_info.size_arg * 1000000;
160 }
161
155 if(args_info.radius_given){ 162 if(args_info.radius_given){
156 radius=args_info.radius_arg; 163 radius=args_info.radius_arg;
157 if(radius<=0 || radius>1000000000){ 164 if(radius<=0 || radius>1000000000){
158 error("radius out of range"); 165 error("radius out of range");
159 } 166 }
370 if ((dbfid = open (dbName, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) 377 if ((dbfid = open (dbName, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0)
371 error("Can't create database file", dbName, "open"); 378 error("Can't create database file", dbName, "open");
372 get_lock(dbfid, 1); 379 get_lock(dbfid, 1);
373 380
374 // go to the location corresponding to the last byte 381 // go to the location corresponding to the last byte
375 if (lseek (dbfid, O2_DEFAULTDBSIZE - 1, SEEK_SET) == -1) 382 if (lseek (dbfid, size - 1, SEEK_SET) == -1)
376 error("lseek error in db file", "", "lseek"); 383 error("lseek error in db file", "", "lseek");
377 384
378 // write a dummy byte at the last location 385 // write a dummy byte at the last location
379 if (write (dbfid, "", 1) != 1) 386 if (write (dbfid, "", 1) != 1)
380 error("write error", "", "write"); 387 error("write error", "", "write");
381 388
382 // mmap the output file 389 // mmap the output file
383 if(verbosity) { 390 if(verbosity) {
384 cerr << "header size:" << O2_HEADERSIZE << endl; 391 cerr << "header size:" << O2_HEADERSIZE << endl;
385 } 392 }
386 if ((db = (char*) mmap(0, O2_DEFAULTDBSIZE, PROT_READ | PROT_WRITE, 393 if ((db = (char*) mmap(0, size, PROT_READ | PROT_WRITE,
387 MAP_SHARED, dbfid, 0)) == (caddr_t) -1) 394 MAP_SHARED, dbfid, 0)) == (caddr_t) -1)
388 error("mmap error for creating database", "", "mmap"); 395 error("mmap error for creating database", "", "mmap");
389 396
390 dbH = new dbTableHeaderT(); 397 dbH = new dbTableHeaderT();
391 assert(dbH); 398 assert(dbH);
398 dbH->flags = 0; 405 dbH->flags = 0;
399 dbH->length = 0; 406 dbH->length = 0;
400 dbH->fileTableOffset = ALIGN_UP(O2_HEADERSIZE, 8); 407 dbH->fileTableOffset = ALIGN_UP(O2_HEADERSIZE, 8);
401 dbH->trackTableOffset = ALIGN_UP(dbH->fileTableOffset + O2_FILETABLESIZE*O2_MAXFILES, 8); 408 dbH->trackTableOffset = ALIGN_UP(dbH->fileTableOffset + O2_FILETABLESIZE*O2_MAXFILES, 8);
402 dbH->dataOffset = ALIGN_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*O2_MAXFILES, 8); 409 dbH->dataOffset = ALIGN_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*O2_MAXFILES, 8);
403 dbH->l2normTableOffset = ALIGN_DOWN(O2_DEFAULTDBSIZE - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8); 410 dbH->l2normTableOffset = ALIGN_DOWN(size - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8);
404 dbH->timesTableOffset = ALIGN_DOWN(dbH->l2normTableOffset - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8); 411 dbH->timesTableOffset = ALIGN_DOWN(dbH->l2normTableOffset - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8);
405 dbH->dbSize = O2_DEFAULTDBSIZE; 412 dbH->dbSize = size;
406 413
407 memcpy (db, dbH, O2_HEADERSIZE); 414 memcpy (db, dbH, O2_HEADERSIZE);
408 if(verbosity) { 415 if(verbosity) {
409 cerr << COM_CREATE << " " << dbName << endl; 416 cerr << COM_CREATE << " " << dbName << endl;
410 } 417 }