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

(2.11) ADR-44: JetStream Dynamic Metadata #5857

Merged
merged 17 commits into from
Sep 7, 2024
Merged

Conversation

MauriceVanVeen
Copy link
Member

Implements ADR-44
Extends #5850

Add dynamic JetStream stream/consumer metadata:

_nats.server.version
_nats.server.api_level

These are not persisted and are only returned in the response of a create/update/info request.

Signed-off-by: Maurice van Veen github@mauricevanveen.com

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
…kage

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@MauriceVanVeen MauriceVanVeen marked this pull request as ready for review September 3, 2024 12:07
@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner September 3, 2024 12:07
@derekcollison
Copy link
Member

This will only report the api version from the meta-leader correct?

@MauriceVanVeen
Copy link
Member Author

This will only report the api version from the meta-leader correct?

The versions will be reported from the one answering the create/update/info request. Which will be only the stream/consumer leader hosting the asset at that time.

@@ -1478,7 +1478,7 @@ func (s *Server) jsStreamCreateRequest(sub *subscription, c *client, _ *Account,
resp.StreamInfo = &StreamInfo{
Created: mset.createdTime(),
State: mset.state(),
Config: mset.config(),
Config: includeDynamicStreamAssetVersionMetadata(mset.config()),
Copy link
Member

Choose a reason for hiding this comment

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

Prefer shorter names ;)

@@ -177,6 +208,51 @@ func TestJetStreamSetConsumerAssetVersionMetadata(t *testing.T) {
}
}

func TestJetStreamSetConsumerAssetVersionMetadataRemoveDynamicFields(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Test names matter since they need to plug into the CI/CD matching when running the tests in parallel.

Copy link
Member Author

Choose a reason for hiding this comment

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

The test names are currently prefixed with TestJetStream so they are run as part of the js_tests. This file also contains the following on top:

//go:build !skip_js_tests
// +build !skip_js_tests

Is this sufficient or does something need to be changed?

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@@ -47,13 +53,29 @@ func setStaticStreamMetadata(cfg *StreamConfig, prevCfg *StreamConfig) {
cfg.Metadata[JSRequiredLevelMetadataKey] = strconv.Itoa(requiredApiLevel)
}

// setDynamicStreamMetadata adds dynamic fields into the (copied) metadata.
func setDynamicStreamMetadata(cfg StreamConfig) StreamConfig {
Copy link
Member

Choose a reason for hiding this comment

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

Doing the pass by value / copy here twice again, in and out of this function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to use pointers

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@derekcollison derekcollison self-requested a review September 6, 2024 20:32
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

LGTM

derekcollison pushed a commit that referenced this pull request Sep 7, 2024
Implements
[ADR-44](https://github.com/nats-io/nats-architecture-and-design/blob/main/adr/ADR-44.md)

Initial addition of JetStream Asset Versioning, containing:
- generating stream and consumer metadata
  - created server version: `_nats.created.server.version`
  - created server API level: `_nats.created.server.api_level`
  - required server API level: `_nats.server.require.api_level`
- logging supported API level upon startup: `[INF]   API Level:       1`

<br>

Note that stream and consumer metadata is only set/updated upon:
- creating a new stream/consumer
- updating a stream/consumer
_(created metadata will not be set for pre-existing assets, only
required level will be updated)_

<br>

Many tests are added ensuring that:
- restoring streams from backups doesn't set this metadata
_(if it doesn't exist, for example restoring a backup from a previous
version)_
- restarting a server (or upgrading) doesn't set this metadata
  _(if it doesn't exist, for example due to upgrading)_
- updating consumer `PauseUntil` ups or lowers required API level
- metadata is consistently reported through add, update and info
requests
- only stream/consumer/meta leader determine the metadata, so that there
can be no skew in metadata if followers were allowed to update as well
- users can't manually supply these `_nats.>` metadata fields, they will
be overwritten to the appropriate values
- if the metadata is missing during an update, the metadata is preserved
_(for example an update by a client that doesn't know about metadata
yet)_

These tests check for both non-clustered R1 setups and clustered R3
setups.

<br>

This PR doesn't fully implement
[ADR-44](https://github.com/nats-io/nats-architecture-and-design/blob/main/adr/ADR-44.md).
There will be follow-up PRs later on to add support for:
- dynamic metadata, like `_nats.server.version` and
`_nats.server.api_level` that report the current server version and API
level the asset lives on:
  #5857
- reporting server JS API level through `jsz`, `varz` and `$JS.API.INFO`
(it is already reported in the logs during startup):
  #5855
- etc.

There are some slight inconsistencies between the ADR and this PR. For
example using the terms feature level, `api_version` and `api_level`
that all mean the same and are all made consistent to be `api_level`.
I'll correct the ADR with any changed details after this PR has been
merged.

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>

---------

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Base automatically changed from adr-44/jetstream-asset-versioning to main September 7, 2024 01:18
@derekcollison derekcollison merged commit 69c57cb into main Sep 7, 2024
3 of 5 checks passed
@derekcollison derekcollison deleted the adr-44/dynamic-metadata branch September 7, 2024 18:47
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.

2 participants