From: drh <> Date: Sat, 10 Sep 2022 18:38:21 +0000 (+0000) Subject: Improved comments in os_kv.c. Better names for the key/value name spaces. X-Git-Tag: version-3.40.0~169^2~123^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c6c9c6aad0a8652d3daf0298fe9d411b03c79c41;p=thirdparty%2Fsqlite.git Improved comments in os_kv.c. Better names for the key/value name spaces. FossilOrigin-Name: 8e1652a3856765c9146cc2a7e3b598a2dc7dc84c556b35eab9a35184514384b9 --- diff --git a/manifest b/manifest index a139582803..23b98932b2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Move\sthe\svfskv.c\sextension\sto\ssrc/os_kv.c\sand\smake\sit\spart\sof\sthe\samalgamation,\nactivated\sif\sand\sonly\sif\sSQLITE_OS_KV\sis\strue. -D 2022-09-10T18:20:59.146 +C Improved\scomments\sin\sos_kv.c.\s\sBetter\snames\sfor\sthe\skey/value\sname\sspaces. +D 2022-09-10T18:38:21.976 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -571,7 +571,7 @@ F src/notify.c 89a97dc854c3aa62ad5f384ef50c5a4a11d70fcc69f86de3e991573421130ed6 F src/os.c 0eb831ba3575af5277e47f4edd14fdfc90025c67eb25ce5cda634518d308d4e9 F src/os.h 1ff5ae51d339d0e30d8a9d814f4b8f8e448169304d83a7ed9db66a65732f3e63 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 -F src/os_kv.c dc409476c3e533def81d022849726f2892e69e6529d4a40a637224cfb3f5df68 w ext/misc/vfskv.c +F src/os_kv.c c658ddfb433b982afb3d12d133117e8db9eee11af33db41c30a6f30375f9b99a F src/os_setup.h 0711dbc4678f3ac52d7fe736951b6384a0615387c4ba5135a4764e4e31f4b6a6 F src/os_unix.c 102f7e5c5b59c18ea3dbc929dc3be8acb3afc0e0b6ad572e032335c9c27f44f1 F src/os_win.c e9454cb141908e8eef2102180bad353a36480612d5b736e4c2bd5777d9b25a34 @@ -2001,8 +2001,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 c8e41279294ea7c2f041c7d4cbbd85fce47d55f2f56180ca837316f7dfd75237 -R 781601077fda92ceda7382ba24a16664 +P f6632e69c2ec1a7ddc4e51f3567e3bc082ee94a6dd51fdafdc0c3bf386a32d4c +R 8cd4482ba17a8f6c143ea61b8462f46c U drh -Z b2ad663d300b47ac24999ede7b88d1e7 +Z 81846bec91bdcab04bc60c9c032d039e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4bfd8ba9c2..c114a26d08 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f6632e69c2ec1a7ddc4e51f3567e3bc082ee94a6dd51fdafdc0c3bf386a32d4c \ No newline at end of file +8e1652a3856765c9146cc2a7e3b598a2dc7dc84c556b35eab9a35184514384b9 \ No newline at end of file diff --git a/src/os_kv.c b/src/os_kv.c index 8ae1a65c59..1412de8122 100644 --- a/src/os_kv.c +++ b/src/os_kv.c @@ -165,26 +165,28 @@ static sqlite3_io_methods kvvfs_jrnl_io_methods = { /* Forward declarations for the low-level storage engine */ -#define KVSTORAGE_KEY_SZ 24 -#define KVSTORAGE_KEY_PREFIX "kvvfs-" +#define KVSTORAGE_KEY_SZ 32 static int kvstorageWrite(const char*, const char *zKey, const char *zData); static int kvstorageDelete(const char*, const char *zKey); static int kvstorageRead(const char*, const char *zKey, char *zBuf, int nBuf); /* Expand the key name with an appropriate prefix and put the result -** in pStore->zKey[] +** zKeyOut[]. The zKeyOut[] buffer is assumed to hold at least +** KVSTORAGE_KEY_SZ bytes. */ static void kvstorageMakeKey( const char *zClass, const char *zKeyIn, char *zKeyOut ){ - sqlite3_snprintf(KVSTORAGE_KEY_SZ, zKeyOut, "%s-%s", zClass, zKeyIn); + sqlite3_snprintf(KVSTORAGE_KEY_SZ, zKeyOut, "kvvfs-%s-%s", zClass, zKeyIn); } -/* Write content into a key. zKey is of limited size. zData should be -** pure text. In other words, zData has already been encoded. +/* Write content into a key. zClass is the particular namespace of the +** underlying key/value store to use - either "local" or "session". +** +** Both zKey and zData are zero-terminated pure text strings. ** ** Return the number of errors. */ @@ -209,7 +211,9 @@ static int kvstorageWrite( } } -/* Delete a key +/* Delete a key (with its corresponding data) from the key/value +** namespace given by zClass. If the key does not previously exist, +** this routine is a no-op. */ static int kvstorageDelete(const char *zClass, const char *zKey){ char zXKey[KVSTORAGE_KEY_SZ]; @@ -219,16 +223,17 @@ static int kvstorageDelete(const char *zClass, const char *zKey){ return 0; } -/* Read the value associated with a key and put the result in the first +/* Read the value associated with a zKey from the key/value namespace given +** by zClass and put the text data associated with that key in the first ** nBuf bytes of zBuf[]. The value might be truncated if zBuf is not large -** enough to hold it all. The value put into zBuf will always be zero -** terminated. +** enough to hold it all. The value put into zBuf must always be zero +** terminated, even if it gets truncated because nBuf is not large enough. ** ** Return the total number of bytes in the data, without truncation, and ** not counting the final zero terminator. Return -1 if the key does ** not exist. ** -** If nBuf==0 then this routine simply returns the size of the data without +** If nBuf<=0 then this routine simply returns the size of the data without ** actually reading it. */ static int kvstorageRead( @@ -248,7 +253,7 @@ static int kvstorageRead( SQLITE_KV_TRACE(("KVVFS-READ %-15s (-1)\n", zXKey)); return -1; } - if( nBuf<0 ){ + if( nBuf<=0 ){ return (int)buf.st_size; }else if( nBuf==1 ){ zBuf[0] = 0; @@ -275,7 +280,6 @@ static int kvstorageRead( /****** Utility subroutines ************************************************/ - /* ** Encode binary into the text encoded used to persist on disk. ** The output text is stored in aOut[], which must be at least @@ -446,7 +450,7 @@ static int kvvfsReadJrnl( assert( pFile->isJournal ); SQLITE_KV_LOG(("xRead('%s-journal',%d,%lld)\n", pFile->zClass, iAmt, iOfst)); if( pFile->aJrnl==0 ){ - int szTxt = kvstorageRead(pFile->zClass, "jrnl", 0, -1); + int szTxt = kvstorageRead(pFile->zClass, "jrnl", 0, 0); char *aTxt; if( szTxt<=4 ){ return SQLITE_IOERR; @@ -752,9 +756,9 @@ static int kvvfsOpen( return SQLITE_CANTOPEN; } if( zName[0]=='s' ){ - pFile->zClass = KVSTORAGE_KEY_PREFIX "ses"; + pFile->zClass = "session"; }else{ - pFile->zClass = KVSTORAGE_KEY_PREFIX "loc"; + pFile->zClass = "local"; } pFile->aJrnl = 0; pFile->nJrnl = 0; @@ -770,10 +774,10 @@ static int kvvfsOpen( */ static int kvvfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ if( strcmp(zPath, "local-journal")==0 ){ - kvstorageDelete(KVSTORAGE_KEY_PREFIX "loc", "jrnl"); + kvstorageDelete("local", "jrnl"); }else if( strcmp(zPath, "session-journal")==0 ){ - kvstorageDelete(KVSTORAGE_KEY_PREFIX "ses", "jrnl"); + kvstorageDelete("session", "jrnl"); } return SQLITE_OK; } @@ -790,16 +794,16 @@ static int kvvfsAccess( ){ SQLITE_KV_LOG(("xAccess(\"%s\")\n", zPath)); if( strcmp(zPath, "local-journal")==0 ){ - *pResOut = kvstorageRead(KVSTORAGE_KEY_PREFIX "loc", "jrnl", 0, -1)>0; + *pResOut = kvstorageRead("local", "jrnl", 0, 0)>0; }else if( strcmp(zPath, "session-journal")==0 ){ - *pResOut = kvstorageRead(KVSTORAGE_KEY_PREFIX "ses", "jrnl", 0, -1)>0; + *pResOut = kvstorageRead("session", "jrnl", 0, 0)>0; }else if( strcmp(zPath, "local")==0 ){ - *pResOut = kvstorageRead(KVSTORAGE_KEY_PREFIX "loc", "sz", 0, -1)>0; + *pResOut = kvstorageRead("local", "sz", 0, 0)>0; }else if( strcmp(zPath, "session")==0 ){ - *pResOut = kvstorageRead(KVSTORAGE_KEY_PREFIX "ses", "sz", 0, -1)>0; + *pResOut = kvstorageRead("session", "sz", 0, 0)>0; }else { *pResOut = 0;