Skip to content

Commit eae44cc

Browse files
committed
extend shell capture for wait-for-namenodes and format-zooekeeper
1 parent a2d8d8a commit eae44cc

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

rust/operator-binary/src/container.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ impl ContainerConfig {
693693
for namenode_id in {pod_names}
694694
do
695695
echo -n "Checking pod $namenode_id... "
696+
696697
# We only redirect 2 (stderr) to 4 (console).
697698
# We leave 1 (stdout) alone so the $(...) can catch it.
698699
SERVICE_STATE=$({hadoop_home}/bin/hdfs haadmin -getServiceState "$namenode_id" 2>&4 | tail -n1 || true)
@@ -703,18 +704,18 @@ impl ContainerConfig {
703704
echo "active"
704705
break
705706
else
706-
echo "unknown"
707+
echo "unknown / unreachable"
707708
fi
708709
done
709710
710711
if [ ! -f "{NAMENODE_ROOT_DATA_DIR}/current/VERSION" ]
711712
then
712713
if [ -z ${{ACTIVE_NAMENODE+x}} ]
713714
then
714-
echo "Create pod $POD_NAME as active namenode."
715+
echo "No active namenode found. Formatting $POD_NAME as active."
715716
exclude_from_capture {hadoop_home}/bin/hdfs namenode -format -noninteractive
716717
else
717-
echo "Create pod $POD_NAME as standby namenode."
718+
echo "Active namenode is $ACTIVE_NAMENODE. Bootstrapping standby."
718719
exclude_from_capture {hadoop_home}/bin/hdfs namenode -bootstrapStandby -nonInteractive
719720
fi
720721
else
@@ -733,6 +734,7 @@ impl ContainerConfig {
733734
ContainerConfig::FormatZooKeeper { container_name, .. } => {
734735
args.push_str(&bash_capture_shell_helper(container_name));
735736
args.push_str("start_capture\n");
737+
736738
if let Some(container_config) = merged_config.as_namenode().map(|node| {
737739
node.logging
738740
.for_container(&NameNodeContainer::FormatZooKeeper)
@@ -747,11 +749,7 @@ impl ContainerConfig {
747749
echo "Attempt to format ZooKeeper..."
748750
if [[ "0" -eq "$(echo $POD_NAME | sed -e 's/.*-//')" ]] ; then
749751
set +e
750-
# Restore original stdout/stderr from FD 3 and 4
751-
exec 1>&3 2>&4
752-
# Clean up (close FD 3 and 4)
753-
exec 3>&- 4>&-
754-
{hadoop_home}/bin/hdfs zkfc -formatZK -nonInteractive
752+
exclude_from_capture {hadoop_home}/bin/hdfs zkfc -formatZK -nonInteractive
755753
EXITCODE=$?
756754
set -e
757755
if [[ $EXITCODE -eq 0 ]]; then
@@ -770,7 +768,10 @@ impl ContainerConfig {
770768
hadoop_home = Self::HADOOP_HOME,
771769
));
772770
}
773-
ContainerConfig::WaitForNameNodes { .. } => {
771+
ContainerConfig::WaitForNameNodes { container_name, .. } => {
772+
args.push_str(&bash_capture_shell_helper(container_name));
773+
args.push_str("start_capture\n");
774+
774775
if let Some(container_config) = merged_config.as_datanode().map(|node| {
775776
node.logging
776777
.for_container(&DataNodeContainer::WaitForNameNodes)
@@ -793,7 +794,11 @@ impl ContainerConfig {
793794
for namenode_id in {pod_names}
794795
do
795796
echo -n "Checking pod $namenode_id... "
796-
{get_service_state_command}
797+
798+
# We only redirect 2 (stderr) to 4 (console).
799+
# We leave 1 (stdout) alone so the $(...) can catch it.
800+
SERVICE_STATE=$({hadoop_home}/bin/hdfs haadmin -getServiceState "$namenode_id" 2>&4 | tail -n1 || true)
801+
797802
if [ "$SERVICE_STATE" = "active" ] || [ "$SERVICE_STATE" = "standby" ]
798803
then
799804
echo "$SERVICE_STATE"
@@ -812,7 +817,7 @@ impl ContainerConfig {
812817
sleep 5
813818
done
814819
"###,
815-
get_service_state_command = Self::get_namenode_service_state_command(),
820+
hadoop_home = Self::HADOOP_HOME,
816821
pod_names = namenode_podrefs
817822
.iter()
818823
.map(|pod_ref| pod_ref.pod_name.as_ref())
@@ -854,14 +859,6 @@ impl ContainerConfig {
854859
))
855860
}
856861

857-
fn get_namenode_service_state_command() -> String {
858-
formatdoc!(
859-
r###"
860-
SERVICE_STATE=$({hadoop_home}/bin/hdfs haadmin -getServiceState $namenode_id | tail -n1 || true)"###,
861-
hadoop_home = Self::HADOOP_HOME,
862-
)
863-
}
864-
865862
/// Returns the container env variables.
866863
fn env(
867864
&self,

0 commit comments

Comments
 (0)