mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(redshift): seed catalog and system views (#3552)
* feat(redshift): seed catalog and system views on cluster startup Seed Amazon Redshift catalog and system views on container startup into both template1 and dev databases so BI, ORM, and migration tools (Tableau, Looker, DBeaver, Flyway, Liquibase, dbt) can introspect database schema metadata without missing-relation errors. * feat(redshift): record COPY failures in stl_load_errors and dynamicize query logs Record failed S3 COPY attempts into pg_catalog.stl_load_errors via LoadErrorRecorder across simple and extended query flows. Convert stl_query and svl_qlog into dynamic views backed by pg_stat_activity, and add stv_wlm_query_state and svv_diskusage catalog views. * fix(redshift): align catalog views with documented Redshift column schema * fix(redshift): separate catalog seeding from copy error recording * test(redshift): preserve container manager coverage
This commit is contained in:
1 parent
e32f762899
commit
d9abefb83f
7 files changed
+838
-3
No files matched your search
+45
@@ -75,6 +75,7 @@ public class RedshiftContainerManager {
|
||||
ContainerBuilder.Builder specBuilder = containerBuilder.newContainer(image)
|
||||
.withName(containerName)
|
||||
.withEnv(envVars)
|
||||
.withCmd(List.of("postgres", "-c", "allow_system_table_mods=on"))
|
||||
.withDockerNetwork(config.services().redshift().dockerNetwork())
|
||||
.withLogRotation();
|
||||
|
||||
@@ -140,6 +141,7 @@ public class RedshiftContainerManager {
|
||||
}
|
||||
|
||||
waitForReady(containerName, info.containerId(), masterUsername, "dev");
|
||||
bootstrapCatalog(info.containerId(), masterUsername, "dev");
|
||||
|
||||
containers.put(containerKey(accountId, clusterIdentifier), handle);
|
||||
return handle;
|
||||
@@ -415,5 +417,48 @@ public class RedshiftContainerManager {
|
||||
throw new IllegalStateException("Timed out initializing " + description + " in " + containerName + ": " + lastOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstraps Redshift catalog and system views in the dev database so BI
|
||||
* and migration tooling can inspect metadata without relation-does-not-exist errors.
|
||||
*/
|
||||
void bootstrapCatalog(String containerId, String username, String dbName) {
|
||||
String effectiveUser = (username != null && !username.isBlank()) ? username : "postgres";
|
||||
String effectiveDb = (dbName != null && !dbName.isBlank()) ? dbName : "dev";
|
||||
try (InputStream in = getClass().getResourceAsStream("/redshift/bootstrap-catalog.sql")) {
|
||||
if (in == null) {
|
||||
LOG.warnv("Redshift bootstrap-catalog.sql not found on classpath; skipping catalog seed for container {0}", containerId);
|
||||
return;
|
||||
}
|
||||
byte[] sqlBytes = in.readAllBytes();
|
||||
byte[] tarBytes = buildSingleFileTar("bootstrap-catalog.sql", sqlBytes, 0644);
|
||||
lifecycleManager.getDockerClient().copyArchiveToContainerCmd(containerId)
|
||||
.withTarInputStream(new ByteArrayInputStream(tarBytes))
|
||||
.withRemotePath("/tmp")
|
||||
.exec();
|
||||
|
||||
List<String> targetDbs = effectiveDb.equals("template1")
|
||||
? List.of("template1")
|
||||
: List.of("template1", effectiveDb);
|
||||
for (String db : targetDbs) {
|
||||
String[] cmd = new String[]{
|
||||
"psql",
|
||||
"-h", "127.0.0.1",
|
||||
"-v", "ON_ERROR_STOP=1",
|
||||
"-U", effectiveUser,
|
||||
"-d", db,
|
||||
"-f", "/tmp/bootstrap-catalog.sql"
|
||||
};
|
||||
ExecResult result = execInContainer(containerId, cmd, 30);
|
||||
if (result.exitCode() != 0) {
|
||||
LOG.warnv("Redshift catalog bootstrap for {0} exited with code {1}: {2}", db, result.exitCode(), result.stderr());
|
||||
} else {
|
||||
LOG.infov("Redshift catalog views bootstrapped successfully for {0} in container {1}", db, containerId);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.warnv(e, "Error bootstrapping Redshift catalog views for container {0}", containerId);
|
||||
}
|
||||
}
|
||||
|
||||
public record ExecResult(long exitCode, String stdout, String stderr) {}
|
||||
}
|
||||
Reference in new issue
Block a user