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

[KYUUBI #5987] Enhance KYUUBI_HOME detection in shell script to handle softlink cases #5988

Closed
wants to merge 5 commits into from

Conversation

Emor-nj
Copy link
Contributor

@Emor-nj Emor-nj commented Jan 17, 2024

🔍 Description

Issue References 🔗

This pull request fixes #5987
Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable.

Describe Your Solution 🔧

If the environment has already declared KYUUBI_HOME, it should use the pre-declared KYUUBI_HOME instead of forcefully specifying the parent directory of the current one.

Types of changes 🔖

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Test Plan 🧪

Behavior Without This Pull Request ⚰️

  1. set soft link:
    ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline
  2. set env like:
    export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi
  3. run kyuubi-beeline:
    kyuubi-beeline -u "jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOST@xxx"
  4. command will fail:
    /bin/kyuubi-beeline: line 27: //bin/load-kyuubi-env.sh: No such file or directory Error: JAVA_HOME IS NOT SET! CANNOT PROCEED.

Behavior With This Pull Request 🎉

  1. set soft link:
    ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline
  2. set env like:
    export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi
  3. run kyuubi-beeline:
    kyuubi-beeline -u "jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOST@xxx"
  4. command will success

Related Unit Tests


Checklist 📝

Be nice. Be informative.

@Emor-nj
Copy link
Contributor Author

Emor-nj commented Jan 17, 2024

cc @pan3793

@pan3793
Copy link
Member

pan3793 commented Jan 17, 2024

The change makes sense to me, mind supplying poistive/negative test cases in the PR description?

@pan3793
Copy link
Member

pan3793 commented Jan 17, 2024

seems we have the same issue on the other scripts.

actually, what we want to do here is to follow the soft link to find the real file, then locale the load-kyuubi-env.sh via the relative path. if we can do that, we don't even declare the evn KYUUBI_HOME before executing the soft link of those scripts

@pan3793
Copy link
Member

pan3793 commented Jan 17, 2024

I checked Spark's scripts, let's simply use this pattern

if [ -z "${KYUUBI_HOME}" ]; then
  KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
fi

@Emor-nj
Copy link
Contributor Author

Emor-nj commented Jan 17, 2024

seems we have the same issue on the other scripts.

actually, what we want to do here is to follow the soft link to find the real file, then locale the load-kyuubi-env.sh via the relative path. if we can do that, we don't even declare the evn KYUUBI_HOME before executing the soft link of those scripts

Good idea! Here's the modified line:
export KYUUBI_HOME="$(cd "$(dirname "$(realpath "$0")")"/..; pwd)"
If there are no issues, I will proceed to uniformly modify all related scripts.

@Emor-nj
Copy link
Contributor Author

Emor-nj commented Jan 17, 2024

I checked Spark's scripts, let's simply use this pattern

if [ -z "${KYUUBI_HOME}" ]; then
  KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
fi

Is the intention to maintain consistency with Spark by prioritizing the use of environment variables rather than directly obtaining the absolute path?

@pan3793
Copy link
Member

pan3793 commented Jan 17, 2024

is realpath available on all UNIX-like OS? I saw Spark handles it exceptionally

Is the intention to maintain consistency with Spark ...

I haven't seen users report similar issues to Spark, thus I suppose the approach Spark used is reliable, it always is my first fallback candidate if no better options.

@Emor-nj
Copy link
Contributor Author

Emor-nj commented Jan 17, 2024

is realpath available on all UNIX-like OS? I saw Spark handles it exceptionally

Is the intention to maintain consistency with Spark ...

I haven't seen users report similar issues to Spark, thus I suppose the approach Spark used is reliable, it always is my first fallback candidate if no better options.

Get it, let's align with Spark. I will uniformly modify all related scripts.

@cxzl25 cxzl25 changed the title [KYUUBI #5987]Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable. [KYUUBI #5987] Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable Jan 17, 2024
bin/beeline Outdated
@@ -19,7 +19,9 @@
## Kyuubi BeeLine Entrance
CLASS="org.apache.hive.beeline.KyuubiBeeLine"

export KYUUBI_HOME="${KYUUBI_HOME:-"$(cd "$(dirname "$0")"/.. || exit; pwd)"}"
if [ -z "${KYUUBI_HOME}" ]; then
export KYUUBI_HOME="$(cd "`dirname "$0"`"/..; pwd)"
Copy link
Member

Choose a reason for hiding this comment

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

export is not required

@pan3793 pan3793 changed the title [KYUUBI #5987] Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable [KYUUBI #5987] Enhance KYUUBI_HOME detection in shell script to handle softlink cases Jan 17, 2024
Copy link
Member

@pan3793 pan3793 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -18,7 +18,7 @@


if [ -z "${KYUUBI_HOME}" ]; then
export ${KYUUBI_HOME:-"$(cd "$(dirname "$0")"/.. || exit; pwd)"}
export KYUUBI_HOME="${KYUUBI_HOME:-"$(cd "$(dirname "$0")"/.. || exit; pwd)"}"
Copy link
Member

Choose a reason for hiding this comment

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

KYUUBI_HOME is always empty

Suggested change
export KYUUBI_HOME="${KYUUBI_HOME:-"$(cd "$(dirname "$0")"/.. || exit; pwd)"}"
export KYUUBI_HOME="$(cd "$(dirname "$0")"/.. || exit; pwd)"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get it, thanks

@pan3793 pan3793 added this to the v1.8.1 milestone Jan 17, 2024
@pan3793 pan3793 closed this in 7b38889 Jan 17, 2024
pan3793 pushed a commit that referenced this pull request Jan 17, 2024
…e softlink cases

# 🔍 Description
## Issue References 🔗

This pull request fixes #5987
Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable.

## Describe Your Solution 🔧

 If the environment has already declared KYUUBI_HOME, it should use the pre-declared KYUUBI_HOME instead of forcefully specifying the parent directory of the current one.

## Types of changes 🔖

- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Test Plan 🧪

#### Behavior Without This Pull Request ⚰️
1. set soft link:
 `ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline`
2. set env like:
`export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi`
3. run kyuubi-beeline:
`kyuubi-beeline -u "jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOSTxxx"`
4. command will fail:
`/bin/kyuubi-beeline: line 27: //bin/load-kyuubi-env.sh: No such file or directory
Error: JAVA_HOME IS NOT SET! CANNOT PROCEED.`

#### Behavior With This Pull Request 🎉
1. set soft link:
 `ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline`
2. set env like:
`export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi`
3. run kyuubi-beeline:
`kyuubi-beeline -u "jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOSTxxx"`
4. command will success
#### Related Unit Tests

---

# Checklist 📝

- [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)

**Be nice. Be informative.**

Closes #5988 from Emor-nj/kyuubi-beeline.

Closes #5987

3a988e0 [Emor-nj] fix KYUUBI_HOME is always empty in load-kyuubi-env.sh
cc70387 [Emor-nj] fix load-kyuubi-env.sh
a101428 [Emor-nj] Remove unnecessary exports.
f48db3f [Emor-nj] uniformly modify all related scripts.
35215b9 [Emor-nj] Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable.

Authored-by: Emor-nj <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
(cherry picked from commit 7b38889)
Signed-off-by: Cheng Pan <[email protected]>
@pan3793
Copy link
Member

pan3793 commented Jan 17, 2024

Thanks, merged to master/1.8

zhaohehuhu pushed a commit to zhaohehuhu/incubator-kyuubi that referenced this pull request Feb 5, 2024
… handle softlink cases

# 🔍 Description
## Issue References 🔗

This pull request fixes apache#5987
Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable.

## Describe Your Solution 🔧

 If the environment has already declared KYUUBI_HOME, it should use the pre-declared KYUUBI_HOME instead of forcefully specifying the parent directory of the current one.

## Types of changes 🔖

- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Test Plan 🧪

#### Behavior Without This Pull Request ⚰️
1. set soft link:
 `ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline`
2. set env like:
`export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi`
3. run kyuubi-beeline:
`kyuubi-beeline -u "jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOSTxxx"`
4. command will fail:
`/bin/kyuubi-beeline: line 27: //bin/load-kyuubi-env.sh: No such file or directory
Error: JAVA_HOME IS NOT SET! CANNOT PROCEED.`

#### Behavior With This Pull Request 🎉
1. set soft link:
 `ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline`
2. set env like:
`export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi`
3. run kyuubi-beeline:
`kyuubi-beeline -u "jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOSTxxx"`
4. command will success
#### Related Unit Tests

---

# Checklist 📝

- [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)

**Be nice. Be informative.**

Closes apache#5988 from Emor-nj/kyuubi-beeline.

Closes apache#5987

3a988e0 [Emor-nj] fix KYUUBI_HOME is always empty in load-kyuubi-env.sh
cc70387 [Emor-nj] fix load-kyuubi-env.sh
a101428 [Emor-nj] Remove unnecessary exports.
f48db3f [Emor-nj] uniformly modify all related scripts.
35215b9 [Emor-nj] Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable.

Authored-by: Emor-nj <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
zhaohehuhu pushed a commit to zhaohehuhu/incubator-kyuubi that referenced this pull request Mar 21, 2024
… handle softlink cases

# 🔍 Description
## Issue References 🔗

This pull request fixes apache#5987
Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable.

## Describe Your Solution 🔧

 If the environment has already declared KYUUBI_HOME, it should use the pre-declared KYUUBI_HOME instead of forcefully specifying the parent directory of the current one.

## Types of changes 🔖

- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Test Plan 🧪

#### Behavior Without This Pull Request ⚰️
1. set soft link:
 `ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline`
2. set env like:
`export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi`
3. run kyuubi-beeline:
`kyuubi-beeline -u "jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOSTxxx"`
4. command will fail:
`/bin/kyuubi-beeline: line 27: //bin/load-kyuubi-env.sh: No such file or directory
Error: JAVA_HOME IS NOT SET! CANNOT PROCEED.`

#### Behavior With This Pull Request 🎉
1. set soft link:
 `ln -s /opt/soft/kyuubi/kyuubi/bin/beeline /usr/bin/kyuubi-beeline`
2. set env like:
`export KYUUBI_HOME=/opt/soft/kyuubi/kyuubi`
3. run kyuubi-beeline:
`kyuubi-beeline -u "jdbc:hive2://xx.xx.xx.xx:2181,xx.xx.xx.xx:2181,xx.xx.xx.xx:2181/tmp;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=hive/_HOSTxxx"`
4. command will success
#### Related Unit Tests

---

# Checklist 📝

- [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)

**Be nice. Be informative.**

Closes apache#5988 from Emor-nj/kyuubi-beeline.

Closes apache#5987

3a988e0 [Emor-nj] fix KYUUBI_HOME is always empty in load-kyuubi-env.sh
cc70387 [Emor-nj] fix load-kyuubi-env.sh
a101428 [Emor-nj] Remove unnecessary exports.
f48db3f [Emor-nj] uniformly modify all related scripts.
35215b9 [Emor-nj] Modify the logic in the beeline script that specifies the KYUUBI_HOME environment variable.

Authored-by: Emor-nj <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants