]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhance the pcache1 implementation so that during an xRekey operation if
authordrh <>
Fri, 2 Sep 2022 14:29:54 +0000 (14:29 +0000)
committerdrh <>
Fri, 2 Sep 2022 14:29:54 +0000 (14:29 +0000)
another page already exists at the destination, that other page gets moved
to the source key.

FossilOrigin-Name: aadd38f99a3e5abcf9bef49f4367752f163cc79500a28f812bb71969d7de419c

manifest
manifest.uuid
src/pcache1.c

index 881f344e8dfb0ea291e118050579d49526cf4181..36e32cc367fa9d531243fca24e92b7ed745022f1 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Mutex\sprotect\saccess\sto\sthe\ssqlite3_test_directory\sand\ssqlite3_data_directory\nglobal\svariables.\s\sSee\n[forum:/forumpost/719a11e1314d1c70|forum\sthread\s719a11e1314d1c70].
-D 2022-09-02T11:45:26.675
+C Enhance\sthe\spcache1\simplementation\sso\sthat\sduring\san\sxRekey\soperation\sif\nanother\spage\salready\sexists\sat\sthe\sdestination,\sthat\sother\spage\sgets\smoved\nto\sthe\ssource\skey.
+D 2022-09-02T14:29:54.641
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -580,7 +580,7 @@ F src/pager.h f82e9844166e1585f5786837ddc7709966138ced17f568c16af7ccf946c2baa3
 F src/parse.y 8e67d820030d2655b9942ffe61c1e7e6b96cea2f2f72183533299393907d0564
 F src/pcache.c 5a64e084260560910d9a61bc0e760394fa88aaa22201477ab3e49e278db92edb
 F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586
-F src/pcache1.c 5cde56d6bb057b0d7420f89bebd3bb9103f4ed9acfc17cef765dca8c33cd3a1f
+F src/pcache1.c 849a26ea9dc1e6a176b75dc576672a598170b0b46aeef87a981dd25e0af0ccf9
 F src/pragma.c 9bf7d8a2a9ad3bc36df3ec0d61817a44c38a1da527d59c26c203047f906e334a
 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7
 F src/prepare.c 971d5819a4bda88038c2283d71fc0a2974ffc3dd480f9bd941341017abacfd1b
@@ -1999,9 +1999,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 1c4157c71cd1e062a9c2c79787d17e34e340f28ce1e40573851dfe174f5da7d7 ebbe9634d6dde9e097f61fb98a79111e46de422b7bbbd9ed3af7b6f22aacf5ec
-R ceab41e21a2b5216a46a28807cd5555b
-T +closed ebbe9634d6dde9e097f61fb98a79111e46de422b7bbbd9ed3af7b6f22aacf5ec
+P 8e6ad3a3e942a326cf16432e16d6596c7206c05b6f45cd0ff3a9b836bcfc9deb
+R 01ad42a8d2f31eadbe33e5f4a288db74
 U drh
-Z 6792df766aacf245b78e8d274ef8f48f
+Z dced8cd032db7b035db78c488a02a704
 # Remove this line to create a well-formed Fossil manifest.
index ee3a8ffbf8af14e09dc40925b5f91740a0fe9fa3..dc8be391e2196702084ab2368017ab137c5616f8 100644 (file)
@@ -1 +1 @@
-8e6ad3a3e942a326cf16432e16d6596c7206c05b6f45cd0ff3a9b836bcfc9deb
\ No newline at end of file
+aadd38f99a3e5abcf9bef49f4367752f163cc79500a28f812bb71969d7de419c
\ No newline at end of file
index 3e406a7a8970b1a879d7de3d1fb1b31b26238d7f..a47087fa1134df2b2d63721c9f996d7f8d50f5e6 100644 (file)
@@ -1119,7 +1119,7 @@ static void pcache1Rekey(
   PCache1 *pCache = (PCache1 *)p;
   PgHdr1 *pPage = (PgHdr1 *)pPg;
   PgHdr1 **pp;
-  unsigned int h; 
+  unsigned int hOld, hNew
   assert( pPage->iKey==iOld );
   assert( pPage->pCache==pCache );
   assert( iOld!=iNew );               /* The page number really is changing */
@@ -1127,18 +1127,33 @@ static void pcache1Rekey(
   pcache1EnterMutex(pCache->pGroup);
   
   assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
-  h = iOld%pCache->nHash;
-  pp = &pCache->apHash[h];
+  hOld = iOld%pCache->nHash;
+  pp = &pCache->apHash[hOld];
   while( (*pp)!=pPage ){
     pp = &(*pp)->pNext;
   }
   *pp = pPage->pNext;
 
-  assert( pcache1FetchNoMutex(p, iNew, 0)==0 ); /* iNew not previously used */
-  h = iNew%pCache->nHash;
+  hNew = iNew%pCache->nHash;
+  pp = &pCache->apHash[hNew];
+  while( *pp ){
+    if( (*pp)->iKey==iNew ){
+      /* If there is already another pcache entry at iNew, change it to iOld,
+      ** thus swapping the positions of iNew and iOld */
+      PgHdr1 *pOld = *pp;
+      *pp = pOld->pNext;
+      pOld->pNext = pCache->apHash[hOld];
+      pCache->apHash[hOld] = pOld;
+      pOld->iKey = iOld;
+      break;
+    }else{
+      pp = &(*pp)->pNext;
+    }
+  }
+
   pPage->iKey = iNew;
-  pPage->pNext = pCache->apHash[h];
-  pCache->apHash[h] = pPage;
+  pPage->pNext = pCache->apHash[hNew];
+  pCache->apHash[hNew] = pPage;
   if( iNew>pCache->iMaxKey ){
     pCache->iMaxKey = iNew;
   }