Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Clean up comments in the test_quota.c source file. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | experimental |
Files: | files | file ages | folders |
SHA1: |
c1eec7dba698e5bad0870cb80079203f |
User & Date: | drh 2010-09-01 13:09:57.000 |
Context
2010-09-01
| ||
14:35 | Add the sqlite3_quota_dump test command. Add a destructor argument on the sqlite3_quota_set() interface. (check-in: 7a624b5ae2 user: drh tags: experimental) | |
13:09 | Clean up comments in the test_quota.c source file. (check-in: c1eec7dba6 user: drh tags: experimental) | |
12:50 | Update the quota shim so that when the same file is opened multiple times, its size only counts against the quota once. (check-in: f5d2638030 user: drh tags: experimental) | |
Changes
Changes to src/test_quota.c.
︙ | ︙ | |||
35 36 37 38 39 40 41 | /* Forward declaration of all object types */ typedef struct quotaGroup quotaGroup; typedef struct quotaOpen quotaOpen; typedef struct quotaFile quotaFile; /* | | < | | > > > > > | | | < < | | > | | | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | /* Forward declaration of all object types */ typedef struct quotaGroup quotaGroup; typedef struct quotaOpen quotaOpen; typedef struct quotaFile quotaFile; /* ** A "quota group" is a collection of files whose collective size we want ** to limit. Each quota group is defined by a GLOB pattern. ** ** There is an instance of the following object for each defined quota ** group. This object records the GLOB pattern that defines which files ** belong to the quota group. The object also remembers the size limit ** for the group (the quota) and the callback to be invoked when the ** sum of the sizes of the files within the group goes over the limit. ** ** A quota group must be established (using sqlite3_quota_set(...)) ** prior to opening any of the database connections that access files ** within the quota group. */ struct quotaGroup { const char *zPattern; /* Filename pattern to be quotaed */ sqlite3_int64 iLimit; /* Upper bound on total file size */ sqlite3_int64 iSize; /* Current size of all files */ void (*xCallback)( /* Callback invoked when going over quota */ const char *zFilename, /* Name of file whose size increases */ sqlite3_int64 *piLimit, /* IN/OUT: The current limit */ sqlite3_int64 iSize, /* Total size of all files in the group */ void *pArg /* Client data */ ); void *pArg; /* Third argument to the xCallback() */ quotaGroup *pNext, **ppPrev; /* Doubly linked list of all quota objects */ quotaFile *pFile; /* Files within this group */ }; /* ** An instance of this structure represents a single file that is part ** of a quota group. A single file can be opened multiple times. In ** order keep multiple openings of the same file from causing the size ** of the file to count against the quota multiple times, each file ** has a unique instance of this object and multiple open connections ** to the same file each point to a single instance of this object. */ struct quotaFile { char *zFilename; /* Name of this file */ quotaGroup *pGroup; /* Upper bound on file size */ sqlite3_int64 iSize; /* Current size of this file */ int nRef; /* Number of times this file is open */ 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 ** VFS is appended to this structure. */ struct quotaOpen { sqlite3_file base; /* Base class - must be first */ quotaFile *pFile; /* The underlying file */ /* The underlying VFS sqlite3_file is appended to this object */ }; /************************* Global Variables **********************************/ /* ** All global variables used by this file are containing within the following ** gQuota structure. */ static struct { /* The pOrigVfs is the real, original underlying VFS implementation. ** Most operations pass-through to the real VFS. This value is read-only ** during operation. It is only modified at start-time and thus does not ** require a mutex. */ sqlite3_vfs *pOrigVfs; /* The sThisVfs is the VFS structure used by this shim. It is initialized |
︙ | ︙ | |||
245 246 247 248 249 250 251 | static quotaGroup *quotaGroupFind(const char *zFilename){ quotaGroup *p; for(p=gQuota.pGroup; p && strglob(p->zPattern, zFilename)==0; p=p->pNext){} return p; } /* Translate an sqlite3_file* that is really a quotaOpen* into | | | | | | | | | | | | | | | | 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | static quotaGroup *quotaGroupFind(const char *zFilename){ quotaGroup *p; for(p=gQuota.pGroup; p && strglob(p->zPattern, zFilename)==0; p=p->pNext){} return p; } /* Translate an sqlite3_file* that is really a quotaOpen* into ** the sqlite3_file* for the underlying original VFS. */ static sqlite3_file *quotaSubOpen(sqlite3_file *pOpen){ quotaOpen *p = (quotaOpen*)pOpen; return (sqlite3_file*)&p[1]; } /************************* 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 ** file that needs to be tracked. */ static int quotaxOpen( sqlite3_vfs *pVfs, /* The quota VFS */ const char *zName, /* Name of file to be opened */ sqlite3_file *pOpen, /* Fill in this file descriptor */ int flags, /* Flags to control the opening */ int *pOutFlags /* Flags showing results of opening */ ){ int rc; /* Result code */ quotaOpen *pQuotaOpen; /* The new quota file descriptor */ quotaFile *pFile; /* Corresponding quotaFile obj */ quotaGroup *pGroup; /* The group file belongs to */ sqlite3_file *pSubOpen; /* Real file descriptor */ sqlite3_vfs *pOrigVfs = gQuota.pOrigVfs; /* Real VFS */ /* If the file is not a main database file or a WAL, then use the ** normal xOpen method. */ if( (flags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_WAL))==0 ){ return pOrigVfs->xOpen(pOrigVfs, zName, pOpen, flags, pOutFlags); } |
︙ | ︙ |