]> source.dussan.org Git - jackcess.git/commitdiff
fix some problems with sporadic usage map corruption
authorJames Ahlborn <jtahlborn@yahoo.com>
Thu, 17 Jan 2008 16:16:04 +0000 (16:16 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Thu, 17 Jan 2008 16:16:04 +0000 (16:16 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@217 f203690c-595d-4dc9-a70b-905162fa7fd2

src/changes/changes.xml
src/java/com/healthmarketscience/jackcess/UsageMap.java

index d83c1335b1f2d870188740b7c9c78a6d1277fdf2..77d34a6da1dba2c1707722599ac151b6b9b3d4de 100644 (file)
@@ -6,6 +6,9 @@
   </properties>
   <body>
     <release version="1.1.11" date="TBD">
+      <action dev="jahlborn" type="fix">
+        Fix some problems with sporadic usage map corruption.
+      </action>
       <action dev="jahlborn" type="update">
         Move from cvs to subversion.
       </action>
index c0bbd8bc6141a6ef79fa548524fc188899ff946f..d5f0237cb71a44087bb302f6f15c1cf271ef92b0 100644 (file)
@@ -657,12 +657,14 @@ public class UsageMap
       int pageIndex = (int)(pageNumber / getMaxPagesPerUsagePage());
       int mapPageNum = getTableBuffer().getInt(
           calculateMapPagePointerOffset(pageIndex));
-      if(mapPageNum <= 0) {
+      ByteBuffer mapPageBuffer = null;
+      if(mapPageNum > 0) {
+        mapPageBuffer = _mapPageHolder.setPage(getPageChannel(), mapPageNum);
+      } else {
         // Need to create a new usage map page
-        mapPageNum  = createNewUsageMapPage(pageIndex);
+        mapPageBuffer = createNewUsageMapPage(pageIndex);
+        mapPageNum = _mapPageHolder.getPageNumber();
       }
-      ByteBuffer mapPageBuffer = _mapPageHolder.setPage(getPageChannel(),
-                                                        mapPageNum);
       updateMap(pageNumber,
                 (pageNumber - (getMaxPagesPerUsagePage() * pageIndex)),
                 mapPageBuffer, add);
@@ -674,19 +676,17 @@ public class UsageMap
      * pointer to it.
      * @param pageIndex Index of the page reference within the map declaration 
      */
-    private int createNewUsageMapPage(int pageIndex) throws IOException {
+    private ByteBuffer createNewUsageMapPage(int pageIndex) throws IOException
+    {
       ByteBuffer mapPageBuffer = _mapPageHolder.setNewPage(getPageChannel());
       mapPageBuffer.put(PageTypes.USAGE_MAP);
       mapPageBuffer.put((byte) 0x01);  //Unknown
       mapPageBuffer.putShort((short) 0); //Unknown
-      for(int i = 0; i < mapPageBuffer.limit(); ++i) {
-        mapPageBuffer.get(i);
-      }
       int mapPageNum = _mapPageHolder.getPageNumber();
       getTableBuffer().putInt(calculateMapPagePointerOffset(pageIndex),
                              mapPageNum);
       writeTable();
-      return mapPageNum;
+      return mapPageBuffer;
     }
   
     private int calculateMapPagePointerOffset(int pageIndex) {