Skip to content
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

fix: stack depth limit exhausted when trying to release 9000 dummy sequences #1495

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import org.loculus.backend.utils.AccessionComparator
import org.loculus.backend.utils.AccessionVersionComparator
import org.loculus.backend.utils.Version
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional

@Component
class AccessionPreconditionValidator(
private val sequenceEntriesViewProvider: SequenceEntriesViewProvider,
private val groupManagementPreconditionValidator: GroupManagementPreconditionValidator,
) {

@Transactional(readOnly = true)
fun validateAccessionVersions(
authenticatedUser: AuthenticatedUser,
accessionVersions: List<AccessionVersionInterface>,
Expand All @@ -48,6 +49,7 @@ class AccessionPreconditionValidator(
}
}

@Transactional(readOnly = true)
fun validateAccessionVersions(accessionVersions: List<AccessionVersionInterface>, statuses: List<Status>) {
sequenceEntriesViewProvider.get(organism = null).let { table ->
val sequenceEntries = table
Expand All @@ -63,6 +65,7 @@ class AccessionPreconditionValidator(
}
}

@Transactional(readOnly = true)
fun validateAccessions(
authenticatedUser: AuthenticatedUser,
accessions: List<Accession>,
Expand Down Expand Up @@ -90,6 +93,7 @@ class AccessionPreconditionValidator(
}
}

@Transactional(readOnly = true)
fun validateAccessions(authenticatedUser: AuthenticatedUser, accessions: List<Accession>) {
sequenceEntriesViewProvider.get(organism = null).let { table ->
val sequenceEntries = table
Expand All @@ -108,6 +112,7 @@ class AccessionPreconditionValidator(
}
}

@Transactional(readOnly = true)
fun validateAccessions(accessions: List<Accession>, statuses: List<Status>): List<AccessionVersionGroup> {
sequenceEntriesViewProvider.get(organism = null).let { table ->
val sequenceEntries = table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,44 +254,34 @@ class SubmissionDatabaseService(
val view = entriesViewProvider.get(organism)
val table = entriesTableProvider.get(organism)

val accessionVersionsToUpdate =
view.join(
DataUseTermsTable,
JoinType.LEFT,
additionalConstraint = {
(view.accessionColumn eq DataUseTermsTable.accessionColumn) and
(DataUseTermsTable.isNewestDataUseTerms)
},
).select {
val statusCondition = view.statusIsOneOf(
listOf(Status.AWAITING_APPROVAL),
)
val statusCondition = view.statusIsOneOf(listOf(Status.AWAITING_APPROVAL))

val accessionCondition = if (accessionVersionsFilter !== null) {
view.accessionVersionIsIn(accessionVersionsFilter)
} else if (authenticatedUser.isSuperUser) {
Op.TRUE
} else {
view.groupIsOneOf(groupManagementDatabaseService.getGroupsOfUser(authenticatedUser))
}
val accessionCondition = if (accessionVersionsFilter !== null) {
view.accessionVersionIsIn(accessionVersionsFilter)
} else if (authenticatedUser.isSuperUser) {
Op.TRUE
} else {
view.groupIsOneOf(groupManagementDatabaseService.getGroupsOfUser(authenticatedUser))
}

val scopeCondition = if (scope == ApproveDataScope.WITHOUT_WARNINGS) {
not(view.entriesWithWarnings)
} else {
Op.TRUE
}
val scopeCondition = if (scope == ApproveDataScope.WITHOUT_WARNINGS) {
not(view.entriesWithWarnings)
} else {
Op.TRUE
}

statusCondition and accessionCondition and scopeCondition
}.map {
AccessionVersion(it[view.accessionColumn], it[view.versionColumn])
}
val accessionVersionsToUpdate = view
.select { statusCondition and accessionCondition and scopeCondition }
.map { AccessionVersion(it[view.accessionColumn], it[view.versionColumn]) }

table.update(
where = {
table.accessionVersionIsIn(accessionVersionsToUpdate)
},
) {
it[releasedAtColumn] = now
for (accessionVersionsChunk in accessionVersionsToUpdate.chunked(1000)) {
table.update(
where = {
table.accessionVersionIsIn(accessionVersionsChunk)
},
) {
it[releasedAtColumn] = now
}
}

return accessionVersionsToUpdate
Expand Down Expand Up @@ -586,46 +576,34 @@ class SubmissionDatabaseService(
)
}

val sequenceEntriesToDelete = entriesTableProvider.get(organism).let { table ->
entriesViewProvider.get(organism).let { view ->
table.join(
view,
JoinType.INNER,
additionalConstraint = {
(table.accessionColumn eq view.accessionColumn) and
(table.versionColumn eq view.versionColumn)
},
).select {
val accessionCondition = if (accessionVersionsFilter != null) {
table.accessionVersionIsIn(accessionVersionsFilter)
} else if (authenticatedUser.isSuperUser) {
Op.TRUE
} else {
table.groupIsOneOf(groupManagementDatabaseService.getGroupsOfUser(authenticatedUser))
}

val scopeCondition = when (scope) {
DeleteSequenceScope.PROCESSED_WITH_ERRORS -> {
view.statusIs(Status.HAS_ERRORS)
}

DeleteSequenceScope.PROCESSED_WITH_WARNINGS -> {
view.statusIs(Status.AWAITING_APPROVAL) and
view.entriesWithWarnings
}

DeleteSequenceScope.ALL -> view.statusIsOneOf(listOfDeletableStatuses)
}

accessionCondition and scopeCondition
}.map {
AccessionVersion(it[table.accessionColumn], it[table.versionColumn])
val sequenceEntriesToDelete = entriesViewProvider
.get(organism)
.let { view ->
val accessionCondition = if (accessionVersionsFilter != null) {
view.accessionVersionIsIn(accessionVersionsFilter)
} else if (authenticatedUser.isSuperUser) {
Op.TRUE
} else {
view.groupIsOneOf(groupManagementDatabaseService.getGroupsOfUser(authenticatedUser))
}

val scopeCondition = when (scope) {
DeleteSequenceScope.PROCESSED_WITH_ERRORS -> view.statusIs(Status.HAS_ERRORS)
DeleteSequenceScope.PROCESSED_WITH_WARNINGS -> view.statusIs(Status.AWAITING_APPROVAL) and
view.entriesWithWarnings

DeleteSequenceScope.ALL -> view.statusIsOneOf(listOfDeletableStatuses)
}

view.slice(view.accessionColumn, view.versionColumn)
.select { accessionCondition and scopeCondition }
.map { AccessionVersion(it[view.accessionColumn], it[view.versionColumn]) }
}
}

entriesTableProvider.get(organism).deleteWhere {
accessionVersionIsIn(sequenceEntriesToDelete)
entriesTableProvider.get(organism).let { table ->
for (accessionVersionsChunk in sequenceEntriesToDelete.chunked(1000)) {
table.deleteWhere { accessionVersionIsIn(accessionVersionsChunk) }
}
}

return sequenceEntriesToDelete
Expand Down
4 changes: 2 additions & 2 deletions preprocessing/dummy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ def main():
print("Started in watch mode - waiting 10 seconds before fetching data.")
time.sleep(10)

if args.maxSequences and args.maxSequences < 5:
if args.maxSequences and args.maxSequences < 100:
sequences_to_fetch = args.maxSequences
else:
sequences_to_fetch = 5
sequences_to_fetch = 100

while True:
unprocessed = fetch_unprocessed_sequences(sequences_to_fetch)
Expand Down
Loading