Fixes
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import org.gradle.model.internal.core.ModelNodes.withType
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "2.0.0-RC2"
|
||||
id("maven-publish")
|
||||
@@ -17,6 +19,9 @@ dependencies {
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
|
||||
minHeapSize = "128m"
|
||||
maxHeapSize = "1g"
|
||||
}
|
||||
|
||||
extra["PUBLISH_GROUP_ID"] = group
|
||||
|
||||
@@ -201,6 +201,7 @@ class Datastore(
|
||||
return typeData.data.values
|
||||
.filter { search(it as T) }
|
||||
.map { o -> o.copy() as T }
|
||||
.sortedBy { it.id }
|
||||
}
|
||||
|
||||
fun findIndex(
|
||||
@@ -230,20 +231,21 @@ class Datastore(
|
||||
|
||||
private fun writeTransaction(actions: Set<Action>) {
|
||||
val number = transactionFormatter.format(nextTransactionNumber)
|
||||
val file = File(directory, "transaction-$number.trn")
|
||||
val file = File(directory, "transaction-$number.trn-tmp")
|
||||
ObjectOutputStream(file.outputStream()).use { oos ->
|
||||
// version number
|
||||
oos.writeInt(1)
|
||||
oos.writeLong(nextTransactionNumber++)
|
||||
oos.writeObject(actions)
|
||||
}
|
||||
file.renameTo(File(directory, "transaction-$number.trn"))
|
||||
}
|
||||
|
||||
fun snapshot() {
|
||||
val start = System.nanoTime()
|
||||
synchronized(this) {
|
||||
val number = transactionFormatter.format(nextTransactionNumber)
|
||||
val file = File(directory, "transaction-$number.snp")
|
||||
val file = File(directory, "transaction-$number.snp-tmp")
|
||||
ObjectOutputStream(file.outputStream()).use { oos ->
|
||||
// version number
|
||||
oos.writeInt(1)
|
||||
@@ -259,6 +261,7 @@ class Datastore(
|
||||
}
|
||||
}
|
||||
}
|
||||
file.renameTo(File(directory, "transaction-$number.snp"))
|
||||
}
|
||||
Logger.debug("Snapshot in %6.3fms", ((System.nanoTime() - start) / 1_000_000f))
|
||||
}
|
||||
|
||||
@@ -4,49 +4,51 @@ import java.io.File
|
||||
import java.io.ObjectInputStream
|
||||
|
||||
class TransactionLog(
|
||||
val directory: File,
|
||||
directory: File,
|
||||
) {
|
||||
val fileManager = FileManager(directory)
|
||||
|
||||
fun showTransactions() {
|
||||
fun showTransactions(printer: (String) -> Unit = ::println) {
|
||||
fileManager.findLastSnapshot().let { (after, snapshot) ->
|
||||
println("Last snapshot: $snapshot")
|
||||
printer("Last snapshot: $snapshot")
|
||||
|
||||
println("Snapshot:")
|
||||
printer("Snapshot:")
|
||||
snapshot?.inputStream()?.use { input ->
|
||||
ObjectInputStream(input).use { ois ->
|
||||
val versionNumber = ois.readInt()
|
||||
check(versionNumber == 1) { "Unsupported version number: $versionNumber" }
|
||||
check(versionNumber == 1) {
|
||||
"Unsupported version number: $versionNumber"
|
||||
}
|
||||
val transactionNumber = ois.readLong()
|
||||
println("[$versionNumber] $transactionNumber")
|
||||
printer("[$versionNumber] $transactionNumber")
|
||||
val data = ois.readObject() as MutableMap<Class<*>, TypeData>
|
||||
println("Data:")
|
||||
println("\tClasses:")
|
||||
printer("Data:")
|
||||
printer("\tClasses:")
|
||||
for ((cls, entries) in data.entries) {
|
||||
println("\t\t- $cls: ${entries.data.keys.size}")
|
||||
printer("\t\t- $cls: ${entries.data.keys.size}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val transactions = fileManager.findTransactionsAfter(after ?: 0L)
|
||||
|
||||
println("Transactions:")
|
||||
printer("Transactions:")
|
||||
transactions?.forEach { transaction ->
|
||||
transaction.inputStream().use { input ->
|
||||
ObjectInputStream(input).use { ois ->
|
||||
val versionNumber = ois.readInt()
|
||||
check(versionNumber == 1) { "Unsupported version number: $versionNumber" }
|
||||
check(versionNumber == 1) {
|
||||
"Unsupported version number: $versionNumber"
|
||||
}
|
||||
val transactionNumber = ois.readLong()
|
||||
val actions = ois.readObject() as Set<Action>
|
||||
println("\t[$transactionNumber]")
|
||||
printer("\t[$transactionNumber]")
|
||||
for (action in actions) {
|
||||
println("\t\t- $action")
|
||||
printer("\t\t- $action")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import nl.astraeus.persistence.domain.Person
|
||||
import java.io.File
|
||||
import kotlin.random.Random
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class TestThreaded {
|
||||
|
||||
@@ -42,6 +43,7 @@ class TestThreaded {
|
||||
person.name to person.age
|
||||
}
|
||||
},
|
||||
index<Person>("personCompanyId") { p -> (p as? Person)?.company?.id ?: 0L },
|
||||
index<Company>("name") { p -> (p as? Company)?.name ?: "" },
|
||||
)
|
||||
)
|
||||
@@ -68,7 +70,7 @@ class TestThreaded {
|
||||
name = names[random.nextInt(names.size)],
|
||||
age = random.nextInt(0, 100),
|
||||
)
|
||||
//person.company = company
|
||||
person.company = company
|
||||
|
||||
store(person)
|
||||
}
|
||||
@@ -80,6 +82,7 @@ class TestThreaded {
|
||||
Thread(runnable)
|
||||
}
|
||||
|
||||
val start = System.nanoTime()
|
||||
for (thread in threads) {
|
||||
thread.start()
|
||||
}
|
||||
@@ -87,19 +90,29 @@ class TestThreaded {
|
||||
for (thread in threads) {
|
||||
thread.join()
|
||||
}
|
||||
println("Store elapsed time: ${(System.nanoTime() - start) / 1_000_000}ms")
|
||||
}
|
||||
|
||||
pst.query {
|
||||
searchIndex<Person>("nameAndAge") { nameAndAge ->
|
||||
val (name, age) = nameAndAge as Pair<String, Int>
|
||||
|
||||
name.contains("mit") && age > 80
|
||||
}.forEach { p ->
|
||||
println("Found person by name and age: ${p.id}: ${p.name} - ${p.age}")
|
||||
var start = 0L
|
||||
repeat(10) {
|
||||
start = System.nanoTime()
|
||||
val withoutIndex = pst.query {
|
||||
search<Person> { person ->
|
||||
person.age == 20
|
||||
}
|
||||
}
|
||||
println("withoutIndex elapsed time: ${(System.nanoTime() - start) / 1_000_000f}ms")
|
||||
|
||||
start = System.nanoTime()
|
||||
val withIndex = pst.query {
|
||||
searchIndex<Person>("age") { age -> (age as? Int ?: -1) == 20 }
|
||||
}
|
||||
println("withIndex elapsed time: ${(System.nanoTime() - start) / 1_000_000f}ms")
|
||||
|
||||
assertEquals(withIndex.size, withoutIndex.size)
|
||||
}
|
||||
|
||||
//pst.snapshot()
|
||||
pst.snapshot()
|
||||
pst.datastore.printStatus()
|
||||
pst.removeOldFiles()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user