feat(redis-projection): per-dict feature flag (CEO plan E2 tiered perf)
Per-dictionary opt-in для Redis projection materialization. Default false
— projection-writer пропускает event'ы того dict'а, никаких dead writes
в Redis. Включается админ'ом через UI checkbox в Metadata tab.
Migration 0017:
- ALTER TABLE dictionary_definitions ADD COLUMN redis_projection_enabled
BOOLEAN NOT NULL DEFAULT false.
- Index idx_dict_def_redis_proj для быстрого filtering в list queries.
Backend:
- DictionaryDefinition entity: new field + getter/setter.
- DictionaryResponse DTO: returns flag в response.
- CreateDictionaryRequest DTO: optional Boolean (null/missing = no change).
- DictionaryDefinitionService.create + updateSchema: применяет flag из request.
- ProjectionWriter (projection-writer service):
* upsert() — early-return + skip counter если flag=false на dict.
* delete() — symmetric: skip если flag=false (защита от stale keys
после flag-flip; полный cleanup TODO Phase 2).
* New metric: ordinis_projection_records_skipped_total.
Admin UI:
- DictionaryEditorDialog Metadata tab: checkbox "Включить Redis-проекцию"
с описанием. Apply через CreateDictionaryRequest payload.
- DictionaryDefinition + CreateDictionaryRequest types updated.
- i18n RU/EN: schema.redisProjection.{label,hint}.
Что НЕ делается (deferred Phase 2):
- read-api Redis routing — read-api сейчас всегда идёт в PG read replica.
Когда dict опт-инится в флаг, projection материализуется, но read-api
ещё не использует. Read routing — отдельная feature с benchmark proof
(через JMH + k6 SLO test).
- One-shot cleanup job для stale keys после flag-flip from true→false.
Behavior change в production:
- До patch: projection-writer пишет в Redis для ВСЕХ dict events (40
dictionaries). Default flag=false после migration → projection-writer
пропускает всё → Redis keys для existing dicts становятся stale.
Это OK потому что read-api НИКОГДА не читал из Redis (writes были
dead). Stale keys eventually evicted Redis maxmemory policy.
- После patch: только dicts с redis_projection_enabled=true получают
материализацию. По default — нет. Admin opt-ins per-dict через UI.
Verify:
- mvn test (full reactor): SUCCESS, all green.
- mvn -P e2e -pl ordinis-app -am test: 20/20 PASS (migration 0017 applied).
- pnpm tsc --noEmit: clean.
- pnpm test (vitest): 89/89 PASS.
- pnpm build: clean.
This commit is contained in:
+11
@@ -67,6 +67,15 @@ public class DictionaryDefinition {
|
||||
@Column(name = "default_locale", nullable = false, length = 10)
|
||||
private String defaultLocale = "ru-RU";
|
||||
|
||||
/**
|
||||
* Per-dictionary Redis projection opt-in (CEO plan E2 tiered perf).
|
||||
* False (default) — projection-writer skips this dict's events, read-api
|
||||
* goes to PG read replica. True — projection-writer materializes updates
|
||||
* to Redis (read-api routing TBD в отдельном feature).
|
||||
*/
|
||||
@Column(name = "redis_projection_enabled", nullable = false)
|
||||
private boolean redisProjectionEnabled = false;
|
||||
|
||||
@CreatedDate
|
||||
@Column(name = "created_at", nullable = false, updatable = false)
|
||||
private OffsetDateTime createdAt;
|
||||
@@ -106,6 +115,7 @@ public class DictionaryDefinition {
|
||||
public String getBundle() { return bundle; }
|
||||
public String[] getSupportedLocales() { return supportedLocales; }
|
||||
public String getDefaultLocale() { return defaultLocale; }
|
||||
public boolean isRedisProjectionEnabled() { return redisProjectionEnabled; }
|
||||
public OffsetDateTime getCreatedAt() { return createdAt; }
|
||||
public OffsetDateTime getUpdatedAt() { return updatedAt; }
|
||||
public String getCreatedBy() { return createdBy; }
|
||||
@@ -119,4 +129,5 @@ public class DictionaryDefinition {
|
||||
public void setBundle(String v) { this.bundle = v; }
|
||||
public void setSupportedLocales(String[] v) { this.supportedLocales = v; }
|
||||
public void setDefaultLocale(String v) { this.defaultLocale = v; }
|
||||
public void setRedisProjectionEnabled(boolean v) { this.redisProjectionEnabled = v; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user