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

Rolling HDFS upgrade #571

Merged
merged 30 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a5e9547
Add upgrade mode with serialized deployments
nightkr Aug 2, 2024
fc6cc0d
Use deployedProductVersion to decide upgrade mode (but do not automat…
nightkr Aug 2, 2024
2eb38a8
Upgrade docs
nightkr Aug 2, 2024
38809e2
Remove dummy log message
nightkr Aug 2, 2024
a36de0f
Move upgrade readiness check into utils module
nightkr Aug 2, 2024
acffa82
Fix test build issue
nightkr Aug 5, 2024
98baaad
Regenerate CRDs
nightkr Aug 5, 2024
5a552d3
Docs
nightkr Aug 5, 2024
c1e13a2
s/terminal/shell/g
nightkr Aug 5, 2024
e1476a2
Update rust/operator-binary/src/hdfs_controller.rs
nightkr Aug 5, 2024
8af1db6
Update docs/modules/hdfs/pages/usage-guide/upgrading.adoc
nightkr Aug 6, 2024
44b5e59
Update docs/modules/hdfs/pages/usage-guide/upgrading.adoc
nightkr Aug 6, 2024
947931e
Update docs/modules/hdfs/pages/usage-guide/upgrading.adoc
nightkr Aug 7, 2024
5970585
Update docs/modules/hdfs/pages/usage-guide/upgrading.adoc
nightkr Aug 7, 2024
13129b5
Update docs/modules/hdfs/pages/usage-guide/upgrading.adoc
nightkr Aug 7, 2024
eb19010
Move upgrade_args to a separate variable
nightkr Aug 7, 2024
d5a092a
Merge branch 'feature/upgrade' of github.com:stackabletech/hdfs-opera…
nightkr Aug 7, 2024
f0df2b7
Upgrade mode -> compatibility mode
nightkr Aug 8, 2024
49cf9d9
Move rollout tracker into operator-rs
nightkr Aug 8, 2024
c582a3a
Update docs/modules/hdfs/pages/usage-guide/upgrading.adoc
nightkr Aug 8, 2024
b24c25f
Add note on downgrades
nightkr Aug 9, 2024
1e68f1d
Merge branch 'feature/upgrade' of github.com:stackabletech/hdfs-opera…
nightkr Aug 9, 2024
10e5220
Perform downgrades in order
nightkr Aug 9, 2024
808f926
Add note about status subresource
nightkr Aug 9, 2024
a9809ba
Update CRDs
nightkr Aug 9, 2024
0604aa6
s/upgrading_product_version/upgrade_target_product_version/g
nightkr Aug 12, 2024
c142421
Switch to main operator-rs
nightkr Aug 12, 2024
6ae8e0b
Update rust/crd/src/lib.rs
nightkr Aug 21, 2024
46eedee
Merge branch 'main' into feature/upgrade
nightkr Aug 26, 2024
2a25ff4
Add guardrail against trying to crossgrade in the middle of another u…
nightkr Aug 26, 2024
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
7 changes: 3 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions Cargo.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9"
snafu = "0.8"
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.73.0" }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.74.0" }
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" }
strum = { version = "0.26", features = ["derive"] }
tokio = { version = "1.39", features = ["full"] }
tracing = "0.1"
tracing-futures = { version = "0.2", features = ["futures-03"] }

#[patch."https://github.com/stackabletech/operator-rs.git"]
[patch."https://github.com/stackabletech/operator-rs.git"]
#stackable-operator = { path = "../operator-rs/crates/stackable-operator" }
#stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch = "main" }
4 changes: 2 additions & 2 deletions crate-hashes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions deploy/helm/hdfs-operator/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,17 @@ spec:
- type
type: object
type: array
deployedProductVersion:
description: |-
The product version that the HDFS cluster is currently running.

During upgrades, this field contains the *old* version.
nullable: true
type: string
upgradeTargetProductVersion:
description: The product version that is currently being upgraded to, otherwise null.
nullable: true
type: string
type: object
required:
- spec
Expand Down
107 changes: 107 additions & 0 deletions docs/modules/hdfs/pages/usage-guide/upgrading.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
= Upgrading HDFS

IMPORTANT: HDFS upgrades are experimental, and details may change at any time

HDFS currently requires a manual process to upgrade. This guide will take you through an example case, upgrading an example cluster (from our xref:getting_started/index.adoc[Getting Started] guide) from HDFS 3.3.6 to 3.4.0.
NickLarsenNZ marked this conversation as resolved.
Show resolved Hide resolved

== Preparing for the worst

Upgrades can fail, and it is important to prepare for when that happens. Apache HDFS supports https://hadoop.apache.org/docs/r3.4.0/hadoop-project-dist/hadoop-hdfs/HdfsRollingUpgrade.html#Downgrade_and_Rollback[two ways to revert an upgrade]:

Rollback:: Reverts all user data to the pre-upgrade state. Requires taking the cluster offline.
Downgrade:: Downgrades the HDFS software but preserves all changes made by users. Can be performed as a rolling change, keeping the cluster online.

The Stackable Operator for HDFS supports downgrading but not rollbacks.

In order to downgrade, revert the `.spec.image.productVersion` field, and then proceed to xref:#finalize[finalizing] once the cluster is downgraded:

[source,shell]
----
$ kubectl patch hdfs/simple-hdfs --patch '{"spec": {"image": {"productVersion": "3.3.6"}}}' --type=merge
hdfscluster.hdfs.stackable.tech/simple-hdfs patched
----

== Preparing HDFS

HDFS must be configured to initiate the upgrade process. To do this, put the cluster into upgrade mode by running the following commands in an HDFS superuser environment
(either a client configured with a superuser account, or from inside a NameNode pod):

// This could be automated by the operator, but dfsadmin does not have good machine-readable output.
// It *can* be queried over JMX, but we're not so lucky for finalization.
NickLarsenNZ marked this conversation as resolved.
Show resolved Hide resolved

[source,shell]
----
$ hdfs dfsadmin -rollingUpgrade prepare

Check notice on line 34 in docs/modules/hdfs/pages/usage-guide/upgrading.adoc

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] docs/modules/hdfs/pages/usage-guide/upgrading.adoc#L34

Possible typo: you repeated a word (ENGLISH_WORD_REPEAT_RULE) Suggestions: `prepare` Rule: https://community.languagetool.org/rule/show/ENGLISH_WORD_REPEAT_RULE?lang=en-US Category: MISC
Raw output
docs/modules/hdfs/pages/usage-guide/upgrading.adoc:34:32: Possible typo: you repeated a word (ENGLISH_WORD_REPEAT_RULE)
 Suggestions: `prepare`
 Rule: https://community.languagetool.org/rule/show/ENGLISH_WORD_REPEAT_RULE?lang=en-US
 Category: MISC
PREPARE rolling upgrade ...
Preparing for upgrade. Data is being saved for rollback.
Run "dfsadmin -rollingUpgrade query" to check the status
for proceeding with rolling upgrade
Block Pool ID: BP-841432641-10.244.0.29-1722612757853
Start Time: Fri Aug 02 15:49:12 GMT 2024 (=1722613752341)
Finalize Time: <NOT FINALIZED>

$ # Then run query until the HDFS is ready to proceed
$ hdfs dfsadmin -rollingUpgrade query

Check notice on line 44 in docs/modules/hdfs/pages/usage-guide/upgrading.adoc

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] docs/modules/hdfs/pages/usage-guide/upgrading.adoc#L44

Possible typo: you repeated a word (ENGLISH_WORD_REPEAT_RULE) Suggestions: `query` Rule: https://community.languagetool.org/rule/show/ENGLISH_WORD_REPEAT_RULE?lang=en-US Category: MISC
Raw output
docs/modules/hdfs/pages/usage-guide/upgrading.adoc:44:32: Possible typo: you repeated a word (ENGLISH_WORD_REPEAT_RULE)
 Suggestions: `query`
 Rule: https://community.languagetool.org/rule/show/ENGLISH_WORD_REPEAT_RULE?lang=en-US
 Category: MISC
QUERY rolling upgrade ...
Preparing for upgrade. Data is being saved for rollback.
Run "dfsadmin -rollingUpgrade query" to check the status
for proceeding with rolling upgrade
Block Pool ID: BP-841432641-10.244.0.29-1722612757853
Start Time: Fri Aug 02 15:49:12 GMT 2024 (=1722613752341)
Finalize Time: <NOT FINALIZED>

$ # It is safe to proceed when the output indicates so, like this:
$ hdfs dfsadmin -rollingUpgrade query

Check notice on line 54 in docs/modules/hdfs/pages/usage-guide/upgrading.adoc

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] docs/modules/hdfs/pages/usage-guide/upgrading.adoc#L54

Possible typo: you repeated a word (ENGLISH_WORD_REPEAT_RULE) Suggestions: `query` Rule: https://community.languagetool.org/rule/show/ENGLISH_WORD_REPEAT_RULE?lang=en-US Category: MISC
Raw output
docs/modules/hdfs/pages/usage-guide/upgrading.adoc:54:32: Possible typo: you repeated a word (ENGLISH_WORD_REPEAT_RULE)
 Suggestions: `query`
 Rule: https://community.languagetool.org/rule/show/ENGLISH_WORD_REPEAT_RULE?lang=en-US
 Category: MISC
QUERY rolling upgrade ...
Proceed with rolling upgrade:
Block Pool ID: BP-841432641-10.244.0.29-1722612757853
Start Time: Fri Aug 02 15:49:12 GMT 2024 (=1722613752341)
Finalize Time: <NOT FINALIZED>
----

== Starting the upgrade

Once HDFS is ready to upgrade, the HdfsCluster can be updated with the new product version:

[source,shell]
----
$ kubectl patch hdfs/simple-hdfs --patch '{"spec": {"image": {"productVersion": "3.4.0"}}}' --type=merge
hdfscluster.hdfs.stackable.tech/simple-hdfs patched
----

Then wait until all pods have restarted, are in the Ready state, and running the new HDFS version.

NOTE: This will automatically enable the NameNodes' compatibility mode, allowing them to start despite the fsImage version mismatch.

NOTE: Services will be upgraded in order: JournalNodes, then NameNodes, then DataNodes.

[#finalize]
== Finalizing the upgrade

Once all HDFS pods are running the new version, the HDFS upgrade can be finalized (from the HDFS superuser environment as described in the preparation step):

[source,shell]
----
$ hdfs dfsadmin -rollingUpgrade finalize

Check notice on line 85 in docs/modules/hdfs/pages/usage-guide/upgrading.adoc

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] docs/modules/hdfs/pages/usage-guide/upgrading.adoc#L85

Possible typo: you repeated a word (ENGLISH_WORD_REPEAT_RULE) Suggestions: `finalize` Rule: https://community.languagetool.org/rule/show/ENGLISH_WORD_REPEAT_RULE?lang=en-US Category: MISC
Raw output
docs/modules/hdfs/pages/usage-guide/upgrading.adoc:85:32: Possible typo: you repeated a word (ENGLISH_WORD_REPEAT_RULE)
 Suggestions: `finalize`
 Rule: https://community.languagetool.org/rule/show/ENGLISH_WORD_REPEAT_RULE?lang=en-US
 Category: MISC
FINALIZE rolling upgrade ...
Rolling upgrade is finalized.
Block Pool ID: BP-841432641-10.244.0.29-1722612757853
Start Time: Fri Aug 02 15:49:12 GMT 2024 (=1722613752341)
Finalize Time: Fri Aug 02 15:58:39 GMT 2024 (=1722614319854)
----

// We can't safely automate this, because finalize is asynchronous and doesn't tell us whether all NameNodes have even received the request to finalize.
NickLarsenNZ marked this conversation as resolved.
Show resolved Hide resolved

WARNING: Please ensure that all NameNodes are running and available before proceeding. NameNodes that have not finalized yet will crash on launch when taken out of compatibility mode.

Finally, mark the cluster as upgraded:

[source,shell]
----
$ kubectl patch hdfs/simple-hdfs --subresource=status --patch '{"status": {"deployedProductVersion": "3.4.0"}}' --type=merge
hdfscluster.hdfs.stackable.tech/simple-hdfs patched
----

NOTE: `deployedProductVersion` is located in the _status_ subresource, which will not be modified by most graphical editors, and `kubectl` requires the `--subresource=status` flag.

The NameNodes will then be restarted a final time, taking them out of compatibility mode.
1 change: 1 addition & 0 deletions docs/modules/hdfs/partials/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
** xref:hdfs:usage-guide/logging-log-aggregation.adoc[]
** xref:hdfs:usage-guide/monitoring.adoc[]
** xref:hdfs:usage-guide/configuration-environment-overrides.adoc[]
** xref:hdfs:usage-guide/upgrading.adoc[]
** xref:hdfs:usage-guide/operations/index.adoc[]
*** xref:hdfs:usage-guide/operations/cluster-operations.adoc[]
*** xref:hdfs:usage-guide/operations/pod-placement.adoc[]
Expand Down
75 changes: 71 additions & 4 deletions rust/crd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use stackable_operator::{
status::condition::{ClusterCondition, HasStatusCondition},
time::Duration,
};
use strum::{Display, EnumIter, EnumString};
use strum::{Display, EnumIter, EnumString, IntoStaticStr};

use crate::{
affinity::get_affinity,
Expand Down Expand Up @@ -312,27 +312,29 @@ impl AnyNodeConfig {

#[derive(
Clone,
Copy,
Debug,
Deserialize,
Display,
EnumIter,
EnumString,
IntoStaticStr,
Eq,
Hash,
JsonSchema,
PartialEq,
Serialize,
)]
pub enum HdfsRole {
#[serde(rename = "journalnode")]
#[strum(serialize = "journalnode")]
JournalNode,
#[serde(rename = "namenode")]
#[strum(serialize = "namenode")]
NameNode,
#[serde(rename = "datanode")]
#[strum(serialize = "datanode")]
DataNode,
#[serde(rename = "journalnode")]
#[strum(serialize = "journalnode")]
JournalNode,
}

impl HdfsRole {
Expand Down Expand Up @@ -802,6 +804,43 @@ impl HdfsCluster {
Ok(result)
}

pub fn upgrade_state(&self) -> Result<Option<UpgradeState>, UpgradeStateError> {
use upgrade_state_error::*;
let Some(status) = self.status.as_ref() else {
return Ok(None);
};
let requested_version = self.spec.image.product_version();
let Some(deployed_version) = status.deployed_product_version.as_deref() else {
// If no deployed version, fresh install -> no upgrade
return Ok(None);
};
let current_upgrade_target_version = status.upgrade_target_product_version.as_deref();

if requested_version != deployed_version {
// If we're requesting a different version than what is deployed, assume that we're upgrading.
NickLarsenNZ marked this conversation as resolved.
Show resolved Hide resolved
// Could also be a downgrade to an older version, but we don't support downgrades after upgrade finalization.
NickLarsenNZ marked this conversation as resolved.
Show resolved Hide resolved
match current_upgrade_target_version {
Some(upgrading_version) if requested_version != upgrading_version => {
// If we're in an upgrade, do not allow switching to a third version
InvalidCrossgradeSnafu {
requested_version,
deployed_version,
upgrading_version,
}
.fail()
}
_ => Ok(Some(UpgradeState::Upgrading)),
}
} else if current_upgrade_target_version.is_some_and(|x| requested_version != x) {
// If we're requesting the old version mid-upgrade, assume that we're downgrading.
// We only support downgrading to the exact previous version.
Ok(Some(UpgradeState::Downgrading))
} else {
// All three versions match, upgrade was completed without clearing `upgrading_product_version`.
Ok(None)
}
}

pub fn authentication_config(&self) -> Option<&AuthenticationConfig> {
self.spec.cluster_config.authentication.as_ref()
}
Expand Down Expand Up @@ -955,6 +994,26 @@ impl HdfsPodRef {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UpgradeState {
/// The cluster is currently being upgraded to a new version.
Upgrading,

/// The cluster is currently being downgraded to the previous version.
Downgrading,
}

#[derive(Debug, Snafu)]
#[snafu(module)]
pub enum UpgradeStateError {
#[snafu(display("requested version {requested_version:?} while still upgrading from {deployed_version:?} to {upgrading_version:?}, please finish the upgrade or downgrade first"))]
InvalidCrossgrade {
requested_version: String,
deployed_version: String,
upgrading_version: String,
},
}

#[derive(
Clone,
Debug,
Expand Down Expand Up @@ -1322,6 +1381,14 @@ impl Configuration for JournalNodeConfigFragment {
pub struct HdfsClusterStatus {
#[serde(default)]
pub conditions: Vec<ClusterCondition>,

/// The product version that the HDFS cluster is currently running.
///
/// During upgrades, this field contains the *old* version.
pub deployed_product_version: Option<String>,

/// The product version that is currently being upgraded to, otherwise null.
pub upgrade_target_product_version: Option<String>,
}

impl HasStatusCondition for HdfsCluster {
Expand Down
Loading
Loading