-
Notifications
You must be signed in to change notification settings - Fork 56
fix: support state save and restore redeploy workflow #5375
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
Open
JeffreyDallas
wants to merge
30
commits into
main
Choose a base branch
from
02379-D-start-saved-state
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
e2441be
update
JeffreyDallas 52a3680
save
JeffreyDallas ad84f73
save
JeffreyDallas 9bf5cce
save
JeffreyDallas 8af5972
save
JeffreyDallas 96dd7d2
save
JeffreyDallas 16cead5
save
JeffreyDallas e29cf3c
save
JeffreyDallas 404fe9b
save
JeffreyDallas fd755ec
Merge commit '57fac1ca5db633cf63cdf5f191a135489c40dbdc' into 02379-D-…
JeffreyDallas fb9b87d
simplify
JeffreyDallas 21b6ddb
save
JeffreyDallas 1265a4a
format
JeffreyDallas ec0a27f
format
JeffreyDallas cf0d832
extend test time
JeffreyDallas 9728385
same
JeffreyDallas 1f94a04
merge
JeffreyDallas b36ed41
Merge branch 'main' into 02379-D-start-saved-state
JeffreyDallas b534f83
Merge branch 'main' into 02379-D-start-saved-state
JeffreyDallas 5d5b02a
Merge branch 'main' into 02379-D-start-saved-state
JeffreyDallas f9da5b5
Merge branch 'main' into 02379-D-start-saved-state
JeffreyDallas 6465468
fix
JeffreyDallas 4f8b0b2
Merge branch 'main' into 02379-D-start-saved-state
JeffreyDallas 785626e
fix: prevent restored consensus nodes from replaying into a stale freeze
JeffreyDallas 52a9b6b
fix: scope preconsensus-event trimming to callers that resume live
JeffreyDallas d8fcb4d
Merge branch 'main' into 02379-D-start-saved-state
JeffreyDallas 0a2a4f7
format
JeffreyDallas aaabc8f
address PR review feedback: tests, perf, and cleanup
JeffreyDallas 3481e9d
Merge branch 'main' into 02379-D-start-saved-state
JeffreyDallas 2c30618
Merge branch 'main' into 02379-D-start-saved-state
JeffreyDallas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
173 changes: 173 additions & 0 deletions
173
examples/state-save-and-restore/scripts/generate-override-network.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| #!/usr/bin/env node | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import fs from 'node:fs'; | ||
|
|
||
| class OverrideNetworkGenerator { | ||
| static main() { | ||
| const argumentsMap = this.parseArguments(process.argv.slice(2)); | ||
| const sourceNetworkPath = this.requireArgument(argumentsMap, 'source-network'); | ||
| const servicesJsonPath = this.requireArgument(argumentsMap, 'services-json'); | ||
| const nodeAliasesText = this.requireArgument(argumentsMap, 'node-aliases'); | ||
| const outputPath = this.requireArgument(argumentsMap, 'output'); | ||
| const sourceNetwork = JSON.parse(fs.readFileSync(sourceNetworkPath, 'utf8')); | ||
| const servicesDocument = JSON.parse(fs.readFileSync(servicesJsonPath, 'utf8')); | ||
| const nodeAliases = nodeAliasesText | ||
| .split(',') | ||
| .map(nodeAlias => nodeAlias.trim()) | ||
| .filter(nodeAlias => nodeAlias.length > 0); | ||
|
|
||
| if (!Array.isArray(sourceNetwork.nodeMetadata)) { | ||
| throw new Error('source network JSON is missing nodeMetadata'); | ||
| } | ||
|
|
||
| if (!Array.isArray(servicesDocument.items)) { | ||
| throw new Error('services JSON is missing items'); | ||
| } | ||
|
|
||
| if (sourceNetwork.nodeMetadata.length < nodeAliases.length) { | ||
| throw new Error( | ||
| `source network only has ${String(sourceNetwork.nodeMetadata.length)} nodeMetadata entries for ${String(nodeAliases.length)} aliases`, | ||
| ); | ||
| } | ||
|
|
||
| const rewrittenNetwork = structuredClone(sourceNetwork); | ||
| let changedEndpointCount = 0; | ||
|
|
||
| for (const [nodeIndex, nodeAlias] of nodeAliases.entries()) { | ||
| const serviceName = `network-${nodeAlias}-svc`; | ||
|
JeffreyDallas marked this conversation as resolved.
|
||
| const service = servicesDocument.items.find(candidateService => candidateService?.metadata?.name === serviceName); | ||
|
|
||
| if (!service) { | ||
| throw new Error(`service not found in services JSON: ${serviceName}`); | ||
| } | ||
|
|
||
| const clusterIpAddress = service?.spec?.clusterIP; | ||
| if (typeof clusterIpAddress !== 'string' || clusterIpAddress.length === 0 || clusterIpAddress === 'None') { | ||
| throw new Error(`service ${serviceName} does not have a usable clusterIP`); | ||
| } | ||
|
|
||
| const encodedIpAddress = this.encodeIpv4Address(clusterIpAddress); | ||
| const nodeMetadata = rewrittenNetwork.nodeMetadata[nodeIndex]; | ||
| changedEndpointCount += this.rewriteNodeEndpoints(nodeMetadata, encodedIpAddress, clusterIpAddress, serviceName); | ||
| } | ||
|
|
||
| if (changedEndpointCount === 0) { | ||
| throw new Error('override-network.json was not changed; this would not test endpoint remapping'); | ||
| } | ||
|
|
||
| fs.writeFileSync(outputPath, `${JSON.stringify(rewrittenNetwork, null, 2)}\n`); | ||
| console.log(`Wrote ${outputPath} with ${String(changedEndpointCount)} rewritten endpoint entries`); | ||
| } | ||
|
|
||
| static parseArguments(argumentList) { | ||
| const argumentsMap = new Map(); | ||
|
|
||
| for (let argumentIndex = 0; argumentIndex < argumentList.length; argumentIndex += 1) { | ||
| const argument = argumentList[argumentIndex]; | ||
| if (!argument.startsWith('--')) { | ||
| throw new Error(`Unexpected argument: ${argument}`); | ||
| } | ||
|
|
||
| const argumentName = argument.slice(2); | ||
| const argumentValue = argumentList[argumentIndex + 1]; | ||
| if (!argumentValue || argumentValue.startsWith('--')) { | ||
| throw new Error(`Missing value for --${argumentName}`); | ||
| } | ||
|
|
||
| argumentsMap.set(argumentName, argumentValue); | ||
| argumentIndex += 1; | ||
| } | ||
|
|
||
| return argumentsMap; | ||
| } | ||
|
|
||
| static requireArgument(argumentsMap, argumentName) { | ||
| const argumentValue = argumentsMap.get(argumentName); | ||
| if (!argumentValue) { | ||
| throw new Error(`Missing required argument --${argumentName}`); | ||
| } | ||
| return argumentValue; | ||
| } | ||
|
|
||
| static encodeIpv4Address(ipAddressText) { | ||
| const octets = ipAddressText.split('.').map(octetText => Number(octetText)); | ||
|
|
||
| if (octets.length !== 4 || octets.some(octet => !Number.isInteger(octet) || octet < 0 || octet > 255)) { | ||
| throw new Error(`Only IPv4 addresses are supported, got: ${ipAddressText}`); | ||
| } | ||
|
|
||
| return Buffer.from(octets).toString('base64'); | ||
| } | ||
|
|
||
| static rewriteNodeEndpoints(nodeMetadata, encodedIpAddress, clusterIpAddress, serviceName) { | ||
| if (!nodeMetadata || typeof nodeMetadata !== 'object') { | ||
| throw new Error('nodeMetadata entry is missing or invalid'); | ||
| } | ||
|
|
||
| // The restored roster uses gossip endpoints before the service endpoints are | ||
| // needed. Rewrite both representations so the fresh cluster can establish | ||
| // peer sync without depending on endpoint names from the source cluster. | ||
| let changedEndpointCount = this.rewriteEndpointList( | ||
| nodeMetadata?.node, | ||
| 'gossipEndpoint', | ||
| encodedIpAddress, | ||
| clusterIpAddress, | ||
| serviceName, | ||
| ); | ||
| changedEndpointCount += this.rewriteEndpointList( | ||
| nodeMetadata?.node, | ||
| 'serviceEndpoint', | ||
| encodedIpAddress, | ||
| clusterIpAddress, | ||
| serviceName, | ||
| ); | ||
| changedEndpointCount += this.rewriteEndpointList( | ||
| nodeMetadata?.rosterEntry, | ||
| 'gossipEndpoint', | ||
| encodedIpAddress, | ||
| clusterIpAddress, | ||
| serviceName, | ||
| ); | ||
| return changedEndpointCount; | ||
| } | ||
|
|
||
| static rewriteEndpointList(parentObject, endpointProperty, encodedIpAddress, clusterIpAddress, serviceName) { | ||
| if (!parentObject || typeof parentObject !== 'object') { | ||
| throw new Error(`node metadata is missing for ${serviceName}`); | ||
| } | ||
|
|
||
| const endpoints = parentObject[endpointProperty]; | ||
| if (!Array.isArray(endpoints) || endpoints.length === 0) { | ||
| throw new Error(`node is missing ${endpointProperty} entries for ${serviceName}`); | ||
| } | ||
|
|
||
| let changedEndpointCount = 0; | ||
|
|
||
| parentObject[endpointProperty] = endpoints.map(endpoint => { | ||
| const rewrittenEndpoint = {...endpoint}; | ||
| const existingIpAddress = rewrittenEndpoint.ipAddressV4; | ||
|
|
||
| rewrittenEndpoint.ipAddressV4 = encodedIpAddress; | ||
| delete rewrittenEndpoint.domainName; | ||
|
|
||
| const endpointChanged = existingIpAddress !== encodedIpAddress; | ||
| if (endpointChanged) { | ||
| changedEndpointCount += 1; | ||
| } | ||
|
|
||
| return rewrittenEndpoint; | ||
| }); | ||
|
|
||
| console.log(`Updated ${endpointProperty} for ${serviceName} -> ${clusterIpAddress}`); | ||
| return changedEndpointCount; | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| OverrideNetworkGenerator.main(); | ||
| } catch (error) { | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| console.error(message); | ||
| process.exitCode = 1; | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.