Skip to content

[LIVY-239] Generate session IDs in SessionStore, not in SessionManager#103

Open
meisam wants to merge 7 commits into
apache:masterfrom
meisam:LIVY-239
Open

[LIVY-239] Generate session IDs in SessionStore, not in SessionManager#103
meisam wants to merge 7 commits into
apache:masterfrom
meisam:LIVY-239

Conversation

@meisam

@meisam meisam commented Jul 17, 2018

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Move the logic to create session IDs from SessionManager to SessionStore

Why this change is needed?

Generating session IDs at session stores that they are unique across all Livy instances that connect to a session store. Right now only one Livy instance connects to the session store, but to implement multimode HA, generating session IDs in session store prevents inconsistent/colliding values.

How was this patch tested?

  • Unit tests are added.
  • This patch is working in production at PayPal for about a year now.

JIRA ticket: https://issues.apache.org/jira/browse/LIVY-239

@meisam

meisam commented Jul 17, 2018

Copy link
Copy Markdown
Contributor Author
sudo -E apt-get ...

failed on one of the travis instances. Closing this PR and opening it again to rebuild.

@meisam meisam closed this Jul 17, 2018
@meisam meisam reopened this Jul 17, 2018
@meisam meisam closed this Jul 17, 2018
@meisam meisam reopened this Jul 17, 2018
@meisam meisam closed this Jul 17, 2018
@meisam meisam reopened this Jul 17, 2018
@codecov-io

codecov-io commented Jul 17, 2018

Copy link
Copy Markdown

Codecov Report

Merging #103 into master will decrease coverage by 0.11%.
The diff coverage is 61.53%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #103      +/-   ##
============================================
- Coverage     68.79%   68.67%   -0.12%     
  Complexity      905      905              
============================================
  Files           100      100              
  Lines          5650     5651       +1     
  Branches        846      845       -1     
============================================
- Hits           3887     3881       -6     
- Misses         1211     1219       +8     
+ Partials        552      551       -1
Impacted Files Coverage Δ Complexity Δ
...a/org/apache/livy/server/recovery/StateStore.scala 83.33% <ø> (ø) 1 <0> (ø) ⬇️
...che/livy/server/recovery/ZooKeeperStateStore.scala 70.83% <0%> (-8.24%) 17 <0> (ø)
...he/livy/server/recovery/FileSystemStateStore.scala 65.3% <100%> (+2.26%) 12 <1> (+1) ⬆️
...org/apache/livy/server/recovery/SessionStore.scala 82.35% <100%> (+2.35%) 9 <2> (-1) ⬇️
...che/livy/server/recovery/BlackholeStateStore.scala 100% <100%> (ø) 7 <2> (+2) ⬆️
...cala/org/apache/livy/sessions/SessionManager.scala 81.92% <100%> (-0.1%) 23 <1> (-1)
...cala/org/apache/livy/scalaapi/ScalaJobHandle.scala 52.94% <0%> (-2.95%) 7% <0%> (ø)
...c/main/scala/org/apache/livy/repl/ReplDriver.scala 30.76% <0%> (-2.57%) 7% <0%> (ø)
...c/src/main/java/org/apache/livy/rsc/RSCClient.java 73.91% <0%> (-1.25%) 20% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80daade...3baf264. Read the comment docs.

@vanzin vanzin left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks reasonable from what I remember of this code.

*
* @return incremented value
*/
def increment(key: String): Long

@vanzin vanzin Aug 22, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This method name is weird, since you're not incrementing the StateStore itself... maybe nextValue instead (or nextSessionId to follow the name in other parts of the code).

@meisam meisam Jan 23, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How about incrementAndGet() to emphasize two things:

  • It is an atomic operation.
  • It is not solely for generating session IDs.

My second choice is nextValue. But nextSessionId is a high level operation. It is not a good fit for StateStore whose other operations are get, set, remove, and getChildren.

Comment thread server/src/main/scala/org/apache/livy/server/recovery/SessionStore.scala Outdated
@alex-the-man

Copy link
Copy Markdown
Contributor

Can we add some migration code so user can seamlessly upgrade from older Livy? Thanks!

@meisam

meisam commented Feb 8, 2019

Copy link
Copy Markdown
Contributor Author

Can we add some migration code so user can seamlessly upgrade from older Livy? Thanks!

Should the migration code be part of Livy? Or should be a separate script that users run once?

Also should we change the version in zookeeper path from /v1/... to /v2/...?

@alex-the-man

alex-the-man commented Feb 14, 2019

Copy link
Copy Markdown
Contributor

Can we add some migration code so user can seamlessly upgrade from older Livy? Thanks!

Should the migration code be part of Livy? Or should be a separate script that users run once?

In this case it seems simple enough to be a part of the startup code.

Also should we change the version in zookeeper path from /v1/... to /v2/...?

I think you are right, we should.

*/
class BlackholeStateStore(livyConf: LivyConf) extends StateStore(livyConf) {

private val atomicLong: AtomicLong = new AtomicLong(-1L)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like this cannot guarantee the global uniqueness across many Livy services, right? As the atomicLong cannot be shared by processes.

private def absPath(key: String): Path = new Path(fsUri.getPath(), key)

override def nextValue(key: String): Long = synchronized {
val incrementedValue = 1 + get[Long](key).getOrElse(-1L)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the get or set method atomic?

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has had no activity for at least 3 months. If you are still working on this change or plan to move it forward, please leave a comment or push a new commit so we know to keep it open. Otherwise, this PR will be closed automatically in about one month. Thank you for your contribution to Apache Livy!

@github-actions github-actions Bot added the stale label Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants