Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ interface Database {
fun setup(ssh: SshConnection): String

fun start(jira: URI, ssh: SshConnection)

/**
* @return Database type e.g. mysql
*/
fun type(): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import org.apache.logging.log4j.Logger
import java.io.File
import java.net.URI
import java.nio.file.Files
import java.io.FileWriter
import java.io.BufferedWriter


/**
* Removes all licenses from [database] and adds [licenses] instead.
Expand Down Expand Up @@ -80,6 +77,8 @@ class LicenseOverridingMysql private constructor(
)
}
}

override fun type(): String = "mysql"
}

internal fun createTempLicenseFile(license: String): File {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ class MySqlDatabase(
Thread.sleep(Duration.ofSeconds(10).toMillis())
}
}

override fun type(): String = "mysql"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.atlassian.performance.tools.infrastructure.api.database

import com.atlassian.performance.tools.infrastructure.DockerImage
import com.atlassian.performance.tools.infrastructure.api.dataset.DatasetPackage
import com.atlassian.performance.tools.ssh.api.SshConnection
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import java.net.URI
import java.time.Duration

class PostgresDatabase(
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.

If you can avoid the FileArchiver changes, perhaps by inlining some code, then this class wouldn't have to be merged it, but could be used in-place.

private val source: DatasetPackage,
private val maxConnections: Int,
private val dataBaseVersion: String
) : Database {
private val logger: Logger = LogManager.getLogger(this::class.java)

private val image: DockerImage = DockerImage(
name = "postgres:$dataBaseVersion",
pullTimeout = Duration.ofMinutes(5)
)

constructor(
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.

source: DatasetPackage,
dataBaseVersion: String
) : this(
source = source,
maxConnections = 200,
dataBaseVersion = dataBaseVersion
)

override fun setup(ssh: SshConnection): String {
val pgData = source.download(ssh)
image.run(
ssh = ssh,
parameters = "-p 3306:5432 -v `realpath $pgData`:/var/lib/postgresql/data",
arguments = "-c 'listen_addresses='*'' -c 'max_connections=$maxConnections'"
Comment thread
dagguh marked this conversation as resolved.
)
return pgData
}

override fun start(jira: URI, ssh: SshConnection) {
// TODO Check logs for the following entry
// LOG: database system is ready to accept connections
Thread.sleep(Duration.ofSeconds(15).toMillis())
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.

This sleep is suspicious too. How do we resolve the TODO?

  • resolve TODO
  • remove sleep

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sleep is enough here, postgres databases are initialising very quickly, checking logs is something nice to have

}

override fun type(): String = "postgres"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class FileArchiver {
) {
ubuntu.install(connection, listOf("lbzip2"))
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.

We don't have to install lbzip2 in case we're not using it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thanks for pointing this out

time("unzip") {
connection.execute("tar -I lbzip2 -xf $archive", timeout)
val cmd = if (archive.contains("SCALED_ISSUES_UNIMODAL_PG"))
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 this change related to "Postgres support"?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes sir, I keep data sets for PG here - https://s3.console.aws.amazon.com/s3/buckets/jpt-pgdata/?region=eu-central-1&tab=overview
we need to move the archives to the correct S3 bucket (but I do not have rights there, need your help)

"tar -xzvf $archive"
else
"tar -I lbzip2 -xf $archive"
connection.execute(cmd, timeout)
}
}

Expand All @@ -35,7 +39,11 @@ class FileArchiver {
) {
ubuntu.install(connection, listOf("lbzip2"))
time("unzip") {
connection.execute("tar -I lbzip2 -xf $archive -C $destination", timeout).output.splitToSequence("\n").asIterable()
val cmd = if (archive.contains("SCALED_ISSUES_UNIMODAL_PG"))
"tar -xzvf $archive -C $destination"
else
"tar -I lbzip2 -xf $archive -C $destination"
connection.execute(cmd, timeout).output.splitToSequence("\n").asIterable()
}
}

Expand Down