Skip to content

fix(server): Retain valid cached project states on error - #1426

Merged
olksdr merged 5 commits into
masterfrom
fix/keep-valid-states
Oct 20, 2022
Merged

olksdr merged 5 commits into
masterfrom
fix/keep-valid-states

Conversation

@jan-auer

@jan-auer jan-auer commented Aug 18, 2022 •

Copy link
Copy Markdown
Member

Fixes a case where valid project states are removed from the project cache after
the fetch deadline has succeeded. Relay should instead continue using caches
until the grace period has expired, and retry fetching in the background.

  • All errors are be mapped to ProjectState::err. The specific error (i.e.
    deserialization and network errors) can still be logged at the source.
  • ProjectState::missing always overwrites the existing state.
  • ProjectState::err only overwrites if the existing state is (hard) outdated.
    This error is cached and propagated.
  • Updated and stale states stay in the cache if the update is
    ProjectState::err. We have to figure out a backoff mechanism for this case
    (probably a flag/Instant on the Project).

INGEST-1504
INGEST-1507

#skip-changelog

@jan-auer

Copy link
Copy Markdown
Member Author

While playing with GitHub Copilot I touched this part of the code.

@olksdr
olksdr force-pushed the fix/keep-valid-states branch from a15f25f to 3b76e3f Compare October 14, 2022 09:11
@olksdr
olksdr marked this pull request as ready for review October 14, 2022 09:12
@olksdr
olksdr requested a review from a team October 14, 2022 09:12
@olksdr olksdr self-assigned this Oct 14, 2022

@jjbayer jjbayer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good to me. @jan-auer you mentioned a potential backoff mechanism in the PR description, could you elaborate on that?

pub last_fetch: Instant,

/// True if this project state was fetched but incompatible with this Relay.
/// True if this project state failed fetching or was incompatible with this Relay.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does "incompatible" mean? Reading the docstrings of invalid, it seems to refer to projects that could not be parsed; but I don't know what the scope of "parse" is, if it's only e.g. syntax issues or network issues while fetching. Specifically, is an expired project state invalid?

Also, the docstrings for invalid are updated here, could we also update them for invalid()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I follow the trail here and here, it seems that incompatible means any error during fetching or deserializing.

Expired is definitely not invalid, just old.

Comment on lines +787 to +788
// If the new state is valid or the old one is expired, always use the new one.
_ => self.state = Some(state.clone()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason to fall back to the old state, if both are expired? Do we assume that the new state is more up-to-date even if both are stale?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's fair to assume that the state passed into this function is newer.

Comment on lines +785 to +788
// If the new state is invalid but the old one still usable, keep the old one.
ExpiryState::Updated(old) | ExpiryState::Stale(old) if state.invalid() => state = old,
// If the new state is valid or the old one is expired, always use the new one.
_ => self.state = Some(state.clone()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a chance both states are updated? What should we do there?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's a good question. We could write this function in a way that it always preserves the fresher config, but for now I would keep the default behavior of replacing the old state with the state passed as an argument, and only make an exception for invalid configs.

pub last_fetch: Instant,

/// True if this project state was fetched but incompatible with this Relay.
/// True if this project state failed fetching or was incompatible with this Relay.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I follow the trail here and here, it seems that incompatible means any error during fetching or deserializing.

Expired is definitely not invalid, just old.

Comment on lines +787 to +788
// If the new state is valid or the old one is expired, always use the new one.
_ => self.state = Some(state.clone()),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's fair to assume that the state passed into this function is newer.

Comment on lines +785 to +788
// If the new state is invalid but the old one still usable, keep the old one.
ExpiryState::Updated(old) | ExpiryState::Stale(old) if state.invalid() => state = old,
// If the new state is valid or the old one is expired, always use the new one.
_ => self.state = Some(state.clone()),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's a good question. We could write this function in a way that it always preserves the fresher config, but for now I would keep the default behavior of replacing the old state with the state passed as an argument, and only make an exception for invalid configs.

@olksdr
olksdr merged commit a6fcbca into master Oct 20, 2022
@olksdr
olksdr deleted the fix/keep-valid-states branch October 20, 2022 05:23
jan-auer added a commit that referenced this pull request Oct 25, 2022
* master:
  release: 0.8.15
  fix(py): Respect the renormalize flag (#1548)
  (fix)e2e: Use report self hosted issues env variable (#1539)
  meta(vscode): Enable all features in Rust-Analyzer (#1542)
  release: 0.8.14
  build(craft): Fix manylinux artifact name (#1547)
  feat(quotas): New data category for indexed transactions (#1535)
  test(auth): Unflake re_auth_failure (#1531)
  replays: add warning log for parse errors (#1534)
  fix(server): Retain valid cached project states on error (#1426)
  feat(protocol): Implement response context schema (#1529)
  feat(replays): emit org_id on recording kafka messages (#1528)
  feat: Add .NET/Portable-PDB specific protocol fields (#1518)
  feat(quotas): Enforce rate limits on metrics buckets (#1515)
  ref(pii): Consider all token as sensitive [INGEST-1550] (#1527)
  release: 22.10.0
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.

4 participants