-
Notifications
You must be signed in to change notification settings - Fork 465
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
sql: RETAIN HISTORY for materialized views #23788
Conversation
Is this a good place to bikeshed the name? I think users may not understand "compaction" but might understand e.g. "history" or "historical" windows instead? |
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.
Code LGTM, I don't really have a strong opinion on the naming.
EDIT: I forgot I'm on the SQL council this month. I will form an opinion next week.
src/environmentd/tests/sql.rs
Outdated
let source = ts.sources.into_element(); | ||
let upper = source.write_frontier.into_element(); | ||
let since = source.read_frontier.into_element(); | ||
if upper.saturating_sub(since) > Timestamp::from(2000u64) { |
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.
Should this be >=
?
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 know! During testing the diff was usually just a bit above 2000. I'm not sure what the guarantees are for read and write frontiers in the storage controller though. I changed 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.
Requesting changes since there's a pending discussion on the naming of the option in Slack.
Changed to |
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.
Syntax looks good modulo the point about the equals sign being optional.
Just to confirm: it's not possible with this change to alter the compaction window for a materialized view, yeah? Seems fine, since this is plenty to unblock testing with rETL tools.
src/sql/src/plan.rs
Outdated
/// Disable logical compaction entirely. | ||
Disabled, |
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 this meant to be constructible at the moment? It doesn't seem to be! Is the idea that we'll introduce RETAIN HISTORY = FOREVER
in the future?
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.
It is written this way to have compatibility with index options which allow for this:
materialize/src/sql/src/plan.rs
Line 1548 in a75510b
/// Configures the logical compaction window for an index. `None` disables |
In a later PR I would like to refactor the index planning and controller read policy code to use this new enum instead of passing around Option<milliseconds or Timestamp or Duration>
.
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 principal motivation for this struct is to describe exactly what a None
Option means. There are some places it means "I want NO user compaction performed" and others it means "no one specified anything, use the default". With the current scheme we'd have some Option<Option<Duration>>
in a few places. I thought this would improve that greatly, although the refactor is getting annoying.
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 plan sounds good to me! I just couldn't tell in the current code where the Disabled
variant was getting used.
Correct. ALTER is a bit harder because it has to muck with the SQL. I'd like to ship retain history for CREATE tables, sources and mvs. Then do ALTER afterward. |
Hold off on any more reviews, this doesn't work on restart. |
RFAL. First commit is #23854. This now works on restart and has a test for that. |
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.
Syntax LGTM. Not going to have time to look through the rest.
Oh, great! I'm happy about this, because I'm planning to also increase the compaction window of I have a question: What happens with indexes on a materialized view that has a custom compaction window? Does the compaction window of the index inherit the MV's window? If not, then this might be surprising to users: they might expect that creating an index can only speed up querying from the MV but never alter the semantics. |
src/catalog/src/memory/objects.rs
Outdated
@@ -448,7 +446,7 @@ pub struct Source { | |||
pub desc: RelationDesc, | |||
pub timeline: Timeline, | |||
pub resolved_ids: ResolvedIds, | |||
pub custom_logical_compaction_window: Option<Duration>, | |||
pub custom_logical_compaction_window: Option<CustomCompactionWindow>, |
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.
For these objects, what's the difference between None
and Some(CustomCompactionWindow::Default)
?
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.
none means the user did not specify a custom window in the syntax. maybe customcompactionwindow::default should not exist then since it's implied by none!
d14d5bf
to
86ee2ca
Compare
@@ -29,6 +32,44 @@ | |||
] | |||
|
|||
|
|||
def workflow_retain_history(c: Composition) -> None: |
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.
Putting this test in restart
doesn't feel quite right. Is there a better place to put 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.
restart
seems right to me, actually! In the future #team-testing will get you a very fast answer to these sorts of questions. They'd probably recommend adding a platform check for this, since platform checks get interspersed with all sorts of disruptions, like restarts. Can do that as a followup though. cc @MaterializeInc/testing for thoughts.
The restart test is failing in another test in the file because
Retrying didn't fix it and I'm unable to reproduce locally. Any ideas? |
The full stack trace is:
test/restart/mzcompose.py:433 just triggers the workflow. @philip-stoev, have you seen this before? Any ideas? |
Good point! This is a thing we decided on in the read holds design
And it needs to be tested and probably implemented here. |
The docker ps -a log shows |
Did some testing and adding an index seems to disable the compaction. Working on a fix. |
We decided that indexes breaking this is in spec for now. Tests were added to assert that behavior. I'm going to merge this once I figure out the test failure. |
Adding indexes currently breaks this, but we've decided that's in spec for now.
@benesch Merging is blocked until your change request is resolved. |
TIL! Thanks. |
Add RETAIN HISTORY to materialized views.
See https://github.com/MaterializeInc/database-issues/issues/4840
Motivation
Checklist
$T ⇔ Proto$T
mapping (possibly in a backwards-incompatible way), then it is tagged with aT-proto
label.COMPACTION WINDOW
toMATERIALIZED VIEWS
.