Skip to content

Keep track of potential first to solves so we can update them when we get 'delayed' results. #2282

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

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

nickygerritsen
Copy link
Member

Fixes #2281.

I don't know why we never found this before, but I think this scenario is real and I see no other easy way to fix this.

I have split up the logic of determining first to solve in two:

  • If there are no correct submissions before the one being considered, this can be first to solve, but there are two options:
    • If there are no pending ones either, it is for sure a first to solve.
    • If there are pending ones, this means this can become a first to solve later, but we are not sure, so keep track of this

Then when we update a score cache entry with 0 pending items, we need to consider that we need to check submissions from other teams for the same problem, to see if they have any potential first to solve submissions and recalculate them.

This brings with it a performance penalty every time we update the score cache with 0 pending submissions, since we need to query for the same contest and problem all score caches with a potential first to solve. There is currently no index on this column, but there are indices on the contest, team and problem columns, so I think this should not be a big overhead. If it turns it this is an issue, we can add an index on cid, probid, is_potential_first_to_solve. The next extra overhead is when there are actually pending first to solves, since then we need to recalculate them. But I think this makes sense, since this is exactly what we try to solve.

I first wrote the testcase, which fails without my fix. If you add $scoreboardService->calculateScoreRow($contest, $team2, $problem); below the second $scoreboardService->calculateScoreRow($contest, $team1, $problem); it does succeed without my change, since then we do indeed update the data.

// If there are no valid correct submissions submitted earlier but there
// are submissions awaiting judgement, we are potentially the first to solve.
// We need to keep track of this since we later need to set the actual first to solve.
$verificationRequiredExtra = ($verificationRequired && !$useExternalJudgements) ? 'OR j.verified = 0' : '';
Copy link
Member

Choose a reason for hiding this comment

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

Why is this change needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

External judgements don't have a verified status in this sense. This just never worked.

@nickygerritsen nickygerritsen force-pushed the first-to-solve-delayed branch 2 times, most recently from 9247b71 to 1c3b93e Compare December 29, 2023 10:41
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE scorecache ADD is_potential_first_to_solve TINYINT(1) DEFAULT 0 NOT NULL COMMENT \'Is this potentially the first solution to this problem?\' AFTER is_first_to_solve');
Copy link
Member

Choose a reason for hiding this comment

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

This seems to require a _public and _jury version: if you first solve a problem in the freeze and there's another one pending before yours, but also in the freeze, then the public/team should not know whether it was actually a first to solve or not.

In general, I'm a bit wary of adding extra complexity and columns. I think it would be better if we can figure out what scoreboard data depends what changes, and just fetch all that data and pass it to a single function that just recalculates the relevant scoreboard data.

Copy link
Member Author

Choose a reason for hiding this comment

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

But we also don’t have a jury and public version of the normal first to solve. So I’m wondering if we have some logic, where we don’t show it if there are blue boxes anyway?

I get what you mean but I’m not sure how to solve this easily. A new incorrect submission can affect a correct submission that came after it and currently we only handle the current submission, not any other

->select('s', 't')
->andWhere('s.contest = :contest')
->andWhere('s.problem = :problem')
->andWhere('s.is_potential_first_to_solve = 1')
Copy link
Member

Choose a reason for hiding this comment

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

Is this restriction actually adding anything? We are hopefully only very rarely executing this codepath anyway, so it would not hurt to go here over all teams

  • which have solved this problem (which is a restriction you are currently not adding)
  • after us (right?)

Copy link
Member Author

Choose a reason for hiding this comment

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

We only set s. is_potential_first_to_solve if that team solved the problem and we have earlier pending submissions, so I'd say that we do filter on teams solving this problem.

My current code assumes that if we loop over all potentional first to solves for the same problem, we will find the one that we need to actually update.

Currently this code path is executed more than you think: it is executed when we have no pending jury submissions for this (team,problem) and we are not the first to solve ourselves.

If you have a better idea to implement this, I am open, but I don't follow your thought currently. Feel free to push it as a commit. I think the added test should catch if it works.

Copy link
Member

Choose a reason for hiding this comment

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

I am thinking of something like 76f1640

That should make sure we don't call it too often while not adding the complexity of the extra column. I still have to think through the potential race conditions...

Copy link
Member Author

Choose a reason for hiding this comment

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

Something like that could indeed work I think.

@meisterT meisterT force-pushed the first-to-solve-delayed branch from 1c3b93e to 5e1442b Compare March 13, 2024 18:58
@nickygerritsen nickygerritsen added this pull request to the merge queue Mar 13, 2024
Merged via the queue into DOMjudge:main with commit 9f4dcc0 Mar 13, 2024
@nickygerritsen nickygerritsen deleted the first-to-solve-delayed branch March 13, 2024 19:14
meisterT added a commit to meisterT/domjudge that referenced this pull request Mar 13, 2024
… when we get 'delayed' results."

This reverts commit 9f4dcc0.

DOMjudge#2282 was merged by accident
and needs more thought.
github-merge-queue bot pushed a commit that referenced this pull request Mar 13, 2024
… when we get 'delayed' results."

This reverts commit 9f4dcc0.

#2282 was merged by accident
and needs more thought.
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.

The first solved is not calculated for some case
4 participants