From adea0d1c39588ebb977b367c97dd31892a0410c4 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 5 Jul 2017 18:48:07 +0000 Subject: [PATCH] Have fts3 virtual table cursors free internal resources when they reach EOF, instead of waiting until the xClose method is called. FossilOrigin-Name: b6b14ab6c8f9758a64e5fd29203f8fa610b5c4ef917de9be51ae55e072fad4ed --- ext/fts3/fts3.c | 32 +++++++++++++++++++++----------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 14ff3f2574..31dbefa63b 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -1707,6 +1707,19 @@ static void fts3CursorFinalizeStmt(Fts3Cursor *pCsr){ sqlite3_finalize(pCsr->pStmt); } +/* +** Free all resources currently held by the cursor passed as the only +** argument. +*/ +static void fts3ClearCursor(Fts3Cursor *pCsr){ + fts3CursorFinalizeStmt(pCsr); + sqlite3Fts3FreeDeferredTokens(pCsr); + sqlite3_free(pCsr->aDoclist); + sqlite3Fts3MIBufferFree(pCsr->pMIBuffer); + sqlite3Fts3ExprFree(pCsr->pExpr); + memset(&(&pCsr->base)[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor)); +} + /* ** Close the cursor. For additional information see the documentation ** on the xClose method of the virtual table interface. @@ -1714,11 +1727,7 @@ static void fts3CursorFinalizeStmt(Fts3Cursor *pCsr){ static int fts3CloseMethod(sqlite3_vtab_cursor *pCursor){ Fts3Cursor *pCsr = (Fts3Cursor *)pCursor; assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 ); - fts3CursorFinalizeStmt(pCsr); - sqlite3Fts3ExprFree(pCsr->pExpr); - sqlite3Fts3FreeDeferredTokens(pCsr); - sqlite3_free(pCsr->aDoclist); - sqlite3Fts3MIBufferFree(pCsr->pMIBuffer); + fts3ClearCursor(pCsr); assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 ); sqlite3_free(pCsr); return SQLITE_OK; @@ -3219,11 +3228,7 @@ static int fts3FilterMethod( assert( iIdx==nVal ); /* In case the cursor has been used before, clear it now. */ - fts3CursorFinalizeStmt(pCsr); - sqlite3_free(pCsr->aDoclist); - sqlite3Fts3MIBufferFree(pCsr->pMIBuffer); - sqlite3Fts3ExprFree(pCsr->pExpr); - memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor)); + fts3ClearCursor(pCsr); /* Set the lower and upper bounds on docids to return */ pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64); @@ -3302,7 +3307,12 @@ static int fts3FilterMethod( ** routine to find out if it has reached the end of a result set. */ static int fts3EofMethod(sqlite3_vtab_cursor *pCursor){ - return ((Fts3Cursor *)pCursor)->isEof; + Fts3Cursor *pCsr = (Fts3Cursor*)pCursor; + if( pCsr->isEof ){ + fts3ClearCursor(pCsr); + pCsr->isEof = 1; + } + return pCsr->isEof; } /* diff --git a/manifest b/manifest index 4f50381b2b..2015d53bd9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\slsmtest\scausing\sone\stest\sto\sfail\sfor\smulti-threaded\sLSM\nconnections. -D 2017-07-05T14:29:04.723 +C Have\sfts3\svirtual\stable\scursors\sfree\sinternal\sresources\swhen\sthey\sreach\sEOF,\ninstead\sof\swaiting\suntil\sthe\sxClose\smethod\sis\scalled. +D 2017-07-05T18:48:07.731 F Makefile.in 081e48dfe7f995d57ce1a88ddf4d2917b4349158648a6cd45b42beae30de3a12 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 4ebb1d257cac7fb1bcb4ba59278416d410ff1c4bf59447a9c37a415f3516056a @@ -70,7 +70,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 6c5543ce771db11d27793fb696564ef5e977116671353a0d5c22056aba73055e +F ext/fts3/fts3.c b47d3ba5c00f550d1f436e62017264fed818665819471b4699aac9527906459b F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h eb2502000148e80913b965db3e59f29251266d0a F ext/fts3/fts3_aux.c 9edc3655fcb287f0467d0a4b886a01c6185fe9f1 @@ -1628,7 +1628,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d1ba200234f40b84327c7fc28c2584ed069da80e97578df71114d1a9ba9c559c -R d19014236aca302457b221b50f1ef9da +P 2bce64c8864b616f9ab0063f64d0ceb2f83e53e110970c6b3b11003cba5c8804 +R 6015f51321fa56ca0aea7f128543d185 U dan -Z 979eda1316a03decf28172c6405a8c04 +Z ff4e48dc3c6989947963449987db258e diff --git a/manifest.uuid b/manifest.uuid index b5c0896059..eee94eb382 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2bce64c8864b616f9ab0063f64d0ceb2f83e53e110970c6b3b11003cba5c8804 \ No newline at end of file +b6b14ab6c8f9758a64e5fd29203f8fa610b5c4ef917de9be51ae55e072fad4ed \ No newline at end of file