Updates and fixes for the cloud (#1817)

This commit is contained in:
Dmitry Bushev 2021-07-09 16:41:50 +03:00 committed by GitHub
parent 8a79e1e033
commit 3591e1b5c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 65 additions and 83 deletions

View File

@ -2,6 +2,7 @@ package org.enso.languageserver.boot
import java.io.File
import java.net.URI
import akka.actor.ActorSystem
import org.enso.jsonrpc.JsonRpcServer
import org.enso.languageserver.boot.DeploymentType.{Azure, Desktop}
@ -38,7 +39,6 @@ import org.enso.languageserver.util.binary.BinaryEncoder
import org.enso.loggingservice.{JavaLoggingLogHandler, LogLevel}
import org.enso.polyglot.{RuntimeOptions, RuntimeServerInfo}
import org.enso.searcher.sql.{SqlDatabase, SqlSuggestionsRepo, SqlVersionsRepo}
import org.enso.searcher.sqlite.LockingMode
import org.enso.text.{ContentBasedVersioning, Sha3_224VersionCalculator}
import org.graalvm.polyglot.Context
import org.graalvm.polyglot.io.MessageEndpoint
@ -96,15 +96,9 @@ class MainModule(serverConfig: LanguageServerConfig, logLevel: LogLevel) {
val sqlDatabase =
DeploymentType.fromEnvironment() match {
case Desktop =>
SqlDatabase(
languageServerConfig.directories.suggestionsDatabaseFile.toString
)
SqlDatabase(languageServerConfig.directories.suggestionsDatabaseFile)
case Azure =>
SqlDatabase(
languageServerConfig.directories.suggestionsDatabaseFile.toString,
Some(LockingMode.UnixFlock)
)
SqlDatabase.inmem("memdb")
}
val suggestionsRepo = new SqlSuggestionsRepo(sqlDatabase)(system.dispatcher)

View File

@ -1,5 +1,7 @@
package org.enso.languageserver.search
import java.util.UUID
import akka.actor.{Actor, ActorRef, Props, Stash}
import akka.pattern.{ask, pipe}
import com.typesafe.scalalogging.LazyLogging
@ -40,7 +42,6 @@ import org.enso.searcher.{FileVersionsRepo, SuggestionsRepo}
import org.enso.text.ContentVersion
import org.enso.text.editing.model.Position
import java.util.UUID
import scala.concurrent.Future
import scala.util.{Failure, Success}
@ -116,10 +117,6 @@ final class SuggestionsHandler(
.subscribe(self, InitializedEvent.SuggestionsRepoInitialized.getClass)
context.system.eventStream
.subscribe(self, InitializedEvent.TruffleContextInitialized.getClass)
PackageManager.Default
.fromDirectory(config.projectContentRoot.file)
.foreach(pkg => self ! ProjectNameUpdated(pkg.config.name))
}
override def receive: Receive =
@ -152,6 +149,18 @@ final class SuggestionsHandler(
case InitializedEvent.TruffleContextInitialized =>
logger.info("Initializing: Truffle context initialized.")
PackageManager.Default
.loadPackage(config.projectContentRoot.file)
.fold(
t =>
logger.error(
"Failed to read the package definition from [{}]. {} {}",
MaskedPath(config.projectContentRoot.file.toPath),
t.getClass.getName,
t.getMessage
),
pkg => self ! ProjectNameUpdated(pkg.config.name)
)
val requestId = UUID.randomUUID()
runtimeConnector
.ask(Api.Request(requestId, Api.GetTypeGraphRequest()))(timeout, self)

View File

@ -230,9 +230,7 @@ class RepoInitializationSpec
def withRepos(
config: Config
)(test: (SqlSuggestionsRepo, SqlVersionsRepo) => Any): Unit = {
val sqlDatabase = SqlDatabase(
config.directories.suggestionsDatabaseFile.toString
)
val sqlDatabase = SqlDatabase(config.directories.suggestionsDatabaseFile)
val suggestionsRepo = new SqlSuggestionsRepo(sqlDatabase)
val versionsRepo = new SqlVersionsRepo(sqlDatabase)

View File

@ -21,7 +21,7 @@ import org.enso.languageserver.session.SessionRouter.{
}
import org.enso.polyglot.runtime.Runtime.Api
import org.enso.searcher.SuggestionsRepo
import org.enso.searcher.sql.SqlSuggestionsRepo
import org.enso.searcher.sql.{SqlDatabase, SqlSuggestionsRepo}
import org.enso.testkit.RetrySpec
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.should.Matchers
@ -482,7 +482,9 @@ class ContextEventsListenerSpec
val contextId = UUID.randomUUID()
val router = TestProbe("session-router")
val contextRegistry = TestProbe("context-registry")
val repo = SqlSuggestionsRepo(config.directories.suggestionsDatabaseFile)
val db = SqlDatabase(config.directories.suggestionsDatabaseFile)
val repo = new SqlSuggestionsRepo(db)
val contentRootManagerActor =
system.actorOf(ContentRootManagerActor.props(config))
val contentRootManagerWrapper: ContentRootManager =

View File

@ -838,9 +838,7 @@ class SuggestionsHandlerSpec
)
val router = TestProbe("session-router")
val connector = TestProbe("runtime-connector")
val sqlDatabase = SqlDatabase(
config.directories.suggestionsDatabaseFile.toString
)
val sqlDatabase = SqlDatabase( config.directories.suggestionsDatabaseFile)
val suggestionsRepo = new SqlSuggestionsRepo(sqlDatabase)
val versionsRepo = new SqlVersionsRepo(sqlDatabase)

View File

@ -102,9 +102,8 @@ class BaseServerTest
InputRedirectionController.props(stdIn, stdInSink, sessionRouter)
)
val zioExec = ZioExec(zio.Runtime.default)
val sqlDatabase =
SqlDatabase(config.directories.suggestionsDatabaseFile.toString)
val zioExec = ZioExec(zio.Runtime.default)
val sqlDatabase = SqlDatabase(config.directories.suggestionsDatabaseFile)
val suggestionsRepo = new SqlSuggestionsRepo(sqlDatabase)(system.dispatcher)
val versionsRepo = new SqlVersionsRepo(sqlDatabase)(system.dispatcher)

View File

@ -1,5 +1,11 @@
package org.enso.languageserver.websocket.json
import java.io.File
import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.{Files, Paths}
import java.security.MessageDigest
import java.util.UUID
import io.circe.literal._
import io.circe.parser.parse
import org.apache.commons.io.FileUtils
@ -8,11 +14,6 @@ import org.enso.languageserver.data._
import org.enso.polyglot.runtime.Runtime.Api
import org.enso.testkit.RetrySpec
import java.io.File
import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.{Files, Paths}
import java.security.MessageDigest
import java.util.UUID
import scala.concurrent.duration._
class FileManagerTest extends BaseServerTest with RetrySpec {
@ -1808,7 +1809,7 @@ class FileManagerTest extends BaseServerTest with RetrySpec {
}
def withCleanRoot[T](test: => T): T = {
FileUtils.cleanDirectory(testContentRoot.file)
FileUtils.deleteQuietly(testContentRoot.file)
test
}
}

View File

@ -1,6 +1,5 @@
package org.enso.searcher.sql;
import java.util.ArrayList;
import org.enso.polyglot.Suggestion;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
@ -11,16 +10,16 @@ import scala.collection.immutable.Seq;
import scala.concurrent.Await;
import scala.concurrent.ExecutionContext;
import scala.concurrent.duration.Duration;
import scala.jdk.CollectionConverters;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;
import scala.jdk.CollectionConverters;
@BenchmarkMode(Mode.AverageTime)
@Fork(1)
@Warmup(iterations = 5)
@ -42,7 +41,9 @@ public class SuggestionsRepoBenchmark {
@Setup
public void setup() throws TimeoutException, InterruptedException {
repo = SqlSuggestionsRepo.apply(dbfile.toFile(), ExecutionContext.global());
repo =
new SqlSuggestionsRepo(
SqlDatabase.apply(dbfile.toFile(), none()), ExecutionContext.global());
if (Files.notExists(dbfile)) {
System.out.println("initializing " + dbfile.toString() + " ...");
Await.ready(repo.init(), TIMEOUT);

View File

@ -3,6 +3,7 @@ searcher {
url = "jdbc:sqlite::memory:"
driver = "org.sqlite.JDBC"
connectionPool = disabled
keepAliveConnection = true
properties.journal_mode = "memory"
properties.locking_mode = "EXCLUSIVE"
numThreads = 1

View File

@ -1,5 +1,7 @@
package org.enso.searcher.sql
import java.io.File
import com.typesafe.config.{Config, ConfigFactory}
import org.enso.searcher.Database
import org.enso.searcher.sqlite.LockingMode
@ -42,23 +44,41 @@ object SqlDatabase {
private val configPath: String =
"searcher.db"
/** Create in-memory [[SqlDatabase]] instance.
*
* @return new sql database instance
*/
def inmem(name: String): SqlDatabase =
fromUrl(inmemUrl(name))
/** Create [[SqlDatabase]] instance.
*
* @param filename the database file path
* @param maybeLockingMode the locking mode
* @return new sql database instance
*/
def apply(
filename: String,
filename: File,
maybeLockingMode: Option[LockingMode] = None
): SqlDatabase = {
): SqlDatabase =
fromUrl(jdbcUrl(filename.toString, maybeLockingMode))
/** Create [[SqlDatabase]] instance.
*
* @param url the database url
* @return new sql database instance
*/
def fromUrl(url: String): SqlDatabase = {
val config = ConfigFactory
.parseString(
s"""$configPath.url = "${jdbcUrl(filename, maybeLockingMode)}""""
)
.parseString(s"""$configPath.url = "$url"""")
.withFallback(ConfigFactory.load())
new SqlDatabase(Some(config))
}
/** Create JDBC URL for in-memory database. */
private def inmemUrl(name: String): String =
s"jdbc:sqlite:file:$name?mode=memory&cache=shared"
/** Create JDBC URL from the file path. */
private def jdbcUrl(
filename: String,

View File

@ -1,6 +1,5 @@
package org.enso.searcher.sql
import java.io.File
import java.util.UUID
import org.enso.polyglot.Suggestion
@ -1101,23 +1100,3 @@ final class SqlSuggestionsRepo(val db: SqlDatabase)(implicit
m <- most
} yield new UUID(m, l)
}
object SqlSuggestionsRepo {
/** Create the suggestions repo.
*
* @return the suggestions repo backed up by SQL database.
*/
def apply()(implicit ec: ExecutionContext): SqlSuggestionsRepo = {
new SqlSuggestionsRepo(new SqlDatabase())
}
/** Create the suggestions repo.
*
* @param path the path to the database file.
* @return the suggestions repo backed up by SQL database.
*/
def apply(path: File)(implicit ec: ExecutionContext): SqlSuggestionsRepo = {
new SqlSuggestionsRepo(SqlDatabase(path.toString))
}
}

View File

@ -143,23 +143,3 @@ final class SqlVersionsRepo(db: SqlDatabase)(implicit ec: ExecutionContext)
util.Arrays.equals(v1, v2)
}
object SqlVersionsRepo {
/** Create the in-memory file versions repo.
*
* @return the versions repo backed up by SQL database
*/
def apply()(implicit ec: ExecutionContext): SqlVersionsRepo = {
new SqlVersionsRepo(new SqlDatabase())
}
/** Create the file versions repo.
*
* @param path the path to the database file
* @return the file versions repo backed up by SQL database
*/
def apply(path: File)(implicit ec: ExecutionContext): SqlVersionsRepo = {
new SqlVersionsRepo(SqlDatabase(path.toString))
}
}

View File

@ -30,7 +30,7 @@ class FileVersionsRepoTest extends AnyWordSpec with Matchers with RetrySpec {
def withRepo(test: SqlVersionsRepo => Any): Any = {
val tmpdb = Files.createTempFile(tmpdir, "versions-repo", ".db")
val repo = SqlVersionsRepo(tmpdb.toFile)
val repo = new SqlVersionsRepo(SqlDatabase(tmpdb.toFile))
Await.ready(repo.init, Timeout)
try test(repo)
finally {

View File

@ -30,7 +30,7 @@ class SuggestionsRepoTest extends AnyWordSpec with Matchers with RetrySpec {
def withRepo(test: SqlSuggestionsRepo => Any): Any = {
val tmpdb = Files.createTempFile(tmpdir, "suggestions-repo", ".db")
val repo = SqlSuggestionsRepo(tmpdb.toFile)
val repo = new SqlSuggestionsRepo(SqlDatabase(tmpdb.toFile))
Await.ready(repo.init, Timeout)
try test(repo)
finally {