mirror of
https://github.com/facebook/sapling.git
synced 2024-10-04 13:57:13 +03:00
commit cloud: Allow specifying db type
Summary: The commit cloud service needs some extra operations when we execute queries so we're backwards compatible with the existing db. E.g commits are hex encoded in `xdb.commit_cloud`, so when retrieving data we need to be able to decode them to then pass them up the service. Reviewed By: markbt Differential Revision: D56193597 fbshipit-source-id: b45e233a09ab581d6aed7a6193e864fae9faf3f1
This commit is contained in:
parent
4a85f15c83
commit
90dd24a304
@ -37,7 +37,7 @@ impl SqlConstructFromMetadataDatabaseConfig for SqlCommitCloudBuilder {
|
||||
}
|
||||
|
||||
impl SqlCommitCloudBuilder {
|
||||
pub fn new(self) -> SqlCommitCloud {
|
||||
SqlCommitCloud::new(self.connections)
|
||||
pub fn new(self, uses_mysql: bool) -> SqlCommitCloud {
|
||||
SqlCommitCloud::new(self.connections, uses_mysql)
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,21 @@ use sql_ext::SqlConnections;
|
||||
pub struct SqlCommitCloud {
|
||||
#[allow(unused)]
|
||||
pub(crate) connections: SqlConnections,
|
||||
// Commit cloud has three databases in mononoke:
|
||||
// 1. xdb.commit_cloud (prod) This is a mysql db used in prod
|
||||
// 2. sqlite db (test) This is created from sqlite-commit-cloud.sql. Used for unit tests.
|
||||
// 3. mock mysql db (test) This is used in integration tests, it's never queried or populated,
|
||||
/// just there to avoid a clash between "bookmarks" tables
|
||||
#[allow(unused)]
|
||||
uses_mysql: bool,
|
||||
}
|
||||
|
||||
impl SqlCommitCloud {
|
||||
pub fn new(connections: SqlConnections) -> Self {
|
||||
Self { connections }
|
||||
pub fn new(connections: SqlConnections, uses_mysql: bool) -> Self {
|
||||
Self {
|
||||
connections,
|
||||
uses_mysql,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ use sql_construct::SqlConstruct;
|
||||
#[fbinit::test]
|
||||
async fn test_checkout_locations(_fb: FacebookInit) -> anyhow::Result<()> {
|
||||
use commit_cloud::sql::ops::Get;
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new();
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false);
|
||||
let reponame = "test_repo".to_owned();
|
||||
let workspace = "user_testuser_default".to_owned();
|
||||
|
||||
@ -53,7 +53,7 @@ async fn test_snapshots(_fb: FacebookInit) -> anyhow::Result<()> {
|
||||
use commit_cloud::sql::ops::Get;
|
||||
use commit_cloud::sql::snapshots::DeleteArgs;
|
||||
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new();
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false);
|
||||
let reponame = "test_repo".to_owned();
|
||||
let workspace = "user_testuser_default".to_owned();
|
||||
|
||||
@ -94,7 +94,7 @@ async fn test_snapshots(_fb: FacebookInit) -> anyhow::Result<()> {
|
||||
async fn test_heads(_fb: FacebookInit) -> anyhow::Result<()> {
|
||||
use commit_cloud::sql::heads::DeleteArgs;
|
||||
use commit_cloud::sql::ops::Get;
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new();
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false);
|
||||
let reponame = "test_repo".to_owned();
|
||||
let workspace = "user_testuser_default".to_owned();
|
||||
|
||||
@ -135,7 +135,7 @@ async fn test_local_bookmarks(_fb: FacebookInit) -> anyhow::Result<()> {
|
||||
use commit_cloud::sql::local_bookmarks::DeleteArgs;
|
||||
use commit_cloud::sql::ops::Get;
|
||||
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new();
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false);
|
||||
let reponame = "test_repo".to_owned();
|
||||
let workspace = "user_testuser_default".to_owned();
|
||||
|
||||
@ -177,7 +177,7 @@ async fn test_local_bookmarks(_fb: FacebookInit) -> anyhow::Result<()> {
|
||||
async fn test_remote_bookmarks(_fb: FacebookInit) -> anyhow::Result<()> {
|
||||
use commit_cloud::sql::ops::Get;
|
||||
use commit_cloud::sql::remote_bookmarks::DeleteArgs;
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new();
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false);
|
||||
let reponame = "test_repo".to_owned();
|
||||
let workspace = "user_testuser_default".to_owned();
|
||||
|
||||
@ -223,7 +223,7 @@ async fn test_remote_bookmarks(_fb: FacebookInit) -> anyhow::Result<()> {
|
||||
#[fbinit::test]
|
||||
async fn test_versions(_fb: FacebookInit) -> anyhow::Result<()> {
|
||||
use commit_cloud::sql::ops::Get;
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new();
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false);
|
||||
let reponame = "test_repo".to_owned();
|
||||
let workspace = "user_testuser_default".to_owned();
|
||||
|
||||
@ -252,7 +252,7 @@ async fn test_history(_fb: FacebookInit) -> anyhow::Result<()> {
|
||||
use commit_cloud::sql::ops::GenericGet;
|
||||
|
||||
// Create a workspace with heads and bookmarks
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new();
|
||||
let sql = SqlCommitCloudBuilder::with_sqlite_in_memory()?.new(false);
|
||||
let reponame = "test_repo".to_owned();
|
||||
let workspace = "user_testuser_default".to_owned();
|
||||
let timestamp = Timestamp::now();
|
||||
|
@ -1713,7 +1713,10 @@ impl RepoFactory {
|
||||
.await
|
||||
.context(RepoFactoryError::SqlCommitCloud)?;
|
||||
Ok(Arc::new(CommitCloud {
|
||||
storage: sql_commit_cloud.new(),
|
||||
storage: sql_commit_cloud.new(matches!(
|
||||
&repo_config.storage_config.metadata,
|
||||
MetadataDatabaseConfig::Remote(_)
|
||||
)),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -870,7 +870,8 @@ impl TestRepoFactory {
|
||||
/// Commit cloud
|
||||
pub fn commit_cloud(&self, _repo_identity: &RepoIdentity) -> Result<ArcCommitCloud> {
|
||||
Ok(Arc::new(commit_cloud::CommitCloud {
|
||||
storage: SqlCommitCloudBuilder::from_sql_connections(self.metadata_db.clone()).new(),
|
||||
storage: SqlCommitCloudBuilder::from_sql_connections(self.metadata_db.clone())
|
||||
.new(false),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user