-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WallHook v2 #517
WallHook v2 #517
Conversation
5d21da9
to
3c75c70
Compare
@@ -517,12 +517,7 @@ static const sqlite3_api_routines sqlite3Apis = { | |||
sqlite3_stmt_explain | |||
}; | |||
|
|||
static const libsql_api_routines libsqlApis = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a delicate change since libsqlApis is public. If we want to nuke them it's better to do it now rather than later, but we need to clearly document and announce that, in case we have external users of the virtual WAL api.
libsql-sqlite3/src/main.c
Outdated
@@ -1238,6 +1238,9 @@ static int sqlite3Close(sqlite3 *db, int forceZombie){ | |||
*/ | |||
sqlite3VtabRollback(db); | |||
|
|||
/* Destroy the create wal */ | |||
/* (db->create_wal.xDestroy)(db->create_wal.self); */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it commented out because it's a draft and it's going to be back later? Or are we changing the way wal is destroyed? In any case, we need a FIXME/TODO comment placed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the quirk I wanted to talk about. With shared pagers, the ownership of the create_wal is shared as well, because pagers are lifted to the global scope. So the connection does not necessarily owns the create_wal. This is only ok for now because there is nothing to clean with the sqlite3_create_wal
. I think we need to have that reference counted, but maybe this is done another way in C?
libsql-sqlite3/src/wal.c
Outdated
@@ -247,13 +247,28 @@ | |||
** that correspond to frames greater than the new K value are removed | |||
** from the hash table at this point. | |||
*/ | |||
#include "sqliteInt.h" | |||
#include <sqlite3.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope - now you risk it will be taken from one of the standard paths like /usr/include/
, and it's not what you want here. Why is this header needed? If just for a few types => forward-declare them
** already be opened on connection pDbFd. The buffer that zWalName points | ||
** to must remain valid for the lifetime of the returned Wal* handle. | ||
** | ||
** Custom virtual methods may be provided via the pMethods parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment is out of date right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes yes, I haven't started looking at documentation, just on getting something in a working state
libsql-sqlite3/src/wal.c
Outdated
** an SQLite error code is returned and *ppWal is left unmodified. | ||
*/ | ||
static int sqlite3WalOpen( | ||
void *self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow why this pointer is type-erased, but we must at least name it anyway. Similarly, sqlite3_file
object is never really instantiated, but instead cast to a specific type before it's used, e.g. a unix file. I can't suggest a name for it before I understand what self
is here, isn't it just an implementation of a specific WAL, so something like libsql_wal_impl *
? This type can be public and still be opaque, same as sqlite3_file
, you just declare it in one of the public headers as
typedef struct libsql_wal_impl libsql_wal_impl;
We can't afford void *
here because this type name also serves as documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self is the method receiver. It's whatever state the WAL needs to function. In the case of sqlite3, this is a sqlite3_wal.
I don't get the analogy with sqlite3_file
? the sqlite3_file
has a pointer to the methods, but self
can really be anything. whatever is returned by xOpen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping: instead of void, it should be a named opaque type, something like libsql_wal_impl *
, defined as typedef struct libsql_wal_impl *libsql_wal_impl
.
libsql-sqlite3/src/wal.h
Outdated
|
||
struct libsql_wal { | ||
libsql_wal_methods methods; /* virtual wal methods */ | ||
void* self; /* methods receiver */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, so it's a pointer-to-implementation. In that case let's name it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need a translation here 😄
libsql-sqlite3/src/wal.h
Outdated
** the WAL file is open. It is a good place for initialization routines, as WAL | ||
** is otherwise open lazily. | ||
*/ | ||
int (*xPreMainDbOpen)(void* self, const char *main_db_path, int main_db_path_len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: since we overhaul the interface, we should consider removing this thing altogether, it makes very little sense. I thought I need it long time ago when bottomless
was developed as a loadable module, but even then, it makes 10000x more sense to just expose an initialization method that users are supposed to call before a database is open, not a weird WAL methods hook. So if we decide on the shape of virtual WAL v2, it should also include nuking this xPreMainDbOpen hook.
dbf9519
to
cf0d62a
Compare
Each request for new frames from a replica to a primary resets the idle timer but such request is a long poll. It won't return until it gets some new frame. This means that a replica won't send another request for new frames in the mean-time and won't restart the idle timer. This commit makes primary keep track of replicas waiting for new frames and prevents IdleShutdownLayer from stopping the primary if there is at least one replica still waiting for the new frames. When a replica is put into sleep, it will drop the connection and the connected_replicas counter will be decreased so only live replicas can prevent primary from going to sleep. Fixes tursodatabase#506 Signed-off-by: Piotr Jastrzebski <[email protected]>
libsql-sqlite3/src/pager.c
Outdated
} | ||
memset((void*)&(pPager->wal), 0, sizeof(libsql_wal)); | ||
destroy_create_wal(&pPager->create_wal); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that one should only be called if pagerUseWal(pPager)
, right? So it should be moved one line up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The create wal is always there, but a wal is only created if the wal journaling mode is enabled. So we always need to destroy it.
7c7a3bf
to
227ca89
Compare
libsql-server/src/replication/primary/replication_logger_wal.rs
Outdated
Show resolved
Hide resolved
libsql-server/src/replication/primary/replication_logger_wal.rs
Outdated
Show resolved
Hide resolved
d58b5f6
to
977d9ea
Compare
b83f752
to
5ee3bcc
Compare
This WAL implementation dispatches between a Bottomless wal and a regular LoggerWal
4f6e81c
to
fef6978
Compare
No description provided.