Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add tests to ensure that patchsets are handled correctly by the session rebase APIs. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | sessions-rebase |
Files: | files | file ages | folders |
SHA3-256: |
0e45baaec01947f6cbf47d5d5922a4ca |
User & Date: | dan 2018-03-22 14:07:36.942 |
Context
2018-03-22
| ||
19:52 | Fix another problem with rebasing updates against multiple remote changes. (check-in: c8e7b5a061 user: dan tags: sessions-rebase) | |
14:07 | Add tests to ensure that patchsets are handled correctly by the session rebase APIs. (check-in: 0e45baaec0 user: dan tags: sessions-rebase) | |
11:15 | Remove some unused code from the sessions module. (check-in: a09518ab63 user: dan tags: sessions-rebase) | |
Changes
Changes to ext/session/sessionrebase.test.
︙ | ︙ | |||
381 382 383 384 385 386 387 388 389 | INSERT INTO abcdefghijkl VALUES(22, 23, 24); } { INSERT INTO abcdefghijkl VALUES(22, 25, 26); UPDATE abcdefghijkl SET y=400 WHERE x=22; } [list REPLACE $p] } finish_test | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | INSERT INTO abcdefghijkl VALUES(22, 23, 24); } { INSERT INTO abcdefghijkl VALUES(22, 25, 26); UPDATE abcdefghijkl SET y=400 WHERE x=22; } [list REPLACE $p] } #------------------------------------------------------------------------- # Check that apply_v2() does not create a rebase buffer for a patchset. # And that it is not possible to rebase a patchset. # do_execsql_test 4.0 { CREATE TABLE t5(o PRIMARY KEY, p, q); INSERT INTO t5 VALUES(1, 2, 3); INSERT INTO t5 VALUES(4, 5, 6); } foreach {tn cmd rebasable} { 1 patchset 0 2 changeset 1 } { proc xConflict {args} { return "OMIT" } do_test 4.1.$tn { execsql { BEGIN; DELETE FROM t5 WHERE o=4; } sqlite3session S db main S attach * execsql { INSERT INTO t5 VALUES(4, 'five', 'six'); } set P [S $cmd] S delete execsql ROLLBACK; set ::rebase [sqlite3changeset_apply_v2 db $P xConflict] expr [llength $::rebase]>0 } $rebasable } foreach {tn cmd rebasable} { 1 patchset 0 2 changeset 1 } { do_test 4.2.$tn { sqlite3session S db main S attach * execsql { INSERT INTO t5 VALUES(5+$tn, 'five', 'six'); } set P [S $cmd] S delete sqlite3rebaser_create R R configure $::rebase expr [catch {R rebase $P}]==0 } $rebasable catch { R delete } } finish_test |
Changes to ext/session/sqlite3session.c.
︙ | ︙ | |||
5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 | rc = sqlite3changegroup_output_strm(pGrp, xOutput, pOut); } sqlite3changegroup_delete(pGrp); return rc; } struct sqlite3_rebaser { sqlite3_changegroup grp; /* Hash table */ }; /* ** Buffers a1 and a2 must both contain a sessions module record nCol ** fields in size. This function appends an nCol sessions module | > > > | 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 | rc = sqlite3changegroup_output_strm(pGrp, xOutput, pOut); } sqlite3changegroup_delete(pGrp); return rc; } /* ** Changeset rebaser handle. */ struct sqlite3_rebaser { sqlite3_changegroup grp; /* Hash table */ }; /* ** Buffers a1 and a2 must both contain a sessions module record nCol ** fields in size. This function appends an nCol sessions module |
︙ | ︙ | |||
5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 | } pBuf->nBuf = pOut-pBuf->aBuf; assert( pBuf->nBuf<=pBuf->nAlloc ); } } static void sessionAppendPartialUpdate( SessionBuffer *pBuf, /* Append record here */ sqlite3_changeset_iter *pIter, /* Iterator pointed at local change */ u8 *aRec, int nRec, /* Local change */ u8 *aChange, int nChange, /* Record to rebase against */ int *pRc /* IN/OUT: Return Code */ ){ | > > > > > > > > > > > > > > > > > > > | 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 | } pBuf->nBuf = pOut-pBuf->aBuf; assert( pBuf->nBuf<=pBuf->nAlloc ); } } /* ** This function is called when rebasing a local UPDATE change against one ** or more remote UPDATE changes. The aRec/nRec buffer contains the current ** old.* and new.* records for the change. The rebase buffer (a single ** record) is in aChange/nChange. The rebased change is appended to buffer ** pBuf. ** ** Rebasing the UPDATE involves: ** ** * Removing any changes to fields for which the corresponding field ** in the rebase buffer is set to "replaced" (type 0xFF). If this ** means the UPDATE change updates no fields, nothing is appended ** to the output buffer. ** ** * For each field modified by the local change for which the ** corresponding field in the rebase buffer is not "undefined" (0x00) ** or "replaced" (0xFF), the old.* value is replaced by the value ** in the rebase buffer. */ static void sessionAppendPartialUpdate( SessionBuffer *pBuf, /* Append record here */ sqlite3_changeset_iter *pIter, /* Iterator pointed at local change */ u8 *aRec, int nRec, /* Local change */ u8 *aChange, int nChange, /* Record to rebase against */ int *pRc /* IN/OUT: Return Code */ ){ |
︙ | ︙ | |||
5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 | a2 += n2; } pBuf->nBuf = (pOut - pBuf->aBuf); } } } static int sessionRebase( sqlite3_rebaser *p, /* Rebaser hash table */ sqlite3_changeset_iter *pIter, /* Input data */ int (*xOutput)(void *pOut, const void *pData, int nData), void *pOut, /* Context for xOutput callback */ int *pnOut, /* OUT: Number of bytes in output changeset */ void **ppOut /* OUT: Inverse of pChangeset */ ){ int rc = SQLITE_OK; u8 *aRec = 0; int nRec = 0; int bNew = 0; SessionTable *pTab = 0; SessionBuffer sOut = {0,0,0}; | > > > > > > > > > > > > > > > | | 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 | a2 += n2; } pBuf->nBuf = (pOut - pBuf->aBuf); } } } /* ** pIter is configured to iterate through a changeset. This function rebases ** that changeset according to the current configuration of the rebaser ** object passed as the first argument. If no error occurs and argument xOutput ** is not NULL, then the changeset is returned to the caller by invoking ** xOutput zero or more times and SQLITE_OK returned. Or, if xOutput is NULL, ** then (*ppOut) is set to point to a buffer containing the rebased changeset ** before this function returns. In this case (*pnOut) is set to the size of ** the buffer in bytes. It is the responsibility of the caller to eventually ** free the (*ppOut) buffer using sqlite3_free(). ** ** If an error occurs, an SQLite error code is returned. If ppOut and ** pnOut are not NULL, then the two output parameters are set to 0 before ** returning. */ static int sessionRebase( sqlite3_rebaser *p, /* Rebaser hash table */ sqlite3_changeset_iter *pIter, /* Input data */ int (*xOutput)(void *pOut, const void *pData, int nData), void *pOut, /* Context for xOutput callback */ int *pnOut, /* OUT: Number of bytes in output changeset */ void **ppOut /* OUT: Inverse of pChangeset */ ){ int rc = SQLITE_OK; u8 *aRec = 0; int nRec = 0; int bNew = 0; SessionTable *pTab = 0; SessionBuffer sOut = {0,0,0}; while( SQLITE_ROW==sessionChangesetNext(pIter, &aRec, &nRec, &bNew) ){ SessionChange *pChange = 0; int bDone = 0; if( bNew ){ const char *zTab = pIter->zTab; for(pTab=p->grp.pList; pTab; pTab=pTab->pNext){ if( 0==sqlite3_stricmp(pTab->zName, zTab) ) break; |
︙ | ︙ |