changeset 128:f789aa32382f

Variable-size databases, step 1: introduce dbSize field into the database header. (Preserve backward-compatibility by assuming that dbSize == 0 implies dbSize = O2_DEFAULTDBSIZE)
author mas01cr
date Fri, 19 Oct 2007 13:51:53 +0000
parents 6fafccfe7c05
children f7eba8eb272c
files audioDB.cpp audioDB.h
diffstat 2 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/audioDB.cpp	Thu Oct 18 13:30:57 2007 +0000
+++ b/audioDB.cpp	Fri Oct 19 13:51:53 2007 +0000
@@ -110,7 +110,7 @@
   if(indata)
     munmap(indata,statbuf.st_size);
   if(db)
-    munmap(db,O2_DEFAULTDBSIZE);
+    munmap(db,dbH->dbSize);
   if(dbfid>0)
     close(dbfid);
   if(infid>0)
@@ -402,6 +402,7 @@
   dbH->dataOffset = ALIGN_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*O2_MAXFILES, 8);
   dbH->l2normTableOffset = ALIGN_DOWN(O2_DEFAULTDBSIZE - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8);
   dbH->timesTableOffset = ALIGN_DOWN(dbH->l2normTableOffset - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8);
+  dbH->dbSize = O2_DEFAULTDBSIZE;
 
   memcpy (db, dbH, O2_HEADERSIZE);
   if(verbosity) {
@@ -443,8 +444,13 @@
     error("database file has incorect version", dbName);
   }
 
+  // FIXME: when changing file format version, remove this workaround.
+  if(dbH->dbSize == 0) {
+    dbH->dbSize = O2_DEFAULTDBSIZE;
+  }
+
   // mmap the database file
-  if ((db = (char*) mmap(0, O2_DEFAULTDBSIZE, PROT_READ | (forWrite ? PROT_WRITE : 0),
+  if ((db = (char*) mmap(0, dbH->dbSize, PROT_READ | (forWrite ? PROT_WRITE : 0),
 			 MAP_SHARED, dbfid, 0)) == (caddr_t) -1)
     error("mmap error for initting tables of database", "", "mmap");
 
@@ -523,7 +529,7 @@
     }
     // CLEAN UP
     munmap(indata,statbuf.st_size);
-    munmap(db,O2_DEFAULTDBSIZE);
+    munmap(db,dbH->dbSize);
     close(infid);
     return;
   }
@@ -583,7 +589,7 @@
    if(!timesFile->is_open()){
      if(dbH->flags & O2_FLAG_TIMES){
        munmap(indata,statbuf.st_size);
-       munmap(db,O2_DEFAULTDBSIZE);
+       munmap(db,dbH->dbSize);
        error("problem opening times file on timestamped database",timesFileName);
      }
      else{
@@ -611,7 +617,7 @@
      }
      if(numtimes<numVectors || numtimes>numVectors+2){
        munmap(indata,statbuf.st_size);
-       munmap(db,O2_DEFAULTDBSIZE);
+       munmap(db,dbH->dbSize);
        close(infid);
        cerr << "expected " << numVectors << " found " << numtimes << endl;
        error("Times file is incorrect length for features file",inFile);
--- a/audioDB.h	Thu Oct 18 13:30:57 2007 +0000
+++ b/audioDB.h	Fri Oct 19 13:51:53 2007 +0000
@@ -96,13 +96,15 @@
   // unportable between 32 and 64-bit architectures.  Making them
   // uint32_t isn't the real answer, as it means we won't be able to
   // scale to really large collections easily but it works around the
-  // problem.  -- CSR, 2007-10-05
+  // problem.  Expanding to 64 bits will of course need a change in
+  // file format version.  -- CSR, 2007-10-05
   uint32_t length;
   uint32_t fileTableOffset;
   uint32_t trackTableOffset;
   uint32_t dataOffset;
   uint32_t l2normTableOffset;
   uint32_t timesTableOffset;
+  uint32_t dbSize;
 } dbTableHeaderT, *dbTableHeaderPtr;