-
-
Save psarna/2363798cfe023a3a379af8d4a4d3ac44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/wal.c b/src/wal.c | |
index fdc4ac39b..a554c86b8 100644 | |
--- a/src/wal.c | |
+++ b/src/wal.c | |
@@ -3597,6 +3597,13 @@ static int walRewriteChecksums(Wal *pWal, u32 iLast){ | |
return rc; | |
} | |
+typedef struct magic_async_job { | |
+ int pgno; | |
+ sqlite3_int64 offset; | |
+} magic_async_job; | |
+ | |
+static magic_async_job magic_job = {0, 0}; | |
+ | |
/* | |
** Write a set of frames to the log. The caller must hold the write-lock | |
** on the log file (obtained using sqlite3WalBeginWriteTransaction()). | |
@@ -3700,6 +3707,8 @@ int sqlite3WalFrames( | |
iOffset = walFrameOffset(iFrame+1, szPage); | |
szFrame = szPage + WAL_FRAME_HDRSIZE; | |
+ int return_busy = 0; | |
+ if (magic_job.pgno == 0 && magic_job.offset == 0) { | |
/* Write all frames into the log file exactly once */ | |
for(p=pList; p; p=p->pDirty){ | |
int nDbSize; /* 0 normally. Positive == commit flag */ | |
@@ -3729,12 +3738,31 @@ int sqlite3WalFrames( | |
iFrame++; | |
assert( iOffset==walFrameOffset(iFrame, szPage) ); | |
nDbSize = (isCommit && p->pDirty==0) ? nTruncate : 0; | |
+ if (magic_job.pgno == 0 && magic_job.offset == 0) { | |
+ // sarna: this is where we would enqueue all write operations into io_uring, | |
+ // and then wait until all of them finished successfully | |
+ fprintf(stderr, "\trecorded that {%d, %u} is in progress\n", p->pgno, iOffset); | |
+ magic_job.pgno = p->pgno; | |
+ magic_job.offset = iOffset; | |
+ return_busy = 1; | |
+ } | |
+ fprintf(stderr, "\t (actually writing <%d, %d>\n", p->pgno, iOffset); | |
rc = walWriteOneFrame(&w, p, nDbSize, iOffset); | |
if( rc ) return rc; | |
pLast = p; | |
iOffset += szFrame; | |
p->flags |= PGHDR_WAL_APPEND; | |
} | |
+ } else { | |
+ // sarna: this branch would be called once polling returns that the async i/o operation succeeded | |
+ fprintf(stderr, "\treturning that {%d, %u} job succeeded asynchronously\n", magic_job.pgno, magic_job.offset); | |
+ magic_job.pgno = 0; | |
+ magic_job.offset = 0; | |
+ rc = SQLITE_OK; | |
+ } | |
+ if (return_busy) { | |
+ return SQLITE_BUSY; | |
+ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment