Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Changes to test_quota.c to make quota groups persistent even after files are closed. Files remain a part of the quota group until they are deleted. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
04111ce980df9692b7fe65a36105e7de |
User & Date: | drh 2011-08-24 01:25:55.043 |
Context
2011-08-24
| ||
15:12 | Fix some harmless compiler warnings. (check-in: 46f5a68bfa user: drh tags: trunk) | |
01:25 | Changes to test_quota.c to make quota groups persistent even after files are closed. Files remain a part of the quota group until they are deleted. (check-in: 04111ce980 user: drh tags: trunk) | |
2011-08-23
| ||
23:41 | Simplifications to the SQLITE_PAGECACHE_BLOCKALLOC logic. Reduce the number of difficult-to-reach branches. (check-in: d5d835fe83 user: drh tags: trunk) | |
Changes
Changes to src/test_quota.c.
︙ | |||
91 92 93 94 95 96 97 98 99 100 101 102 103 104 | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | + | ** to the same file each point to a single instance of this object. */ struct quotaFile { char *zFilename; /* Name of this file */ quotaGroup *pGroup; /* Quota group to which this file belongs */ sqlite3_int64 iSize; /* Current size of this file */ int nRef; /* Number of times this file is open */ int deleteOnClose; /* True to delete this file when it closes */ quotaFile *pNext, **ppPrev; /* Linked list of files in the same group */ }; /* ** An instance of the following object represents each open connection ** to a file that participates in quota tracking. This object is a ** subclass of sqlite3_file. The sqlite3_file object for the underlying |
︙ | |||
160 161 162 163 164 165 166 167 168 169 170 171 | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + | /* ** Acquire and release the mutex used to serialize access to the ** list of quotaGroups. */ static void quotaEnter(void){ sqlite3_mutex_enter(gQuota.pMutex); } static void quotaLeave(void){ sqlite3_mutex_leave(gQuota.pMutex); } /* Count the number of open files in a quotaGroup */ static int quotaGroupOpenFileCount(quotaGroup *pGroup){ int N = 0; quotaFile *pFile = pGroup->pFiles; while( pFile ){ if( pFile->nRef ) N++; pFile = pFile->pNext; } return N; } /* Remove a file from a quota group. */ static void quotaRemoveFile(quotaFile *pFile){ quotaGroup *pGroup = pFile->pGroup; pGroup->iSize -= pFile->iSize; *pFile->ppPrev = pFile->pNext; if( pFile->pNext ) pFile->pNext->ppPrev = pFile->ppPrev; sqlite3_free(pFile); } /* Remove all files from a quota group. It is always the case that ** all files will be closed when this routine is called. */ static void quotaRemoveAllFiles(quotaGroup *pGroup){ while( pGroup->pFiles ){ assert( pGroup->pFiles->nRef==0 ); quotaRemoveFile(pGroup->pFiles); } } /* If the reference count and threshold for a quotaGroup are both ** zero, then destroy the quotaGroup. */ static void quotaGroupDeref(quotaGroup *pGroup){ |
︙ | |||
271 272 273 274 275 276 277 278 279 280 281 282 283 284 | 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | + + + + + + + + + + + | /* Translate an sqlite3_file* that is really a quotaConn* into ** the sqlite3_file* for the underlying original VFS. */ static sqlite3_file *quotaSubOpen(sqlite3_file *pConn){ quotaConn *p = (quotaConn*)pConn; return (sqlite3_file*)&p[1]; } /* Find a file in a quota group and return a pointer to that file. ** Return NULL if the file is not in the group. */ static quotaFile *quotaFindFile(quotaGroup *pGroup, const char *zName){ quotaFile *pFile = pGroup->pFiles; while( pFile && strcmp(pFile->zFilename, zName)!=0 ){ pFile = pFile->pNext; } return pFile; } /************************* VFS Method Wrappers *****************************/ /* ** This is the xOpen method used for the "quota" VFS. ** ** Most of the work is done by the underlying original VFS. This method ** simply links the new file into the appropriate quota group if it is a |
︙ | |||
315 316 317 318 319 320 321 | 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - - | }else{ /* If we get to this point, it means the file needs to be quota tracked. */ pQuotaOpen = (quotaConn*)pConn; pSubOpen = quotaSubOpen(pConn); rc = pOrigVfs->xOpen(pOrigVfs, zName, pSubOpen, flags, pOutFlags); if( rc==SQLITE_OK ){ |
︙ | |||
582 583 584 585 586 587 588 589 590 591 592 593 594 595 | 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | + | if( !gQuota.pMutex ){ return SQLITE_NOMEM; } gQuota.isInitialized = 1; gQuota.pOrigVfs = pOrigVfs; gQuota.sThisVfs = *pOrigVfs; gQuota.sThisVfs.xOpen = quotaOpen; gQuota.sThisVfs.xDelete = quotaDelete; gQuota.sThisVfs.szOsFile += sizeof(quotaConn); gQuota.sThisVfs.zName = "quota"; gQuota.sIoMethodsV1.iVersion = 1; gQuota.sIoMethodsV1.xClose = quotaClose; gQuota.sIoMethodsV1.xRead = quotaRead; gQuota.sIoMethodsV1.xWrite = quotaWrite; gQuota.sIoMethodsV1.xTruncate = quotaTruncate; |
︙ | |||
613 614 615 616 617 618 619 | 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 | - + - + + | /* ** Shutdown the quota system. ** ** All SQLite database connections must be closed before calling this ** routine. ** |
︙ | |||
913 914 915 916 917 918 919 920 921 922 923 924 925 926 | 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | + + | pFileTerm = Tcl_NewObj(); Tcl_ListObjAppendElement(interp, pFileTerm, Tcl_NewStringObj(pFile->zFilename, -1)); Tcl_ListObjAppendElement(interp, pFileTerm, Tcl_NewWideIntObj(pFile->iSize)); Tcl_ListObjAppendElement(interp, pFileTerm, Tcl_NewWideIntObj(pFile->nRef)); Tcl_ListObjAppendElement(interp, pFileTerm, Tcl_NewWideIntObj(pFile->deleteOnClose)); Tcl_ListObjAppendElement(interp, pGroupTerm, pFileTerm); } Tcl_ListObjAppendElement(interp, pResult, pGroupTerm); } quotaLeave(); Tcl_SetObjResult(interp, pResult); return TCL_OK; |
︙ |
Changes to test/quota.test.
︙ | |||
219 220 221 222 223 224 225 | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | - + | do_test quota-3.2.X { foreach db {db1a db2a db2b db1b} { catch { $db close } } sqlite3_quota_set * 0 {} } {SQLITE_OK} #------------------------------------------------------------------------- |
︙ | |||
326 327 328 329 330 331 332 333 334 335 | 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + | sqlite3 db A sqlite3_quota_set A 0 quota_callback db close quota_list } {} do_test quota-4.4.1 { set ::quota {} sqlite3_quota_set */quota-test-A?.db 10000 quota_callback file delete -force ./quota-test-A1.db ./quota-test-A2.db sqlite3 db ./quota-test-A1.db db eval { CREATE TABLE t1(x); INSERT INTO t1 VALUES(randomblob(5000)); } quota_list } {*/quota-test-A?.db} do_test quota-4.4.2 { expr {$::quota==""} } {1} do_test quota-4.4.3 { db close sqlite3 db ./quota-test-A2.db db eval { CREATE TABLE t1(x); INSERT INTO t1 VALUES(randomblob(5000)); } quota_list } {*/quota-test-A?.db} do_test quota-4.4.4 { expr {$::quota!=""} } {1} do_test quota-4.9.1 { db close sqlite3_quota_set A 1000 quota_callback sqlite3_quota_shutdown } {SQLITE_OK} |
︙ |