/ Check-in [8c2d43ba]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Merge two "wal" leaves.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wal
Files: files | file ages | folders
SHA1: 8c2d43babd61fe2225d5c402174253f412604092
User & Date: dan 2010-04-27 18:49:54
Context
2010-04-28
17:48
Change walthread.test so that tests can be run with either multiple threads or multiple processes. check-in: 25f85f68 user: dan tags: wal
14:42
Rename the sqlite3_log_hook() to sqlite3_wal_hook(). Added comments to wal.h. check-in: bbc38511 user: drh tags: wal
2010-04-27
18:49
Merge two "wal" leaves. check-in: 8c2d43ba user: dan tags: wal
18:43
Add a test to check that a checkpointer releases its locks before returning, even if it has been prevented by a conflicting lock from checkpointing the database. check-in: be44349d user: dan tags: wal
11:49
Add the xShmRelease() method to the VFS. The os_unix.c implementation of the shared memory logic is still non-functional. check-in: ed715b47 user: drh tags: wal
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to src/os_os2.c.

1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
    os2DlOpen,         /* xDlOpen */
    os2DlError,        /* xDlError */
    os2DlSym,          /* xDlSym */
    os2DlClose,        /* xDlClose */
    os2Randomness,     /* xRandomness */
    os2Sleep,          /* xSleep */
    os2CurrentTime,    /* xCurrentTime */
    os2GetLastError    /* xGetLastError */
    0,                 /* xShmOpen */
    0,                 /* xShmSize */
    0,                 /* xShmPush */
    0,                 /* xShmPull */
    0,                 /* xShmLock */
    0,                 /* xShmClose */
    0,                 /* xShmDelete */
    0,                 /* xRename */
    0,                 /* xCurrentTimeInt64 */
  };
  sqlite3_vfs_register(&os2Vfs, 1);
  initUconvObjects();
  return SQLITE_OK;
}
int sqlite3_os_end(void){
  freeUconvObjects();
  return SQLITE_OK;
}

#endif /* SQLITE_OS_OS2 */







|
<
<
<
<
<
<
<
<
<











1107
1108
1109
1110
1111
1112
1113
1114









1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
    os2DlOpen,         /* xDlOpen */
    os2DlError,        /* xDlError */
    os2DlSym,          /* xDlSym */
    os2DlClose,        /* xDlClose */
    os2Randomness,     /* xRandomness */
    os2Sleep,          /* xSleep */
    os2CurrentTime,    /* xCurrentTime */
    os2GetLastError,   /* xGetLastError */









  };
  sqlite3_vfs_register(&os2Vfs, 1);
  initUconvObjects();
  return SQLITE_OK;
}
int sqlite3_os_end(void){
  freeUconvObjects();
  return SQLITE_OK;
}

#endif /* SQLITE_OS_OS2 */

Changes to src/os_unix.c.

4643
4644
4645
4646
4647
4648
4649
4650
4651





4652
4653
4654
4655
4656
4657
4658
....
4674
4675
4676
4677
4678
4679
4680








4681
4682
4683
4684
4685
4686
4687
....
5930
5931
5932
5933
5934
5935
5936

5937
5938
5939
5940
5941
5942
5943
  return rc;
}

/*
** Query and/or changes the size of a shared-memory segment.
** The reqSize parameter is the new size of the segment, or -1 to
** do just a query.  The size of the segment after resizing is
** written into pNewSize.  The start of the shared memory buffer
** is stored in **ppBuffer.





*/
static int unixShmSize(
  sqlite3_shm *pSharedMem,  /* Pointer returned by unixShmOpen() */
  int reqSize,              /* Requested size.  -1 for query only */
  int *pNewSize,            /* Write new size here */
  char **ppBuf              /* Write new buffer origin here */
){
................................................................................
      }
    }
  }
  *pNewSize = p->size;
  *ppBuf = p->pBuf;
  return rc;
}









/*
** Create or release a lock on shared memory.
*/
static int unixShmLock(
  sqlite3_shm *pSharedMem,   /* Pointer from unixShmOpen() */
  int lockType,              /* _RDLK, _WRLK, or _UNLK, possibly ORed _BLOCK */
................................................................................
    unixDlClose,          /* xDlClose */                    \
    unixRandomness,       /* xRandomness */                 \
    unixSleep,            /* xSleep */                      \
    unixCurrentTime,      /* xCurrentTime */                \
    unixGetLastError,     /* xGetLastError */               \
    unixShmOpen,          /* xShmOpen */                    \
    unixShmSize,          /* xShmSize */                    \

    0,                    /* xShmPush */                    \
    0,                    /* xShmPull */                    \
    unixShmLock,          /* xShmLock */                    \
    unixShmClose,         /* xShmClose */                   \
    unixShmDelete,        /* xShmDelete */                  \
    0,                    /* xRename */                     \
    0,                    /* xCurrentTimeInt64 */           \







|
|
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>







4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
....
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
....
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
  return rc;
}

/*
** Query and/or changes the size of a shared-memory segment.
** The reqSize parameter is the new size of the segment, or -1 to
** do just a query.  The size of the segment after resizing is
** written into pNewSize.  A writer lock is held on the shared memory
** segment while resizing it.
**
** If ppBuffer is not NULL, the a reader lock is acquired no the shared
** memory segment and *ppBuffer is made to point to the start of the 
** shared memory segment.  xShmRelease() must be called to release the
** lock.
*/
static int unixShmSize(
  sqlite3_shm *pSharedMem,  /* Pointer returned by unixShmOpen() */
  int reqSize,              /* Requested size.  -1 for query only */
  int *pNewSize,            /* Write new size here */
  char **ppBuf              /* Write new buffer origin here */
){
................................................................................
      }
    }
  }
  *pNewSize = p->size;
  *ppBuf = p->pBuf;
  return rc;
}

/*
** Release the lock held on the shared memory segment to that other
** threads are free to resize it if necessary.
*/
static int unixShmRelease(sqlite3_shm *pSharedMem){
  return SQLITE_OK;
}

/*
** Create or release a lock on shared memory.
*/
static int unixShmLock(
  sqlite3_shm *pSharedMem,   /* Pointer from unixShmOpen() */
  int lockType,              /* _RDLK, _WRLK, or _UNLK, possibly ORed _BLOCK */
................................................................................
    unixDlClose,          /* xDlClose */                    \
    unixRandomness,       /* xRandomness */                 \
    unixSleep,            /* xSleep */                      \
    unixCurrentTime,      /* xCurrentTime */                \
    unixGetLastError,     /* xGetLastError */               \
    unixShmOpen,          /* xShmOpen */                    \
    unixShmSize,          /* xShmSize */                    \
    unixShmRelease,       /* xShmRelease */                 \
    0,                    /* xShmPush */                    \
    0,                    /* xShmPull */                    \
    unixShmLock,          /* xShmLock */                    \
    unixShmClose,         /* xShmClose */                   \
    unixShmDelete,        /* xShmDelete */                  \
    0,                    /* xRename */                     \
    0,                    /* xCurrentTimeInt64 */           \

Changes to src/os_win.c.

1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
    winDlOpen,         /* xDlOpen */
    winDlError,        /* xDlError */
    winDlSym,          /* xDlSym */
    winDlClose,        /* xDlClose */
    winRandomness,     /* xRandomness */
    winSleep,          /* xSleep */
    winCurrentTime,    /* xCurrentTime */
    winGetLastError    /* xGetLastError */
    0,                 /* xShmOpen */
    0,                 /* xShmSize */
    0,                 /* xShmPush */
    0,                 /* xShmPull */
    0,                 /* xShmLock */
    0,                 /* xShmClose */
    0,                 /* xShmDelete */
    0,                 /* xRename */
    0,                 /* xCurrentTimeInt64 */
  };

  sqlite3_vfs_register(&winVfs, 1);
  return SQLITE_OK; 
}
int sqlite3_os_end(void){ 
  return SQLITE_OK;
}

#endif /* SQLITE_OS_WIN */







|
<
<
<
<
<
<
<
<
<










1908
1909
1910
1911
1912
1913
1914
1915









1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
    winDlOpen,         /* xDlOpen */
    winDlError,        /* xDlError */
    winDlSym,          /* xDlSym */
    winDlClose,        /* xDlClose */
    winRandomness,     /* xRandomness */
    winSleep,          /* xSleep */
    winCurrentTime,    /* xCurrentTime */
    winGetLastError,   /* xGetLastError */









  };

  sqlite3_vfs_register(&winVfs, 1);
  return SQLITE_OK; 
}
int sqlite3_os_end(void){ 
  return SQLITE_OK;
}

#endif /* SQLITE_OS_WIN */

Changes to src/sqlite.h.in.

841
842
843
844
845
846
847

848
849
850
851
852
853
854
  int (*xGetLastError)(sqlite3_vfs*, int, char *);
  /*
  ** The methods above are in version 1 of the sqlite_vfs object
  ** definition.  Those that follow are added in version 2 or later
  */
  int (*xShmOpen)(sqlite3_vfs*, const char *zName, sqlite3_shm**);
  int (*xShmSize)(sqlite3_shm*, int reqSize, int *pNewSize, char **);

  int (*xShmPush)(sqlite3_shm*);
  int (*xShmPull)(sqlite3_shm*);
  int (*xShmLock)(sqlite3_shm*, int lockType, int ofst, int nByte);
  int (*xShmClose)(sqlite3_shm*);
  int (*xShmDelete)(sqlite3_vfs*, const char *zName);
  int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync);
  int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);







>







841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
  int (*xGetLastError)(sqlite3_vfs*, int, char *);
  /*
  ** The methods above are in version 1 of the sqlite_vfs object
  ** definition.  Those that follow are added in version 2 or later
  */
  int (*xShmOpen)(sqlite3_vfs*, const char *zName, sqlite3_shm**);
  int (*xShmSize)(sqlite3_shm*, int reqSize, int *pNewSize, char**);
  int (*xShmRelease)(sqlite3_shm*);
  int (*xShmPush)(sqlite3_shm*);
  int (*xShmPull)(sqlite3_shm*);
  int (*xShmLock)(sqlite3_shm*, int lockType, int ofst, int nByte);
  int (*xShmClose)(sqlite3_shm*);
  int (*xShmDelete)(sqlite3_vfs*, const char *zName);
  int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync);
  int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);

Changes to src/test6.c.

778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
    cfDlOpen,             /* xDlOpen */
    cfDlError,            /* xDlError */
    cfDlSym,              /* xDlSym */
    cfDlClose,            /* xDlClose */
    cfRandomness,         /* xRandomness */
    cfSleep,              /* xSleep */
    cfCurrentTime,        /* xCurrentTime */
    0,                    /* xShmOpen */
    0,                    /* xShmSize */
    0,                    /* xShmPush */
    0,                    /* xShmPull */
    0,                    /* xShmLock */
    0,                    /* xShmClose */
    0,                    /* xShmDelete */
    0,                    /* xRename */
    0                     /* xCurrentTimeInt64 */
  };

  if( objc!=2 ){
    Tcl_WrongNumArgs(interp, 1, objv, "ENABLE");
    return TCL_ERROR;
  }








<
<
<
<
<
<
<
<
<







778
779
780
781
782
783
784









785
786
787
788
789
790
791
    cfDlOpen,             /* xDlOpen */
    cfDlError,            /* xDlError */
    cfDlSym,              /* xDlSym */
    cfDlClose,            /* xDlClose */
    cfRandomness,         /* xRandomness */
    cfSleep,              /* xSleep */
    cfCurrentTime,        /* xCurrentTime */









  };

  if( objc!=2 ){
    Tcl_WrongNumArgs(interp, 1, objv, "ENABLE");
    return TCL_ERROR;
  }

Changes to src/test_demovfs.c.

620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
    demoDlOpen,                   /* xDlOpen */
    demoDlError,                  /* xDlError */
    demoDlSym,                    /* xDlSym */
    demoDlClose,                  /* xDlClose */
    demoRandomness,               /* xRandomness */
    demoSleep,                    /* xSleep */
    demoCurrentTime,              /* xCurrentTime */
    0,                            /* xShmOpen */
    0,                            /* xShmSize */
    0,                            /* xShmPush */
    0,                            /* xShmPull */
    0,                            /* xShmLock */
    0,                            /* xShmClose */
    0,                            /* xShmDelete */
    0,                            /* xRename */
    0                             /* xCurrentTimeInt64 */
  };
  return &demovfs;
}

#endif /* !defined(SQLITE_TEST) || defined(SQLITE_OS_UNIX) */









<
<
<
<
<
<
<
<
<







620
621
622
623
624
625
626









627
628
629
630
631
632
633
    demoDlOpen,                   /* xDlOpen */
    demoDlError,                  /* xDlError */
    demoDlSym,                    /* xDlSym */
    demoDlClose,                  /* xDlClose */
    demoRandomness,               /* xRandomness */
    demoSleep,                    /* xSleep */
    demoCurrentTime,              /* xCurrentTime */









  };
  return &demovfs;
}

#endif /* !defined(SQLITE_TEST) || defined(SQLITE_OS_UNIX) */


Changes to src/test_devsym.c.

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  0,                        /* xDlError */
  0,                        /* xDlSym */
  0,                        /* xDlClose */
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
  devsymRandomness,         /* xRandomness */
  devsymSleep,              /* xSleep */
  devsymCurrentTime,        /* xCurrentTime */
  0,                        /* xShmOpen */
  0,                        /* xShmSize */
  0,                        /* xShmPush */
  0,                        /* xShmPull */
  0,                        /* xShmLock */
  0,                        /* xShmClose */
  0,                        /* xShmDelete */
  0,                        /* xRename */
  0                         /* xCurrentTimeInt64 */
};

static sqlite3_io_methods devsym_io_methods = {
  1,                            /* iVersion */
  devsymClose,                      /* xClose */
  devsymRead,                       /* xRead */
  devsymWrite,                      /* xWrite */







<
<
<
<
<
<
<
<
<







89
90
91
92
93
94
95









96
97
98
99
100
101
102
  0,                        /* xDlError */
  0,                        /* xDlSym */
  0,                        /* xDlClose */
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
  devsymRandomness,         /* xRandomness */
  devsymSleep,              /* xSleep */
  devsymCurrentTime,        /* xCurrentTime */









};

static sqlite3_io_methods devsym_io_methods = {
  1,                            /* iVersion */
  devsymClose,                      /* xClose */
  devsymRead,                       /* xRead */
  devsymWrite,                      /* xWrite */

Changes to src/test_journal.c.

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
  jtDlOpen,                      /* xDlOpen */
  jtDlError,                     /* xDlError */
  jtDlSym,                       /* xDlSym */
  jtDlClose,                     /* xDlClose */
  jtRandomness,                  /* xRandomness */
  jtSleep,                       /* xSleep */
  jtCurrentTime,                 /* xCurrentTime */
  0,                             /* xShmOpen */
  0,                             /* xShmSize */
  0,                             /* xShmPush */
  0,                             /* xShmPull */
  0,                             /* xShmLock */
  0,                             /* xShmClose */
  0,                             /* xShmDelete */
  0,                             /* xRename */
  0                              /* xCurrentTimeInt64 */
};

static sqlite3_io_methods jt_io_methods = {
  1,                             /* iVersion */
  jtClose,                       /* xClose */
  jtRead,                        /* xRead */
  jtWrite,                       /* xWrite */







<
<
<
<
<
<
<
<
<







176
177
178
179
180
181
182









183
184
185
186
187
188
189
  jtDlOpen,                      /* xDlOpen */
  jtDlError,                     /* xDlError */
  jtDlSym,                       /* xDlSym */
  jtDlClose,                     /* xDlClose */
  jtRandomness,                  /* xRandomness */
  jtSleep,                       /* xSleep */
  jtCurrentTime,                 /* xCurrentTime */









};

static sqlite3_io_methods jt_io_methods = {
  1,                             /* iVersion */
  jtClose,                       /* xClose */
  jtRead,                        /* xRead */
  jtWrite,                       /* xWrite */

Changes to src/test_osinst.c.

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
  instDlOpen,             /* xDlOpen */
  instDlError,            /* xDlError */
  instDlSym,              /* xDlSym */
  instDlClose,            /* xDlClose */
  instRandomness,         /* xRandomness */
  instSleep,              /* xSleep */
  instCurrentTime,        /* xCurrentTime */
  0,                      /* xShmOpen */
  0,                      /* xShmSize */
  0,                      /* xShmPush */
  0,                      /* xShmPull */
  0,                      /* xShmLock */
  0,                      /* xShmClose */
  0,                      /* xShmDelete */
  0,                      /* xRename */
  0                       /* xCurrentTimeInt64 */
};

static sqlite3_io_methods inst_io_methods = {
  1,                            /* iVersion */
  instClose,                      /* xClose */
  instRead,                       /* xRead */
  instWrite,                      /* xWrite */







<
<
<
<
<
<
<
<
<







200
201
202
203
204
205
206









207
208
209
210
211
212
213
  instDlOpen,             /* xDlOpen */
  instDlError,            /* xDlError */
  instDlSym,              /* xDlSym */
  instDlClose,            /* xDlClose */
  instRandomness,         /* xRandomness */
  instSleep,              /* xSleep */
  instCurrentTime,        /* xCurrentTime */









};

static sqlite3_io_methods inst_io_methods = {
  1,                            /* iVersion */
  instClose,                      /* xClose */
  instRead,                       /* xRead */
  instWrite,                      /* xWrite */

Changes to src/wal.c.

1
2
3
4
5

6
7
8
9
10
11
12
...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

/*
** This file contains the implementation of a log file used in 
** "journal_mode=wal" mode.
*/


/*
** LOG FILE FORMAT
**
** A log file consists of a header followed by zero or more log frames.
** The log header is 12 bytes in size and consists of the following three
** big-endian 32-bit unsigned integer values:
................................................................................
**
** MUTEX:  The MUTEX lock is used as a robust inter-process mutex. It
**         is held while the log-summary header is modified, and 
**         sometimes when it is read. It is also held while a new client
**         obtains the DMH lock (see below), and while log recovery is
**         being run.
**
** DMH:    The DMH (Dead Mans Hand mechanism) lock is used to ensure
**         that log-recovery is always run following a system restart.
**         When it first opens a log-summary file, a process takes a
**         SHARED lock on the DMH region. This lock is not released until
**         the log-summary file is closed. 
**
**         The process then attempts to upgrade to an EXCLUSIVE lock. If 
**         successful, then the contents of the log-summary file are deemed 





>







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

/*
** This file contains the implementation of a log file used in 
** "journal_mode=wal" mode.
*/


/*
** LOG FILE FORMAT
**
** A log file consists of a header followed by zero or more log frames.
** The log header is 12 bytes in size and consists of the following three
** big-endian 32-bit unsigned integer values:
................................................................................
**
** MUTEX:  The MUTEX lock is used as a robust inter-process mutex. It
**         is held while the log-summary header is modified, and 
**         sometimes when it is read. It is also held while a new client
**         obtains the DMH lock (see below), and while log recovery is
**         being run.
**
** DMS:    The DMS (Dead Mans Switch mechanism) lock is used to ensure
**         that log-recovery is always run following a system restart.
**         When it first opens a log-summary file, a process takes a
**         SHARED lock on the DMH region. This lock is not released until
**         the log-summary file is closed. 
**
**         The process then attempts to upgrade to an EXCLUSIVE lock. If 
**         successful, then the contents of the log-summary file are deemed