-
Notifications
You must be signed in to change notification settings - Fork 206
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
[Divulgence pruning] Prune immediate divulgence [DPP-513] #10691
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,6 @@ import scalaz.syntax.tag._ | |
private[backend] trait CommonStorageBackend[DB_BATCH] extends StorageBackend[DB_BATCH] { | ||
|
||
private val logger: ContextualizedLogger = ContextualizedLogger.get(this.getClass) | ||
|
||
// Ingestion | ||
|
||
private val SQL_DELETE_OVERSPILL_ENTRIES: List[SqlQuery] = | ||
|
@@ -55,6 +54,8 @@ private[backend] trait CommonStorageBackend[DB_BATCH] extends StorageBackend[DB_ | |
SQL("DELETE FROM party_entries WHERE ledger_offset > {ledger_offset}"), | ||
) | ||
|
||
def queryStrategy: QueryStrategy | ||
|
||
override def initializeIngestion( | ||
connection: Connection | ||
): Option[ParameterStorageBackend.LedgerEnd] = { | ||
|
@@ -479,6 +480,7 @@ private[backend] trait CommonStorageBackend[DB_BATCH] extends StorageBackend[DB_ | |
|
||
// Events | ||
|
||
// TODO Cleanup: Extract to [[EventStorageBackendTemplate]] | ||
def pruneEvents( | ||
pruneUpToInclusive: Offset, | ||
pruneAllDivulgedContracts: Boolean, | ||
|
@@ -524,6 +526,35 @@ private[backend] trait CommonStorageBackend[DB_BATCH] extends StorageBackend[DB_ | |
)""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Event pruning would be probably more well suited in the EventStorageBackendTemplate, especiallly since it using templates now. (if you are under time pressure never mind, we can do it in the cleanup epic) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. I'll add a TODO to it and please let's leave it for the cleanup epic. |
||
}(connection, loggingContext) | ||
|
||
if (pruneAllDivulgedContracts) { | ||
tudor-da marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val pruneAfterClause = { | ||
// We need to distinguish between the two cases since lexicographical comparison | ||
// in Oracle doesn't work with '' (empty strings are treated as NULLs) as one of the operands | ||
participantAllDivulgedContractsPrunedUpToInclusive(connection) match { | ||
case Some(pruneAfter) => cSQL"and event_offset > $pruneAfter" | ||
case None => cSQL"" | ||
} | ||
} | ||
|
||
pruneWithLogging(queryDescription = "Immediate divulgence events pruning") { | ||
SQL""" | ||
-- Immediate divulgence pruning | ||
delete from participant_events_create c | ||
where event_offset <= $pruneUpToInclusive | ||
-- Only prune create events which did not have a locally hosted party before their creation offset | ||
and not exists ( | ||
select 1 | ||
from party_entries p | ||
where p.typ = 'accept' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was this the issue with the string comparison? if yes, would be nice to add a short comment that without this some fields got empty which lead to oracle issues etcetcetc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are referring to the Oracle-specific blocker that I've mentioned offline, it was the comparison There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which makes me wonder: this is a very common comparison that we're doing. howcome it did not pop out in other places 🤔 ? |
||
and p.ledger_offset <= c.event_offset | ||
and #${queryStrategy.isTrue("p.is_local")} | ||
and #${queryStrategy.arrayContains("c.flat_event_witnesses", "p.party")} | ||
) | ||
$pruneAfterClause | ||
""" | ||
}(connection, loggingContext) | ||
} | ||
|
||
pruneWithLogging(queryDescription = "Exercise (consuming) events pruning") { | ||
SQL""" | ||
-- Exercise events (consuming) | ||
|
@@ -541,6 +572,14 @@ private[backend] trait CommonStorageBackend[DB_BATCH] extends StorageBackend[DB_ | |
}(connection, loggingContext) | ||
} | ||
|
||
private def participantAllDivulgedContractsPrunedUpToInclusive( | ||
connection: Connection | ||
): Option[Offset] = | ||
SQL"select participant_all_divulged_contracts_pruned_up_to_inclusive from parameters" | ||
.as(offset("participant_all_divulged_contracts_pruned_up_to_inclusive").?.single)( | ||
connection | ||
) | ||
|
||
private def pruneWithLogging(queryDescription: String)(query: SimpleSql[Row])( | ||
connection: Connection, | ||
loggingContext: LoggingContext, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,6 +188,10 @@ private[backend] object PostgresStorageBackend | |
cSQL"#$columnName::text[] && $partiesArray::text[]" | ||
} | ||
|
||
override def arrayContains(arrayColumnName: String, elementColumnName: String): String = | ||
s"$elementColumnName = any($arrayColumnName)" | ||
|
||
override def isTrue(booleanColumnName: String): String = booleanColumnName | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about defining this in QueryStrategy itself and overriding only in Oracle? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm bearish on overriding, in general, and here, for two lines shaved, I would keep them clear. Traversing inheritance levels for understanding functionality is not my piece of cake. I'd change it if you think this degrades coherence in the implementation, though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't we have to override in both Oracle and H2 when defining in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you were probably talking only about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nmarton-da I'll merge this as it is. If we'll reach a different conclusion on this topic, I'll amend it in a separate PR. |
||
} | ||
|
||
override def queryStrategy: QueryStrategy = PostgresQueryStrategy | ||
|
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.
Normalization of these conformance test will be done in a subsequent PR. For clarity/conciseness, in this PR, I blacklist the tests that cannot run on single-participant setups.