SQLite4
Check-in [7343be21c9]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the BT_CONTROL_MULTIPROC option.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7343be21c964a03f08a91379e3880c621cf06ce8
User & Date: dan 2013-11-11 20:27:05
Context
2013-11-13
15:21
Fix an issue with using a bt cursor after sqlite4BtCsrDelete() has been called on it. check-in: f10991c423 user: dan tags: trunk
2013-11-11
20:27
Add the BT_CONTROL_MULTIPROC option. check-in: 7343be21c9 user: dan tags: trunk
20:06
Add support for multiple processes to bt. check-in: 1336c5d00a user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lsm-test/lsmtest_tdb4.c.

599
600
601
602
603
604
605
606

607
608
609
610
611
612
613

  if( zCfg ){
    struct CfgParam {
      const char *zParam;
      int eParam;
    } aParam[] = {
      { "safety",         BT_CONTROL_SAFETY },
      { "autockpt",       BT_CONTROL_AUTOCKPT }

    };
    const char *z = zCfg;
    int n = strlen(z);
    char *aSpace;
    const char *zOpt;
    const char *zArg;








|
>







599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

  if( zCfg ){
    struct CfgParam {
      const char *zParam;
      int eParam;
    } aParam[] = {
      { "safety",         BT_CONTROL_SAFETY },
      { "autockpt",       BT_CONTROL_AUTOCKPT },
      { "multiproc",      BT_CONTROL_MULTIPROC }
    };
    const char *z = zCfg;
    int n = strlen(z);
    char *aSpace;
    const char *zOpt;
    const char *zArg;

Changes to src/bt.h.

159
160
161
162
163
164
165
166



167
168
169
170
171
172
173

174
175
176
177
178
179
180
**   auto-checkpoint value before returning.
**
** BT_CONTROL_LOGSIZE:
**   The third argument is interpreted as a pointer to type (int). The
**   value pointer to is set to the number of uncheckpointed frames
**   that stored in the log file according to the snapshot used by the
**   most recently completed transaction or checkpoint operation.
**   



*/
#define BT_CONTROL_INFO     7706389
#define BT_CONTROL_SETVFS   7706390
#define BT_CONTROL_GETVFS   7706391
#define BT_CONTROL_SAFETY   7706392
#define BT_CONTROL_AUTOCKPT 7706393
#define BT_CONTROL_LOGSIZE  7706394


int sqlite4BtControl(bt_db*, int op, void *pArg);

#define BT_SAFETY_OFF    0
#define BT_SAFETY_NORMAL 1
#define BT_SAFETY_FULL   2








|
>
>
>

|
|
|
|
|
|
>







159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
**   auto-checkpoint value before returning.
**
** BT_CONTROL_LOGSIZE:
**   The third argument is interpreted as a pointer to type (int). The
**   value pointer to is set to the number of uncheckpointed frames
**   that stored in the log file according to the snapshot used by the
**   most recently completed transaction or checkpoint operation.
**
** BT_CONTROL_MULTIPROC:
**   The third argument is interpreted as a pointer to type (int).
**   
*/
#define BT_CONTROL_INFO      7706389
#define BT_CONTROL_SETVFS    7706390
#define BT_CONTROL_GETVFS    7706391
#define BT_CONTROL_SAFETY    7706392
#define BT_CONTROL_AUTOCKPT  7706393
#define BT_CONTROL_LOGSIZE   7706394
#define BT_CONTROL_MULTIPROC 7706395

int sqlite4BtControl(bt_db*, int op, void *pArg);

#define BT_SAFETY_OFF    0
#define BT_SAFETY_NORMAL 1
#define BT_SAFETY_FULL   2

Changes to src/btInt.h.

130
131
132
133
134
135
136

137
138
139
140
141
142
143
...
226
227
228
229
230
231
232

233
234
235
236
237
238
239
bt_env *sqlite4BtPagerGetEnv(BtPager*);
void sqlite4BtPagerSetEnv(BtPager*, bt_env*);

void sqlite4BtPagerSetSafety(BtPager*, int*);
void sqlite4BtPagerSetAutockpt(BtPager*, int*);

void sqlite4BtPagerLogsize(BtPager*, int*);


/*
** End of bt_pager.c interface.
*************************************************************************/

/*************************************************************************
** File-system interface.
................................................................................
  **   log file, automatically run a checkpoint operation.
  **
  ** iSafetyLevel:
  **   Current safety level. 0==off, 1==normal, 2=full.
  */
  int iSafetyLevel;               /* 0==OFF, 1==NORMAL, 2==FULL */
  int nAutoCkpt;                  /* Auto-checkpoint when log is this large */


  /* These are used only by the bt_lock module. */
  BtShared *pShared;              /* Shared by all handles on this file */
  BtLock *pNext;                  /* Next connection using pShared */
  u32 mExclLock;                  /* Mask of exclusive locks held */
  u32 mSharedLock;                /* Mask of shared locks held */
  BtFile *pBtFile;                /* Used to defer close if necessary */







>







 







>







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
bt_env *sqlite4BtPagerGetEnv(BtPager*);
void sqlite4BtPagerSetEnv(BtPager*, bt_env*);

void sqlite4BtPagerSetSafety(BtPager*, int*);
void sqlite4BtPagerSetAutockpt(BtPager*, int*);

void sqlite4BtPagerLogsize(BtPager*, int*);
void sqlite4BtPagerMultiproc(BtPager *pPager, int *piVal);

/*
** End of bt_pager.c interface.
*************************************************************************/

/*************************************************************************
** File-system interface.
................................................................................
  **   log file, automatically run a checkpoint operation.
  **
  ** iSafetyLevel:
  **   Current safety level. 0==off, 1==normal, 2=full.
  */
  int iSafetyLevel;               /* 0==OFF, 1==NORMAL, 2==FULL */
  int nAutoCkpt;                  /* Auto-checkpoint when log is this large */
  int bRequestMultiProc;          /* Request multi-proc support */

  /* These are used only by the bt_lock module. */
  BtShared *pShared;              /* Shared by all handles on this file */
  BtLock *pNext;                  /* Next connection using pShared */
  u32 mExclLock;                  /* Mask of exclusive locks held */
  u32 mSharedLock;                /* Mask of shared locks held */
  BtFile *pBtFile;                /* Used to defer close if necessary */

Changes to src/bt_lock.c.

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
...
411
412
413
414
415
416
417

418
419
420
421
422
423
424
      sqlite4_free(pEnv, pShared);
      sqlite4_mutex_free(pMutex);
      pShared = 0;
      pMutex = 0;
      rc = btErrorBkpt(SQLITE4_NOMEM);
    }else{
      memset(pShared, 0, sizeof(BtShared));
      pShared->bMultiProc = 1;
      pShared->nName = nName;
      pShared->zName = (char *)&pShared[1];
      memcpy(pShared->zName, zName, nName+1);
      pShared->pNext = gBtShared.pDatabase;
      pShared->pClientMutex = pMutex;
      gBtShared.pDatabase = pShared;
    }
................................................................................
      rc = xCkpt(p);
    }
    if( rc==SQLITE4_OK ){
      rc = btLockLockop(p, BT_LOCK_DMS2_RO, BT_LOCK_EXCL, 0);
    }
    if( rc==SQLITE4_OK ){
      rc = xDel(p);

    }
    if( rc==SQLITE4_BUSY ) rc = SQLITE4_OK;
    btLockLockop(p, BT_LOCK_DMS2_RW, BT_LOCK_UNLOCK, 0);
    btLockLockop(p, BT_LOCK_DMS2_RO, BT_LOCK_UNLOCK, 0);
    btLockLockop(p, BT_LOCK_DMS1, BT_LOCK_UNLOCK, 0);
  }








|







 







>







294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
...
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
      sqlite4_free(pEnv, pShared);
      sqlite4_mutex_free(pMutex);
      pShared = 0;
      pMutex = 0;
      rc = btErrorBkpt(SQLITE4_NOMEM);
    }else{
      memset(pShared, 0, sizeof(BtShared));
      pShared->bMultiProc = p->bRequestMultiProc;
      pShared->nName = nName;
      pShared->zName = (char *)&pShared[1];
      memcpy(pShared->zName, zName, nName+1);
      pShared->pNext = gBtShared.pDatabase;
      pShared->pClientMutex = pMutex;
      gBtShared.pDatabase = pShared;
    }
................................................................................
      rc = xCkpt(p);
    }
    if( rc==SQLITE4_OK ){
      rc = btLockLockop(p, BT_LOCK_DMS2_RO, BT_LOCK_EXCL, 0);
    }
    if( rc==SQLITE4_OK ){
      rc = xDel(p);
      if( pShared->pFile ) p->pVfs->xShmUnmap(pShared->pFile, 1);
    }
    if( rc==SQLITE4_BUSY ) rc = SQLITE4_OK;
    btLockLockop(p, BT_LOCK_DMS2_RW, BT_LOCK_UNLOCK, 0);
    btLockLockop(p, BT_LOCK_DMS2_RO, BT_LOCK_UNLOCK, 0);
    btLockLockop(p, BT_LOCK_DMS1, BT_LOCK_UNLOCK, 0);
  }

Changes to src/bt_main.c.

2403
2404
2405
2406
2407
2408
2409






2410
2411
2412
2413
2414
2415
      break;
    }

    case BT_CONTROL_LOGSIZE: {
      int *pInt = (int*)pArg;
      sqlite4BtPagerLogsize(db->pPager, pInt);
      break;






    }
  }

  return rc;
}








>
>
>
>
>
>






2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
      break;
    }

    case BT_CONTROL_LOGSIZE: {
      int *pInt = (int*)pArg;
      sqlite4BtPagerLogsize(db->pPager, pInt);
      break;
    }
                             
    case BT_CONTROL_MULTIPROC: {
      int *pInt = (int*)pArg;
      sqlite4BtPagerMultiproc(db->pPager, pInt);
      break;
    }
  }

  return rc;
}

Changes to src/bt_pager.c.

18
19
20
21
22
23
24


25
26
27
28
29
30
31
...
212
213
214
215
216
217
218

219
220
221
222
223
224
225
...
921
922
923
924
925
926
927







928
929
930
931
932
933
934
#include <stdio.h>


/* By default auto-checkpoint is 1000 */
#define BT_DEFAULT_AUTOCKPT 1000

#define BT_DEFAULT_SAFETY BT_SAFETY_NORMAL



typedef struct BtPageHash BtPageHash;

typedef struct BtSavepoint BtSavepoint;
typedef struct BtSavepage BtSavepage;

/*
................................................................................
  if( !p ) return btErrorBkpt(SQLITE4_NOMEM); 
  memset(p, 0, nByte);

  p->btl.pEnv = pEnv;
  p->btl.pVfs = sqlite4BtEnvDefault();
  p->btl.iSafetyLevel = BT_DEFAULT_SAFETY;
  p->btl.nAutoCkpt = BT_DEFAULT_AUTOCKPT;

  *pp = p;
  return SQLITE4_OK;
}

static void btFreePage(BtPager *p, BtPage *pPg){
  if( pPg ){
    sqlite4_free(p->btl.pEnv, pPg->aData);
................................................................................
  }
  *piVal = pPager->btl.nAutoCkpt;
}

void sqlite4BtPagerLogsize(BtPager *pPager, int *pnFrame){
  *pnFrame = sqlite4BtLogSize(pPager->pLog);
}








#ifndef NDEBUG
int sqlite4BtPagerRefcount(BtPager *p){
  return p->nTotalRef;
}
#endif








>
>







 







>







 







>
>
>
>
>
>
>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
...
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
#include <stdio.h>


/* By default auto-checkpoint is 1000 */
#define BT_DEFAULT_AUTOCKPT 1000

#define BT_DEFAULT_SAFETY BT_SAFETY_NORMAL

#define BT_DEFAULT_MULTIPROC 1

typedef struct BtPageHash BtPageHash;

typedef struct BtSavepoint BtSavepoint;
typedef struct BtSavepage BtSavepage;

/*
................................................................................
  if( !p ) return btErrorBkpt(SQLITE4_NOMEM); 
  memset(p, 0, nByte);

  p->btl.pEnv = pEnv;
  p->btl.pVfs = sqlite4BtEnvDefault();
  p->btl.iSafetyLevel = BT_DEFAULT_SAFETY;
  p->btl.nAutoCkpt = BT_DEFAULT_AUTOCKPT;
  p->btl.bRequestMultiProc = BT_DEFAULT_MULTIPROC;
  *pp = p;
  return SQLITE4_OK;
}

static void btFreePage(BtPager *p, BtPage *pPg){
  if( pPg ){
    sqlite4_free(p->btl.pEnv, pPg->aData);
................................................................................
  }
  *piVal = pPager->btl.nAutoCkpt;
}

void sqlite4BtPagerLogsize(BtPager *pPager, int *pnFrame){
  *pnFrame = sqlite4BtLogSize(pPager->pLog);
}

void sqlite4BtPagerMultiproc(BtPager *pPager, int *piVal){
  if( *piVal==0 || *piVal==1 ){
    pPager->btl.bRequestMultiProc = *piVal;
  }
  *piVal = pPager->btl.bRequestMultiProc;
}

#ifndef NDEBUG
int sqlite4BtPagerRefcount(BtPager *p){
  return p->nTotalRef;
}
#endif