Skip to content

Commit 4e9bf5a

Browse files
author
drh
committed
Enhance the pcache1 implementation so that during an xRekey operation if
another page already exists at the destination, that other page gets moved to the source key. FossilOrigin-Name: aadd38f99a3e5abcf9bef49f4367752f163cc79500a28f812bb71969d7de419c
1 parent e04c9f4 commit 4e9bf5a

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

manifest

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
C Mutex\sprotect\saccess\sto\sthe\ssqlite3_test_directory\sand\ssqlite3_data_directory\nglobal\svariables.\s\sSee\n[forum:/forumpost/719a11e1314d1c70|forum\sthread\s719a11e1314d1c70].
2-
D 2022-09-02T11:45:26.675
1+
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.
2+
D 2022-09-02T14:29:54.641
33
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
44
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
55
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -580,7 +580,7 @@ F src/pager.h f82e9844166e1585f5786837ddc7709966138ced17f568c16af7ccf946c2baa3
580580
F src/parse.y 8e67d820030d2655b9942ffe61c1e7e6b96cea2f2f72183533299393907d0564
581581
F src/pcache.c 5a64e084260560910d9a61bc0e760394fa88aaa22201477ab3e49e278db92edb
582582
F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586
583-
F src/pcache1.c 5cde56d6bb057b0d7420f89bebd3bb9103f4ed9acfc17cef765dca8c33cd3a1f
583+
F src/pcache1.c 849a26ea9dc1e6a176b75dc576672a598170b0b46aeef87a981dd25e0af0ccf9
584584
F src/pragma.c 9bf7d8a2a9ad3bc36df3ec0d61817a44c38a1da527d59c26c203047f906e334a
585585
F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7
586586
F src/prepare.c 971d5819a4bda88038c2283d71fc0a2974ffc3dd480f9bd941341017abacfd1b
@@ -1999,9 +1999,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
19991999
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
20002000
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
20012001
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
2002-
P 1c4157c71cd1e062a9c2c79787d17e34e340f28ce1e40573851dfe174f5da7d7 ebbe9634d6dde9e097f61fb98a79111e46de422b7bbbd9ed3af7b6f22aacf5ec
2003-
R ceab41e21a2b5216a46a28807cd5555b
2004-
T +closed ebbe9634d6dde9e097f61fb98a79111e46de422b7bbbd9ed3af7b6f22aacf5ec
2002+
P 8e6ad3a3e942a326cf16432e16d6596c7206c05b6f45cd0ff3a9b836bcfc9deb
2003+
R 01ad42a8d2f31eadbe33e5f4a288db74
20052004
U drh
2006-
Z 6792df766aacf245b78e8d274ef8f48f
2005+
Z dced8cd032db7b035db78c488a02a704
20072006
# Remove this line to create a well-formed Fossil manifest.

manifest.uuid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8e6ad3a3e942a326cf16432e16d6596c7206c05b6f45cd0ff3a9b836bcfc9deb
1+
aadd38f99a3e5abcf9bef49f4367752f163cc79500a28f812bb71969d7de419c

src/pcache1.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,26 +1119,41 @@ static void pcache1Rekey(
11191119
PCache1 *pCache = (PCache1 *)p;
11201120
PgHdr1 *pPage = (PgHdr1 *)pPg;
11211121
PgHdr1 **pp;
1122-
unsigned int h;
1122+
unsigned int hOld, hNew;
11231123
assert( pPage->iKey==iOld );
11241124
assert( pPage->pCache==pCache );
11251125
assert( iOld!=iNew ); /* The page number really is changing */
11261126

11271127
pcache1EnterMutex(pCache->pGroup);
11281128

11291129
assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
1130-
h = iOld%pCache->nHash;
1131-
pp = &pCache->apHash[h];
1130+
hOld = iOld%pCache->nHash;
1131+
pp = &pCache->apHash[hOld];
11321132
while( (*pp)!=pPage ){
11331133
pp = &(*pp)->pNext;
11341134
}
11351135
*pp = pPage->pNext;
11361136

1137-
assert( pcache1FetchNoMutex(p, iNew, 0)==0 ); /* iNew not previously used */
1138-
h = iNew%pCache->nHash;
1137+
hNew = iNew%pCache->nHash;
1138+
pp = &pCache->apHash[hNew];
1139+
while( *pp ){
1140+
if( (*pp)->iKey==iNew ){
1141+
/* If there is already another pcache entry at iNew, change it to iOld,
1142+
** thus swapping the positions of iNew and iOld */
1143+
PgHdr1 *pOld = *pp;
1144+
*pp = pOld->pNext;
1145+
pOld->pNext = pCache->apHash[hOld];
1146+
pCache->apHash[hOld] = pOld;
1147+
pOld->iKey = iOld;
1148+
break;
1149+
}else{
1150+
pp = &(*pp)->pNext;
1151+
}
1152+
}
1153+
11391154
pPage->iKey = iNew;
1140-
pPage->pNext = pCache->apHash[h];
1141-
pCache->apHash[h] = pPage;
1155+
pPage->pNext = pCache->apHash[hNew];
1156+
pCache->apHash[hNew] = pPage;
11421157
if( iNew>pCache->iMaxKey ){
11431158
pCache->iMaxKey = iNew;
11441159
}

0 commit comments

Comments
 (0)