Centralize durable schema migration ownership
This commit is contained in:
parent
cc328237f4
commit
069f3813ae
6 changed files with 354 additions and 350 deletions
|
|
@ -23,6 +23,7 @@ remora-object-source = { path = "../remora-object-source" }
|
|||
remora-outbound = { path = "../remora-outbound" }
|
||||
remora-result = { path = "../remora-result" }
|
||||
remora-runtime = { path = "../remora-runtime" }
|
||||
remora-schema.workspace = true
|
||||
remora-stream = { path = "../remora-stream" }
|
||||
remora-target = { path = "../remora-target" }
|
||||
reqwest = { version = "=0.13.4", default-features = false, features = ["json", "rustls"] }
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
CREATE TABLE worker_descriptors (
|
||||
descriptor_id TEXT PRIMARY KEY,
|
||||
attempt_id TEXT NOT NULL REFERENCES attempts (attempt_id) ON DELETE CASCADE,
|
||||
kind TEXT NOT NULL CHECK (kind IN ('resolved_source', 'checkpoint')),
|
||||
schema_version INTEGER NOT NULL CHECK (schema_version >= 1),
|
||||
payload JSONB NOT NULL,
|
||||
byte_length BIGINT NOT NULL CHECK (byte_length >= 0),
|
||||
item_count BIGINT CHECK (item_count >= 0),
|
||||
checksum TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX worker_descriptors_attempt_idx
|
||||
ON worker_descriptors (attempt_id, kind, created_at, descriptor_id);
|
||||
|
|
@ -146,8 +146,7 @@ impl WorkerApplication {
|
|||
)
|
||||
.await
|
||||
.map_err(runtime_error)?;
|
||||
wait_for_core_schema(&pool).await?;
|
||||
crate::migrate(&pool).await.map_err(runtime_error)?;
|
||||
wait_for_schema(&pool).await?;
|
||||
let coordination = CoordinationStore::connect(
|
||||
&self.config.coordination_url,
|
||||
&self.config.coordination_namespace,
|
||||
|
|
@ -219,20 +218,15 @@ impl WorkerApplication {
|
|||
}
|
||||
}
|
||||
|
||||
async fn wait_for_core_schema(pool: &sqlx::PgPool) -> Result<(), RuntimeError> {
|
||||
async fn wait_for_schema(pool: &sqlx::PgPool) -> Result<(), RuntimeError> {
|
||||
for _ in 0..120 {
|
||||
let ready =
|
||||
sqlx::query_scalar::<_, Option<String>>("SELECT to_regclass('public.jobs')::text")
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
.is_ok_and(|table| table.is_some());
|
||||
if ready {
|
||||
if remora_schema::is_ready(pool).await.unwrap_or(false) {
|
||||
return Ok(());
|
||||
}
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
Err(RuntimeError::message(
|
||||
"core database schema was not initialized",
|
||||
"database schema did not reach the required generation",
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ use time::OffsetDateTime;
|
|||
|
||||
use crate::WorkerError;
|
||||
|
||||
const MIGRATION_TABLE: &str = "_remora_worker_migrations";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DescriptorStore {
|
||||
pool: PgPool,
|
||||
|
|
@ -154,17 +152,6 @@ impl DescriptorStore {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn migrate(pool: &PgPool) -> Result<(), sqlx::migrate::MigrateError> {
|
||||
migrator().run(pool).await
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn migrator() -> sqlx::migrate::Migrator {
|
||||
let mut migrator = sqlx::migrate!("./migrations");
|
||||
migrator.dangerous_set_table_name(MIGRATION_TABLE);
|
||||
migrator
|
||||
}
|
||||
|
||||
struct StoredDescriptor {
|
||||
id: OpaqueId,
|
||||
schema_version: PositiveIntegerDto,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ mod runtime;
|
|||
|
||||
pub use application::{WorkerApplication, WorkerApplicationConfig};
|
||||
pub use client::WorkerApiClient;
|
||||
pub use descriptor::{DescriptorStore, migrate, migrator};
|
||||
pub use descriptor::DescriptorStore;
|
||||
pub use error::WorkerError;
|
||||
pub use executor::{AdapterExecutor, ObjectSourceEndpoint};
|
||||
pub use runtime::{
|
||||
|
|
|
|||
|
|
@ -16,13 +16,11 @@ use rcgen::{
|
|||
BasicConstraints, Certificate, CertificateParams, ExtendedKeyUsagePurpose, IsCa, Issuer,
|
||||
KeyPair, KeyUsagePurpose,
|
||||
};
|
||||
use remora_admission::{
|
||||
AdmissionConfig, AdmissionDecision, AdmissionService, migrate as admission_migrate,
|
||||
};
|
||||
use remora_admission::{AdmissionConfig, AdmissionDecision, AdmissionService};
|
||||
use remora_api::{WorkerApiState, authenticate_rustls_worker, configure_worker_api};
|
||||
use remora_attempt::{
|
||||
ActivationOutcome, AttemptConfig, AttemptService, CheckpointRecord, DurableDescriptor,
|
||||
RecoveryConfig, StagingObject, migrate as attempt_migrate,
|
||||
RecoveryConfig, StagingObject,
|
||||
};
|
||||
use remora_contracts::{
|
||||
CheckpointDescriptorRefDto, HttpSourceSubmissionDto, HuggingFaceRepositoryTypeDto,
|
||||
|
|
@ -34,19 +32,19 @@ use remora_contracts::{
|
|||
use remora_coordination::{CoordinationStore, LeaseOwner, StoreConfig};
|
||||
use remora_credentials::{
|
||||
CreateCredential, CredentialRegistry, GrantBoundResolver, SecretMaterial, VaultClient,
|
||||
VaultConfig, migrate as credentials_migrate,
|
||||
VaultConfig,
|
||||
};
|
||||
use remora_domain::{BucketName, JobPhase, OpaqueId, StorageScope, TargetPrefix, TargetStoreId};
|
||||
use remora_durable::{PoolConfig, connect, migrate as durable_migrate};
|
||||
use remora_durable::{PoolConfig, connect};
|
||||
use remora_identity::{DefaultTarget, Principal};
|
||||
use remora_outbound::OutboundPolicyBuilder;
|
||||
use remora_result::{ResultInventory, ResultMember, migrate as result_migrate};
|
||||
use remora_result::{ResultInventory, ResultMember};
|
||||
use remora_schema::migrate as migrate_schema;
|
||||
use remora_stream::{CancelToken, CopyConfig, RetryTiming};
|
||||
use remora_target::{CreateObjectRequest, TargetStore, TargetStoreConfig, attempt_manifest_key_in};
|
||||
use remora_worker::{
|
||||
AdapterExecutor, AttemptContext, AttemptExecution, AttemptExecutor, DescriptorStore,
|
||||
ObjectSourceEndpoint, WorkerApiClient, WorkerConfig, WorkerRunOutcome, WorkerRuntime,
|
||||
migrate as worker_migrate,
|
||||
};
|
||||
use reqwest::{Certificate as ClientCertificate, Client, Identity};
|
||||
use rustls::{
|
||||
|
|
@ -80,12 +78,7 @@ impl Harness {
|
|||
)
|
||||
.await
|
||||
.unwrap();
|
||||
durable_migrate(&pool).await.unwrap();
|
||||
credentials_migrate(&pool).await.unwrap();
|
||||
admission_migrate(&pool).await.unwrap();
|
||||
attempt_migrate(&pool).await.unwrap();
|
||||
result_migrate(&pool).await.unwrap();
|
||||
worker_migrate(&pool).await.unwrap();
|
||||
migrate_schema(&pool).await.unwrap();
|
||||
sqlx::query("TRUNCATE TABLE jobs CASCADE")
|
||||
.execute(&pool)
|
||||
.await
|
||||
|
|
|
|||
Loading…
Reference in a new issue