[KYUUBI #5900][FOLLOWUP] Get the engine service node to delete instead of delete engine space

# 🔍 Description
## Issue References 🔗

Followup for patch #5901
We shall find the engine node first and then delete it instead of deleting the engine space.
This pull request fixes #

## Describe Your Solution 🔧

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

## 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 ⚰️

#### Behavior With This Pull Request 🎉

#### Related Unit Tests

---

# Checklists
## 📝 Author Self Checklist

- [ ] My code follows the [style guidelines](https://kyuubi.readthedocs.io/en/master/contributing/code/style.html) of this project
- [ ] I have performed a self-review
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)

## 📝 Committer Pre-Merge Checklist

- [ ] Pull request title is okay.
- [ ] No license issues.
- [ ] Milestone correctly set?
- [ ] Test coverage is ok
- [ ] Assignees are selected.
- [ ] Minimum number of approvals
- [ ] No changes are requested

**Be nice. Be informative.**

Closes #5910 from turboFei/deregister_followup.

Closes #5900

f72962903 [Fei Wang] ut
6683d9f55 [Fei Wang] refine
43ad0bfe1 [Fei Wang] save

Authored-by: Fei Wang <fwang12@ebay.com>
Signed-off-by: Fei Wang <fwang12@ebay.com>
This commit is contained in:
Fei Wang 2023-12-23 18:24:10 -08:00
parent 8f59355eb6
commit c290dae2ee
2 changed files with 31 additions and 2 deletions

View File

@ -315,8 +315,16 @@ private[kyuubi] class EngineRef(
*/
def deregister(discoveryClient: DiscoveryClient, hostPort: (String, Int)): Unit =
tryWithLock(discoveryClient) {
if (discoveryClient.getServerHost(engineSpace) == Option(hostPort)) {
discoveryClient.delete(engineSpace)
// refer the DiscoveryClient::getServerHost implementation
discoveryClient.getServiceNodesInfo(engineSpace, Some(1), silent = true) match {
case Seq(sn) =>
if ((sn.host, sn.port) == hostPort) {
info(s"Deleting engine node:$sn")
discoveryClient.delete(s"$engineSpace/${sn.nodeName}")
} else {
warn(s"Engine node:$sn is not matched with host&port[$hostPort]")
}
case _ => warn(s"No engine node found in $engineSpace")
}
}

View File

@ -341,4 +341,25 @@ trait EngineRefTests extends KyuubiFunSuite {
val engine4 = new EngineRef(conf, user, PluginLoader.loadGroupProvider(conf), id, null)
assert(engine4.subdomain.startsWith("engine-pool-"))
}
test("deregister engine with existing host port") {
val id = UUID.randomUUID().toString
conf.set(KyuubiConf.ENGINE_SHARE_LEVEL, USER.toString)
conf.set(KyuubiConf.ENGINE_TYPE, SPARK_SQL.toString)
conf.set(KyuubiConf.FRONTEND_THRIFT_BINARY_BIND_PORT, 0)
conf.set(HighAvailabilityConf.HA_NAMESPACE, "engine_test")
conf.set(HighAvailabilityConf.HA_ADDRESSES, getConnectString())
conf.set(KyuubiConf.GROUP_PROVIDER, "hadoop")
val engine = new EngineRef(conf, user, PluginLoader.loadGroupProvider(conf), id, null)
DiscoveryClientProvider.withDiscoveryClient(conf) { client =>
val hp = engine.getOrCreate(client)
assert(client.getServerHost(engine.engineSpace) == Option(hp))
engine.deregister(client, ("non_existing_host", 0))
assert(client.getServerHost(engine.engineSpace) == Option(hp))
engine.deregister(client, hp)
assert(client.getServerHost(engine.engineSpace).isEmpty)
}
}
}