Skip to content

Commit

Permalink
Minor update to lock mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Jan 7, 2025
1 parent bcccc40 commit e1aaa02
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 153 deletions.
4 changes: 2 additions & 2 deletions benchmark/src/main/scala/benchmark/bench/Bench.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package benchmark.bench

import benchmark.ActionIterator
import lightdb.Unique
import rapid.Unique

import java.sql.ResultSet
import scala.collection.parallel.CollectionConverters._
Expand Down Expand Up @@ -33,7 +33,7 @@ trait Bench {

private def insertRecordsTask(status: StatusCallback): Int = {
val iterator = ActionIterator(
(0 until RecordCount).iterator.map(index => P(Unique(), index, s"id$index")),
(0 until RecordCount).iterator.map(index => P(Unique().sync(), index, s"id$index")),
b => if (b) status.progress()
)
insertRecords(iterator)
Expand Down
1 change: 0 additions & 1 deletion benchmark/src/main/scala/benchmark/bench/Runner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ object Runner {
"LightDB-RocksDB-Lucene" -> LightDBBench(SplitStoreManager(RocksDBStore, LuceneStore)),
"LightDB-H2" -> LightDBBench(H2Store),
"LightDB-HaloDB-H2" -> LightDBBench(SplitStoreManager(HaloDBStore, H2Store)),
"LightDB-Async-HaloDB-Lucene" -> LightDBAsyncBench(SplitStoreManager(HaloDBStore, LuceneStore)),
// "LightDB-PostgreSQL" -> LightDBBench(PostgreSQLStoreManager(HikariConnectionManager(SQLConfig(
// jdbcUrl = s"jdbc:postgresql://localhost:5432/basic",
// username = Some("postgres"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package benchmark.bench.impl

import benchmark.bench.Bench
import lightdb.Unique
import rapid.Unique

import java.io.File
import java.sql.{Connection, DriverManager}
Expand Down Expand Up @@ -106,5 +106,5 @@ object DerbyBench extends Bench {
}
}

case class Person(name: String, age: Int, id: String = Unique())
case class Person(name: String, age: Int, id: String = Unique().sync())
}
4 changes: 2 additions & 2 deletions benchmark/src/main/scala/benchmark/bench/impl/H2Bench.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package benchmark.bench.impl

import benchmark.bench.Bench
import lightdb.Unique
import rapid.Unique

import java.io.File
import java.sql.{Connection, DriverManager}
Expand Down Expand Up @@ -95,5 +95,5 @@ object H2Bench extends Bench {
}
}

case class Person(name: String, age: Int, id: String = Unique())
case class Person(name: String, age: Int, id: String = Unique().sync())
}

This file was deleted.

30 changes: 17 additions & 13 deletions benchmark/src/main/scala/benchmark/bench/impl/LightDBBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import lightdb.sql.SQLConversion
import lightdb.store.StoreManager
import lightdb.upgrade.DatabaseUpgrade
import lightdb.{Id, LightDB}
import rapid.Task

import java.nio.file.Path
import java.sql.ResultSet
Expand All @@ -16,25 +17,25 @@ import scala.language.implicitConversions
case class LightDBBench(storeManager: StoreManager) extends Bench { bench =>
override def name: String = s"LightDB ${storeManager.name}"

override def init(): Unit = db.init
override def init(): Unit = DB.init.sync()

implicit def p2Person(p: P): Person = Person(p.name, p.age, Id(p.id))

def toP(person: Person): P = P(person.name, person.age, person._id.value)

override protected def insertRecords(iterator: Iterator[P]): Unit = DB.people.transaction { implicit transaction =>
iterator.foreach { p =>
val person: Person = p
DB.people.insert(person)
}
}
rapid.Stream.fromIterator(Task(iterator))
.evalMap(p => DB.people.insert(p))
.drain
}.sync()

override protected def streamRecords(f: Iterator[P] => Unit): Unit = DB.people.transaction { implicit transaction =>
f(DB.people.iterator.map(toP))
// f(DB.people.iterator.map(toP))
???
}

override protected def getEachRecord(idIterator: Iterator[String]): Unit = DB.people.transaction { implicit transaction =>
idIterator.foreach { idString =>
/*idIterator.foreach { idString =>
val id = Person.id(idString)
DB.people.get(id) match {
case Some(person) =>
Expand All @@ -43,11 +44,12 @@ case class LightDBBench(storeManager: StoreManager) extends Bench { bench =>
}
case None => scribe.warn(s"$id was not found!")
}
}
}*/
???
}

override protected def searchEachRecord(ageIterator: Iterator[Int]): Unit = DB.people.transaction { implicit transaction =>
ageIterator.foreach { age =>
/*ageIterator.foreach { age =>
try {
val list = DB.people.query.filter(_.age === age).search.docs.list
val person = list.head
Expand All @@ -60,12 +62,14 @@ case class LightDBBench(storeManager: StoreManager) extends Bench { bench =>
} catch {
case t: Throwable => throw new RuntimeException(s"Error with $age", t)
}
}
}*/
???
}

override protected def searchAllRecords(f: Iterator[P] => Unit): Unit = DB.people.transaction { implicit transaction =>
val iterator = DB.people.query.search.docs.iterator.map(toP)
f(iterator)
// val iterator = DB.people.query.search.docs.iterator.map(toP)
// f(iterator)
???
}

override def size(): Long = -1L
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package benchmark.bench.impl

import benchmark.bench.Bench
import lightdb.Unique
import rapid.Unique

import java.sql.{Connection, DriverManager}

Expand Down Expand Up @@ -93,5 +93,5 @@ object PostgreSQLBench extends Bench {
}
}

case class Person(name: String, age: Int, id: String = Unique())
case class Person(name: String, age: Int, id: String = Unique().sync())
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package benchmark.bench.impl

import benchmark.bench.Bench
import lightdb.Unique
import rapid.Unique

import java.io.File
import java.sql.{Connection, DriverManager}
Expand Down Expand Up @@ -94,5 +94,5 @@ object SQLiteBench extends Bench {
}
}

case class Person(name: String, age: Int, id: String = Unique())
case class Person(name: String, age: Int, id: String = Unique().sync())
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object MariaDBImplementation extends BenchmarkImplementation {
}

override def map2TitleAka(map: Map[String, String]): TitleAka = TitleAkaPG(
id = map.option("id").getOrElse(lightdb.Unique()),
id = map.option("id").getOrElse(rapid.Unique().sync()),
titleId = map.value("titleId"),
ordering = map.int("ordering"),
title = map.value("title"),
Expand All @@ -88,7 +88,7 @@ object MariaDBImplementation extends BenchmarkImplementation {
)

override def map2TitleBasics(map: Map[String, String]): TitleBasicsPG = TitleBasicsPG(
id = map.option("id").getOrElse(lightdb.Unique()),
id = map.option("id").getOrElse(rapid.Unique().sync()),
tconst = map.value("tconst"),
titleType = map.value("titleType"),
primaryTitle = map.value("primaryTitle"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import benchmark.FlushingBacklog
import cats.effect.unsafe.IORuntime
import com.mongodb.client.MongoClients
import com.mongodb.client.model.Indexes
import lightdb.Unique
import org.bson.Document
import rapid.Task
import rapid.{Task, Unique}

import java.{lang, util}
import scala.jdk.CollectionConverters._
Expand All @@ -26,7 +25,7 @@ object MongoDBImplementation extends BenchmarkImplementation {

override def map2TitleAka(map: Map[String, String]): Document = {
new Document(Map[String, AnyRef](
"_id" -> Unique(),
"_id" -> Unique().sync(),
"titleId" -> map.value("titleId"),
"ordering" -> Integer.valueOf(map.int("ordering")),
"title" -> map.value("title"),
Expand All @@ -40,7 +39,7 @@ object MongoDBImplementation extends BenchmarkImplementation {

override def map2TitleBasics(map: Map[String, String]): Document = {
new Document(Map[String, AnyRef](
"_id" -> Unique(),
"_id" -> Unique().sync(),
"tconst" -> map.value("tconst"),
"titleType" -> map.value("titleType"),
"primaryTitle" -> map.value("primaryTitle"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object PostgresImplementation extends BenchmarkImplementation {
}

override def map2TitleAka(map: Map[String, String]): TitleAka = TitleAkaPG(
id = map.option("id").getOrElse(lightdb.Unique()),
id = map.option("id").getOrElse(rapid.Unique().sync()),
titleId = map.value("titleId"),
ordering = map.int("ordering"),
title = map.value("title"),
Expand All @@ -88,7 +88,7 @@ object PostgresImplementation extends BenchmarkImplementation {
)

override def map2TitleBasics(map: Map[String, String]): TitleBasicsPG = TitleBasicsPG(
id = map.option("id").getOrElse(lightdb.Unique()),
id = map.option("id").getOrElse(rapid.Unique().sync()),
tconst = map.value("tconst"),
titleType = map.value("titleType"),
primaryTitle = map.value("primaryTitle"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package benchmark.imdb

import benchmark.FlushingBacklog
import cats.effect.unsafe.IORuntime
import lightdb.Unique
import rapid.Task
import rapid.{Task, Unique}

import java.sql.{Connection, DriverManager, ResultSet}

Expand Down Expand Up @@ -77,7 +76,7 @@ object SQLiteImplementation extends BenchmarkImplementation {
}

override def map2TitleAka(map: Map[String, String]): TitleAka = TitleAkaPG(
id = map.option("id").getOrElse(Unique()),
id = map.option("id").getOrElse(Unique().sync()),
titleId = map.value("titleId"),
ordering = map.int("ordering"),
title = map.value("title"),
Expand All @@ -89,7 +88,7 @@ object SQLiteImplementation extends BenchmarkImplementation {
)

override def map2TitleBasics(map: Map[String, String]): TitleBasicsPG = TitleBasicsPG(
id = map.option("id").getOrElse(Unique()),
id = map.option("id").getOrElse(Unique().sync()),
tconst = map.value("tconst"),
titleType = map.value("titleType"),
primaryTitle = map.value("primaryTitle"),
Expand Down
Loading

0 comments on commit e1aaa02

Please sign in to comment.