From bbe72a474bcdf35b9f34eee7ce23b5c57df357f9 Mon Sep 17 00:00:00 2001 From: "T. von Dein" Date: Fri, 26 Jun 2026 11:25:30 +0200 Subject: [PATCH] fix #53: shardsize to string, fix nil pointer, add cold phase (#54) --- cmd/ilm.go | 7 ++++++- pkg/cfg/ilm.go | 7 ++++--- pkg/es/ilm.go | 42 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/cmd/ilm.go b/cmd/ilm.go index 8cc984d..128caa9 100644 --- a/cmd/ilm.go +++ b/cmd/ilm.go @@ -144,7 +144,7 @@ func IlmCreate(conf *cfg.Config) *cli.Command { Usage: "hot phase: rollover after", Destination: &conf.Ilm.HotRolloverMaxAge, }, - &cli.Int64Flag{ + &cli.StringFlag{ Name: "hot-rollover-max-primary-shard-size", Usage: "hot phase: max primary shard size", Destination: &conf.Ilm.HotRolloverMaxPrimaryShardSize, @@ -210,6 +210,11 @@ func IlmCreate(conf *cfg.Config) *cli.Command { Usage: "frozen phase: min age", Destination: &conf.Ilm.FrozenMinAge, }, + &cli.StringFlag{ + Name: "frozen-searchable-snapshot-repo", + Usage: "frozen phase: searchable snapshot repo", + Destination: &conf.Ilm.FrozenSearchableSnapshotRepo, + }, // delete &cli.StringFlag{ diff --git a/pkg/cfg/ilm.go b/pkg/cfg/ilm.go index 3353d9a..67c742a 100644 --- a/pkg/cfg/ilm.go +++ b/pkg/cfg/ilm.go @@ -21,7 +21,7 @@ type Ilm struct { HotMinAge string HotRolloverMaxAge string - HotRolloverMaxPrimaryShardSize int64 + HotRolloverMaxPrimaryShardSize string HotRolloverMaxDocs int64 HotReadonly bool @@ -35,7 +35,8 @@ type Ilm struct { ColdForceMerge int ColdPriority int - FrozenMinAge string + FrozenMinAge string + FrozenSearchableSnapshotRepo string DeleteMinAge string DeleteSearchableSnapshots bool @@ -47,7 +48,7 @@ func (cfg *Ilm) HaveHot() bool { return cfg.HotMinAge != "" || cfg.HotRolloverMaxAge != "" || cfg.HotRolloverMaxDocs > 0 || - cfg.HotRolloverMaxPrimaryShardSize > 0 || + cfg.HotRolloverMaxPrimaryShardSize != "" || cfg.HotReadonly } diff --git a/pkg/es/ilm.go b/pkg/es/ilm.go index 19cbbc0..9fa14f7 100644 --- a/pkg/es/ilm.go +++ b/pkg/es/ilm.go @@ -245,7 +245,7 @@ func IlmCreate(conf *cfg.Config, policyname string) error { haveroll = true } - if cfg.HotRolloverMaxPrimaryShardSize != 0 { + if cfg.HotRolloverMaxPrimaryShardSize != "" { rollover.MaxPrimaryShardSize = &cfg.HotRolloverMaxPrimaryShardSize } @@ -281,16 +281,50 @@ func IlmCreate(conf *cfg.Config, policyname string) error { phases.PhasesCaster().Warm = &warm } + if cfg.HaveCold() { + cold := types.Phase{} + var actions types.IlmActionsVariant = esdsl.NewIlmActions() + + if cfg.ColdForceMerge != 0 { + actions.IlmActionsCaster().Forcemerge = &types.ForceMergeAction{MaxNumSegments: cfg.ColdForceMerge} + } + + if cfg.ColdMinAge != "" { + cold.MinAge = cfg.ColdMinAge + } + + if cfg.ColdPriority != 0 { + actions.IlmActionsCaster().SetPriority = &types.SetPriorityAction{Priority: &cfg.ColdPriority} + } + + if cfg.ColdSearchableSnapshotRepo != "" { + actions.IlmActionsCaster().SearchableSnapshot = + &types.SearchableSnapshotAction{SnapshotRepository: cfg.ColdSearchableSnapshotRepo} + } + + cold.Actions = actions.IlmActionsCaster() + phases.PhasesCaster().Cold = &cold + } + if cfg.HaveFrozen() { - froze := phases.PhasesCaster().Frozen + froze := types.Phase{} + var actions types.IlmActionsVariant = esdsl.NewIlmActions() if cfg.FrozenMinAge != "" { froze.MinAge = cfg.FrozenMinAge } + + if cfg.FrozenSearchableSnapshotRepo != "" { + actions.IlmActionsCaster().SearchableSnapshot = + &types.SearchableSnapshotAction{SnapshotRepository: cfg.FrozenSearchableSnapshotRepo} + } + + froze.Actions = actions.IlmActionsCaster() + phases.PhasesCaster().Frozen = &froze } if cfg.HaveDelete() { - del := phases.PhasesCaster().Delete + del := types.Phase{} delete := types.DeleteAction{} var actions types.IlmActionsVariant = esdsl.NewIlmActions() @@ -304,7 +338,7 @@ func IlmCreate(conf *cfg.Config, policyname string) error { actions.IlmActionsCaster().Delete = &delete del.Actions = actions.IlmActionsCaster() - phases.PhasesCaster().Delete = del + phases.PhasesCaster().Delete = &del } put := &putlifecycle.Request{}