:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
perf(personhog): switch leader fence scan to mark_active (#100629)
Nick Bestf4f01e71b0db
diff --git a/rust/personhog-leader/.sqlx/query-0a5daf41fe9185ee691c87aa6e009100999e6ec1c85bf2ab9bdacb933b4a7c50.json b/rust/personhog-leader/.sqlx/query-0a5daf41fe9185ee691c87aa6e009100999e6ec1c85bf2ab9bdacb933b4a7c50.jsonnew file mode 100644index 000000000000..b9b1a9872ada--- /dev/null+++ b/rust/personhog-leader/.sqlx/query-0a5daf41fe9185ee691c87aa6e009100999e6ec1c85bf2ab9bdacb933b4a7c50.json@@ -0,0 +1,40 @@+{+ "db_name": "PostgreSQL",+ "query": "SELECT id, group_type, group_type_index, team_id FROM posthog_grouptypemapping WHERE team_id = $1",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Int4"+ },+ {+ "ordinal": 1,+ "name": "group_type",+ "type_info": "Varchar"+ },+ {+ "ordinal": 2,+ "name": "group_type_index",+ "type_info": "Int4"+ },+ {+ "ordinal": 3,+ "name": "team_id",+ "type_info": "Int4"+ }+ ],+ "parameters": {+ "Left": [+ "Int4"+ ]+ },+ "nullable": [+ false,+ false,+ false,+ false+ ]+ },+ "hash": "0a5daf41fe9185ee691c87aa6e009100999e6ec1c85bf2ab9bdacb933b4a7c50"+}diff --git a/rust/personhog-leader/.sqlx/query-1a0a830fe83fd6bc0870fa1fdc226a5c67574fd9042b76c923b420a34f150bdd.json b/rust/personhog-leader/.sqlx/query-1a0a830fe83fd6bc0870fa1fdc226a5c67574fd9042b76c923b420a34f150bdd.jsonnew file mode 100644index 000000000000..8ccfc5426712--- /dev/null+++ b/rust/personhog-leader/.sqlx/query-1a0a830fe83fd6bc0870fa1fdc226a5c67574fd9042b76c923b420a34f150bdd.json@@ -0,0 +1,65 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT pp.id, pp.created_at, pp.team_id, pp.uuid, '{}'::jsonb as properties, pp.is_identified, pp.is_user_id, pp.version\n FROM posthog_person pp\n INNER JOIN posthog_persondistinctid\n ON pp.id = posthog_persondistinctid.person_id\n WHERE\n posthog_persondistinctid.distinct_id = $1\n AND posthog_persondistinctid.team_id = $2\n AND posthog_persondistinctid.is_deleted = false\n AND pp.team_id = $2\n AND pp.is_deleted = false\n LIMIT 1\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Int8"+ },+ {+ "ordinal": 1,+ "name": "created_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 2,+ "name": "team_id",+ "type_info": "Int4"+ },+ {+ "ordinal": 3,+ "name": "uuid",+ "type_info": "Uuid"+ },+ {+ "ordinal": 4,+ "name": "properties",+ "type_info": "Jsonb"+ },+ {+ "ordinal": 5,+ "name": "is_identified",+ "type_info": "Bool"+ },+ {+ "ordinal": 6,+ "name": "is_user_id",+ "type_info": "Int4"+ },+ {+ "ordinal": 7,+ "name": "version",+ "type_info": "Int8"+ }+ ],+ "parameters": {+ "Left": [+ "Text",+ "Int4"+ ]+ },+ "nullable": [+ false,+ false,+ false,+ false,+ null,+ false,+ true,+ true+ ]+ },+ "hash": "1a0a830fe83fd6bc0870fa1fdc226a5c67574fd9042b76c923b420a34f150bdd"+}diff --git a/rust/personhog-leader/.sqlx/query-4122d9f532c4eb09667b5d665f947708e778b99c6ec471f72079af5149ac878f.json b/rust/personhog-leader/.sqlx/query-4122d9f532c4eb09667b5d665f947708e778b99c6ec471f72079af5149ac878f.jsonnew file mode 100644index 000000000000..04c7478628a1--- /dev/null+++ b/rust/personhog-leader/.sqlx/query-4122d9f532c4eb09667b5d665f947708e778b99c6ec471f72079af5149ac878f.json@@ -0,0 +1,41 @@+{+ "db_name": "PostgreSQL",+ "query": "SELECT id, group_type, group_type_index, team_id FROM posthog_grouptypemapping WHERE team_id = $1 AND group_type = $2",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Int4"+ },+ {+ "ordinal": 1,+ "name": "group_type",+ "type_info": "Varchar"+ },+ {+ "ordinal": 2,+ "name": "group_type_index",+ "type_info": "Int4"+ },+ {+ "ordinal": 3,+ "name": "team_id",+ "type_info": "Int4"+ }+ ],+ "parameters": {+ "Left": [+ "Int4",+ "Text"+ ]+ },+ "nullable": [+ false,+ false,+ false,+ false+ ]+ },+ "hash": "4122d9f532c4eb09667b5d665f947708e778b99c6ec471f72079af5149ac878f"+}diff --git a/rust/personhog-leader/.sqlx/query-9797599a9be923f86da25f824e6992763239554455e0fc17ab6fc9c6797a1520.json b/rust/personhog-leader/.sqlx/query-9797599a9be923f86da25f824e6992763239554455e0fc17ab6fc9c6797a1520.jsonnew file mode 100644index 000000000000..23b384a07d00--- /dev/null+++ b/rust/personhog-leader/.sqlx/query-9797599a9be923f86da25f824e6992763239554455e0fc17ab6fc9c6797a1520.json@@ -0,0 +1,41 @@+{+ "db_name": "PostgreSQL",+ "query": "SELECT id, group_type, group_type_index, team_id FROM posthog_grouptypemapping WHERE team_id = $1 AND group_type_index = $2",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Int4"+ },+ {+ "ordinal": 1,+ "name": "group_type",+ "type_info": "Varchar"+ },+ {+ "ordinal": 2,+ "name": "group_type_index",+ "type_info": "Int4"+ },+ {+ "ordinal": 3,+ "name": "team_id",+ "type_info": "Int4"+ }+ ],+ "parameters": {+ "Left": [+ "Int4",+ "Int4"+ ]+ },+ "nullable": [+ false,+ false,+ false,+ false+ ]+ },+ "hash": "9797599a9be923f86da25f824e6992763239554455e0fc17ab6fc9c6797a1520"+}diff --git a/rust/personhog-leader/.sqlx/query-c630f8d0ae43133684ee35d8d35b5c40e3054ae58bbac24f0723cc30fa709b1a.json b/rust/personhog-leader/.sqlx/query-c630f8d0ae43133684ee35d8d35b5c40e3054ae58bbac24f0723cc30fa709b1a.jsonnew file mode 100644index 000000000000..9569520c6f9b--- /dev/null+++ b/rust/personhog-leader/.sqlx/query-c630f8d0ae43133684ee35d8d35b5c40e3054ae58bbac24f0723cc30fa709b1a.json@@ -0,0 +1,65 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT pp.id, pp.created_at, pp.team_id, pp.uuid, pp.properties, pp.is_identified, pp.is_user_id, pp.version\n FROM posthog_person pp\n INNER JOIN posthog_persondistinctid\n ON pp.id = posthog_persondistinctid.person_id\n WHERE\n posthog_persondistinctid.distinct_id = $1\n AND posthog_persondistinctid.team_id = $2\n AND posthog_persondistinctid.is_deleted = false\n AND pp.team_id = $2\n AND pp.is_deleted = false\n LIMIT 1\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Int8"+ },+ {+ "ordinal": 1,+ "name": "created_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 2,+ "name": "team_id",+ "type_info": "Int4"+ },+ {+ "ordinal": 3,+ "name": "uuid",+ "type_info": "Uuid"+ },+ {+ "ordinal": 4,+ "name": "properties",+ "type_info": "Jsonb"+ },+ {+ "ordinal": 5,+ "name": "is_identified",+ "type_info": "Bool"+ },+ {+ "ordinal": 6,+ "name": "is_user_id",+ "type_info": "Int4"+ },+ {+ "ordinal": 7,+ "name": "version",+ "type_info": "Int8"+ }+ ],+ "parameters": {+ "Left": [+ "Text",+ "Int4"+ ]+ },+ "nullable": [+ false,+ false,+ false,+ false,+ false,+ false,+ true,+ true+ ]+ },+ "hash": "c630f8d0ae43133684ee35d8d35b5c40e3054ae58bbac24f0723cc30fa709b1a"+}diff --git a/rust/personhog-leader/src/fence.rs b/rust/personhog-leader/src/fence.rsindex 5ae3d7436554..cd752a80430a 100644--- a/rust/personhog-leader/src/fence.rs+++ b/rust/personhog-leader/src/fence.rs@@ -142,7 +142,7 @@ pub async fn rebuild_partition_fences(SELECT lop.team_id, lop.person_id, lop.op_id, o.op_typeFROM {op_person} lopJOIN {op} o ON o.op_id = lop.op_id- WHERE lop.status IN ('marked', 'sealed')+ WHERE lop.mark_activeAND lop.role <> 'target'"#,op_person = tables.op_person,diff --git a/rust/personhog-leader/tests/fence_integration.rs b/rust/personhog-leader/tests/fence_integration.rsindex 8b494d60873c..04447ac498d0 100644--- a/rust/personhog-leader/tests/fence_integration.rs+++ b/rust/personhog-leader/tests/fence_integration.rs@@ -351,8 +351,8 @@ async fn a_committed_release_produces_the_death_document_above_every_version() {.await.expect("insert op");sqlx::query(- "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status) \- VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed')",+ "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status, mark_active) \+ VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed', true)",).bind(op).bind(team_id as i32)@@ -507,8 +507,8 @@ async fn a_revival_is_served_once_the_death_documents_mark_settles() {.await.expect("insert op");sqlx::query(- "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status) \- VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed')",+ "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status, mark_active) \+ VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed', true)",).bind(op).bind(team_id as i32)@@ -690,8 +690,8 @@ async fn a_committed_release_derives_the_death_version_above_the_emitted_floor().await.expect("insert op");sqlx::query(- "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status) \- VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed')",+ "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status, mark_active) \+ VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed', true)",).bind(op).bind(team_id as i32)@@ -786,8 +786,8 @@ async fn a_stub_sealed_at_version_zero_can_be_released() {.await.expect("insert op");sqlx::query(- "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status) \- VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed')",+ "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status, mark_active) \+ VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed', true)",).bind(op).bind(team_id as i32)@@ -869,8 +869,8 @@ async fn a_ghost_fence_heals_after_a_rejected_write() {.await.expect("insert op");sqlx::query(- "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status) \- VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed')",+ "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status, mark_active) \+ VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed', true)",).bind(op).bind(team_id as i32)@@ -963,8 +963,8 @@ async fn a_ghost_fence_heals_after_a_rejected_fence_attempt() {.await.expect("insert op");sqlx::query(- "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status) \- VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed')",+ "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status, mark_active) \+ VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed', true)",).bind(ghost_op).bind(team_id as i32)@@ -1054,8 +1054,8 @@ async fn a_live_marked_fence_survives_heal_attempts() {.await.expect("insert op");sqlx::query(- "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status) \- VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed')",+ "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status, mark_active) \+ VALUES ($1, $2, $3, gen_random_uuid(), 'victim', 'sealed', true)",).bind(holder_op).bind(team_id as i32)@@ -1331,21 +1331,22 @@ async fn the_takeover_scan_rebuilds_exactly_the_partitions_live_fences() {}let target: i64 = 100;let settled: i64 = 101;- for (person_id, role, status) in [- (fenced_a, "source", "marked"),- (fenced_b, "victim", "sealed"),- (target, "target", "marked"),- (settled, "victim", "deleted"),+ for (person_id, role, status, active) in [+ (fenced_a, "source", "marked", true),+ (fenced_b, "victim", "sealed", true),+ (target, "target", "marked", true),+ (settled, "victim", "deleted", false),] {sqlx::query(- "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status) \- VALUES ($1, $2, $3, gen_random_uuid(), $4, $5)",+ "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status, mark_active) \+ VALUES ($1, $2, $3, gen_random_uuid(), $4, $5, $6)",).bind(op_id).bind(team_id as i32).bind(person_id).bind(role).bind(status)+ .bind(active).execute(&pool).await.expect("insert mark");@@ -1581,6 +1582,7 @@ async fn seed_target_mark(team_id: i64,person_id: i64,status: &str,+ mark_active: bool,) {// A far-future lease keeps these never-completed ops out of the// identity sweeper's abandoned-op scan (it resumes NULL-lease and@@ -1596,13 +1598,14 @@ async fn seed_target_mark(.await.expect("insert op");sqlx::query(- "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status) \- VALUES ($1, $2, $3, gen_random_uuid(), 'target', $4)",+ "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status, mark_active) \+ VALUES ($1, $2, $3, gen_random_uuid(), 'target', $4, $5)",).bind(op).bind(team_id as i32).bind(person_id).bind(status)+ .bind(mark_active).execute(pool).await.expect("insert target mark");@@ -1622,7 +1625,15 @@ async fn start_marked_fold_harness(seed: CachedPerson, op: &Uuid) -> FenceHarnes}),).await;- seed_target_mark(&pool, op, harness.team_id, harness.person_id, "marked").await;+ seed_target_mark(+ &pool,+ op,+ harness.team_id,+ harness.person_id,+ "marked",+ true,+ )+ .await;harness}@@ -2125,7 +2136,15 @@ async fn a_fold_whose_op_holds_no_live_target_mark_is_refused() {);// A settled op: the target row was cleared when the saga completed.- seed_target_mark(&pool, &op, harness.team_id, harness.person_id, "cleared").await;+ seed_target_mark(+ &pool,+ &op,+ harness.team_id,+ harness.person_id,+ "cleared",+ false,+ )+ .await;let status = harness.client.fold_person_document(with_partition(request.clone(), harness.partition))@@ -2136,7 +2155,7 @@ async fn a_fold_whose_op_holds_no_live_target_mark_is_refused() {// The wrong role: the op holds the person, but not as its target —// folding into it would be a saga bug.sqlx::query(- "UPDATE lifecycle_op_person SET role = 'victim', status = 'marked' WHERE op_id = $1",+ "UPDATE lifecycle_op_person SET role = 'victim', status = 'marked', mark_active = true WHERE op_id = $1",).bind(op).execute(&pool)@@ -2566,8 +2585,8 @@ async fn a_release_after_a_cache_eviction_still_produces_the_death_document() {.await.expect("insert op");sqlx::query(- "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status) \- VALUES ($1, $2, $3, $4::uuid, 'victim', 'sealed')",+ "INSERT INTO lifecycle_op_person (op_id, team_id, person_id, person_uuid, role, status, mark_active) \+ VALUES ($1, $2, $3, $4::uuid, 'victim', 'sealed', true)",).bind(op).bind(team_id as i32)