Skip to content

sql partial refresh support#8914

Open
rustyrussell wants to merge 9 commits intoElementsProject:masterfrom
rustyrussell:guilt/sql-partial-refresh
Open

sql partial refresh support#8914
rustyrussell wants to merge 9 commits intoElementsProject:masterfrom
rustyrussell:guilt/sql-partial-refresh

Conversation

@rustyrussell
Copy link
Contributor

Replaces #8841

This properly adds wait support to all supported tables (ie. all list commands which support indexing) in the sql plugin. It's a little tricky, so we do this in easy stages.

The final result is far more optimal for queries to those tables.

@rustyrussell rustyrussell added this to the v26.04 milestone Feb 25, 2026
@rustyrussell rustyrussell force-pushed the guilt/sql-partial-refresh branch 2 times, most recently from e3859eb to 6008f6c Compare March 1, 2026 23:52
Copy link
Collaborator

@Andezion Andezion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refresh_needs bitmask, the watch_init/watch_for/wait_done chain, and the priority ordering in paginated_refresh are all interesting solutions!! Stealing these ideas for future reference!)) LGTM!

f.result(TIMEOUT)


def test_sql_during_change(node_factory):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool test! Especially nice - the negative assertions after the create step confirm that only the minimal refresh path was triggered, not a heavier one. That kind of "we did the cheap thing" check is easy to skip but good to have!!

return send_outreq(req);
}

static struct command_result *updated_list_done(struct command *cmd,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small question: in updated_list_done, unused is passed as last_created_index because we dont want updates to advance that counter - but is there a risk that entries returned by the updated index query actually contain new created_index values that we had then miss?

}

/* Mutual recursion */
static void watch_for(struct sql *sql,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The watch_init + watch_for + wait_done trio is clean. Using nextvalue=0 in watch_init as a "give me current state" trick, then immediately chaining into the async watch loop is a nice pattern!!

@sangbida sangbida modified the milestones: v26.04, 26.06 Mar 18, 2026
1. Refresh time would say "dont refresh if it's only this old" but
   better is to simply make refresh more efficient, which we've done
   and continue to do.
2. time_msec could be used in two places, but floating point suffices.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This is trivial now, as the invoice table gets reloaded every time,
but is an important check as we improve the implementation.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
It's a "have we initialized the table" flag, and we're going to use it for more
than setting up the indices, so rename it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
We can actually just make struct table_desc non-const where required,
and hand its var directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
We now always watch for deleted/created/updated, and keep multiple
flags and indices (though we don't use them yet!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
We're going to need this once we start using `wait updated` to track
these.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
The current variable name is confusing, since it's an INSERT!

This becomes more noticible in the next patch, where we add a delete statement.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…ndex values.

This will let us (efficiently) delete a single entry, so we can wean
tables with created_index off the default "delete all and reload" behavior.

Change insert_stmt to a const, too (and use a temporary when we're
building it).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
For these, when things change, we simply delete amd recreate the
changed entries.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Plugins: `sql` plugin tables "htlcs", "forwards", "invoices", "sendpays" and "networkevents" are now updated more efficiently.
@rustyrussell rustyrussell force-pushed the guilt/sql-partial-refresh branch from 6008f6c to 8eca1c5 Compare March 18, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants