Skip to content

Commit

Permalink
[query] Lift backend state into {Service|Py4J}BackendApi
Browse files Browse the repository at this point in the history
  • Loading branch information
ehigham committed Sep 20, 2024
1 parent 16d54bd commit 33a991e
Show file tree
Hide file tree
Showing 56 changed files with 1,256 additions and 1,411 deletions.
1 change: 0 additions & 1 deletion hail/python/hail/backend/local_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def __init__(
hail_package = getattr(self._gateway.jvm, 'is').hail

jbackend = hail_package.backend.local.LocalBackend.apply(
tmpdir,
log,
True,
append,
Expand Down
20 changes: 13 additions & 7 deletions hail/python/hail/backend/py4j_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,15 @@ def parse(node):

class Py4JBackend(Backend):
@abc.abstractmethod
def __init__(self, jvm: JVMView, jbackend: JavaObject, jhc: JavaObject):
super(Py4JBackend, self).__init__()
def __init__(
self,
jvm: JVMView,
jbackend: JavaObject,
jhc: JavaObject,
tmpdir: str,
remote_tmpdir: str,
):
super().__init__()
import base64

def decode_bytearray(encoded):
Expand All @@ -184,12 +191,11 @@ def decode_bytearray(encoded):
self._jvm = jvm
self._hail_package = getattr(self._jvm, 'is').hail
self._utils_package_object = scala_package_object(self._hail_package.utils)
self._jbackend = jbackend
self._jhc = jhc

self._backend_server = self._hail_package.backend.BackendServer(self._jbackend)
self._backend_server_port: int = self._backend_server.port()
self._backend_server.start()
self._jbackend = self._hail_package.backend.api.P4jBackendApi(jbackend)
self._jhttp_server = self._jbackend.pyHttpServer()
self._backend_server_port: int = self._jbackend.HttpServer.port()
self._requests_session = requests.Session()

# This has to go after creating the SparkSession. Unclear why.
Expand Down Expand Up @@ -289,7 +295,7 @@ def _to_java_blockmatrix_ir(self, ir):
return self._parse_blockmatrix_ir(self._render_ir(ir))

def stop(self):
self._backend_server.close()
self._jhttp_server.close()
self._jbackend.close()
self._jhc.stop()
self._jhc = None
Expand Down
6 changes: 3 additions & 3 deletions hail/src/main/scala/is/hail/backend/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import is.hail.io.fs.FS
import is.hail.types.RTable
import is.hail.types.encoded.EType
import is.hail.types.physical.PTuple
import is.hail.utils.ExecutionTimer.Timings
import is.hail.utils.fatal

import scala.reflect.ClassTag
Expand Down Expand Up @@ -54,6 +53,7 @@ trait BackendContext {
}

abstract class Backend extends Closeable {

// From https://github.com/hail-is/hail/issues/14580 :
// IR can get quite big, especially as it can contain an arbitrary
// amount of encoded literals from the user's python session. This
Expand Down Expand Up @@ -119,7 +119,7 @@ abstract class Backend extends Closeable {
def tableToTableStage(ctx: ExecuteContext, inputIR: TableIR, analyses: LoweringAnalyses)
: TableStage

def withExecuteContext[T](f: ExecuteContext => T)(implicit E: Enclosing): (T, Timings)

def execute(ctx: ExecuteContext, ir: IR): Either[Unit, (PTuple, Long)]

def backendContext(ctx: ExecuteContext): BackendContext
}
4 changes: 0 additions & 4 deletions hail/src/main/scala/is/hail/backend/BackendRpc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,4 @@ trait HttpLikeBackendRpc[A] extends BackendRpc {
)
}
}

implicit protected def Ask: Routing
implicit protected def Write: Write[A]
implicit protected def Context: Context[A]
}
123 changes: 0 additions & 123 deletions hail/src/main/scala/is/hail/backend/BackendServer.scala

This file was deleted.

12 changes: 1 addition & 11 deletions hail/src/main/scala/is/hail/backend/ExecuteContext.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package is.hail.backend

import is.hail.{HailContext, HailFeatureFlags}
import is.hail.HailFeatureFlags
import is.hail.annotations.{Region, RegionPool}
import is.hail.asm4s.HailClassLoader
import is.hail.backend.local.LocalTaskContext
Expand Down Expand Up @@ -55,11 +55,6 @@ object NonOwningTempFileManager {
}

object ExecuteContext {
def scoped[T](f: ExecuteContext => T)(implicit E: Enclosing): T =
HailContext.sparkBackend.withExecuteContext(
selfContainedExecution = false
)(f)

def scoped[T](
tmpdir: String,
localTmpdir: String,
Expand All @@ -69,7 +64,6 @@ object ExecuteContext {
tempFileManager: TempFileManager,
theHailClassLoader: HailClassLoader,
flags: HailFeatureFlags,
backendContext: BackendContext,
irMetadata: IrMetadata,
references: mutable.Map[String, ReferenceGenome],
blockMatrixCache: mutable.Map[String, BlockMatrix],
Expand All @@ -91,7 +85,6 @@ object ExecuteContext {
tempFileManager,
theHailClassLoader,
flags,
backendContext,
irMetadata,
references,
blockMatrixCache,
Expand Down Expand Up @@ -124,7 +117,6 @@ class ExecuteContext(
_tempFileManager: TempFileManager,
val theHailClassLoader: HailClassLoader,
val flags: HailFeatureFlags,
val backendContext: BackendContext,
var irMetadata: IrMetadata,
val References: mutable.Map[String, ReferenceGenome],
val BlockMatrixCache: mutable.Map[String, BlockMatrix],
Expand Down Expand Up @@ -197,7 +189,6 @@ class ExecuteContext(
tempFileManager: TempFileManager = NonOwningTempFileManager(this.tempFileManager),
theHailClassLoader: HailClassLoader = this.theHailClassLoader,
flags: HailFeatureFlags = this.flags,
backendContext: BackendContext = this.backendContext,
references: mutable.Map[String, ReferenceGenome] = this.References,
irMetadata: IrMetadata = this.irMetadata,
blockMatrixCache: mutable.Map[String, BlockMatrix] = this.BlockMatrixCache,
Expand All @@ -217,7 +208,6 @@ class ExecuteContext(
tempFileManager,
theHailClassLoader,
flags,
backendContext,
irMetadata,
references,
blockMatrixCache,
Expand Down
Loading

0 comments on commit 33a991e

Please sign in to comment.