Skip to content

Commit 032c5f9

Browse files
authored
services/horizon/cmd: add datastore config option to ingest verify-range cmd (#5732)
1 parent 65b2d61 commit 032c5f9

File tree

5 files changed

+395
-230
lines changed

5 files changed

+395
-230
lines changed

services/horizon/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).
77

88
- Update default pubnet captive core configuration to replace Whalestack with Creit Technologies in the quorum set ([5564](https://github.com/stellar/go/pull/5564)).
99

10+
- Add `--ledgerbackend` and `--datastore-config` options to `ingest verify-range` command to support CDP datastore backend configuration ([5553](https://github.com/stellar/go/pull/5553)).
11+
12+
1013
## 22.0.3
1114

1215
### Fixed

services/horizon/cmd/db.go

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,33 @@ var (
4949
ledgerBackendType ingest.LedgerBackendType
5050
)
5151

52+
// generateLedgerBackendOpt creates a reusable ConfigOption for ledgerbackend parameter
53+
func generateLedgerBackendOpt(configKey *string, backendTypeVar *ingest.LedgerBackendType) *support.ConfigOption {
54+
return &support.ConfigOption{
55+
Name: "ledgerbackend",
56+
ConfigKey: configKey,
57+
OptType: types.String,
58+
Required: false,
59+
FlagDefault: ingest.CaptiveCoreBackend.String(),
60+
Usage: fmt.Sprintf("[optional] Specify the ledger backend type: '%s' (default) or '%s'",
61+
ingest.CaptiveCoreBackend.String(),
62+
ingest.BufferedStorageBackend.String()),
63+
CustomSetValue: func(co *support.ConfigOption) error {
64+
val := viper.GetString(co.Name)
65+
switch val {
66+
case ingest.CaptiveCoreBackend.String():
67+
*backendTypeVar = ingest.CaptiveCoreBackend
68+
case ingest.BufferedStorageBackend.String():
69+
*backendTypeVar = ingest.BufferedStorageBackend
70+
default:
71+
return fmt.Errorf("invalid ledger backend: %s, must be 'captive-core' or 'datastore'", val)
72+
}
73+
*co.ConfigKey.(*string) = val
74+
return nil
75+
},
76+
}
77+
}
78+
5279
func requireAndSetFlags(horizonFlags config.ConfigOptions, names ...string) error {
5380
set := map[string]bool{}
5481
for _, name := range names {
@@ -133,29 +160,7 @@ func ingestRangeCmdOpts() support.ConfigOptions {
133160
FlagDefault: uint(5),
134161
Usage: "[optional] backoff seconds between reingest retries",
135162
},
136-
{
137-
Name: "ledgerbackend",
138-
ConfigKey: &ledgerBackendStr,
139-
OptType: types.String,
140-
Required: false,
141-
FlagDefault: ingest.CaptiveCoreBackend.String(),
142-
Usage: fmt.Sprintf("[optional] Specify the ledger backend type: '%s' (default) or '%s'",
143-
ingest.CaptiveCoreBackend.String(),
144-
ingest.BufferedStorageBackend.String()),
145-
CustomSetValue: func(co *support.ConfigOption) error {
146-
val := viper.GetString(co.Name)
147-
switch val {
148-
case ingest.CaptiveCoreBackend.String():
149-
ledgerBackendType = ingest.CaptiveCoreBackend
150-
case ingest.BufferedStorageBackend.String():
151-
ledgerBackendType = ingest.BufferedStorageBackend
152-
default:
153-
return fmt.Errorf("invalid ledger backend: %s, must be 'captive-core' or 'datastore'", val)
154-
}
155-
*co.ConfigKey.(*string) = val
156-
return nil
157-
},
158-
},
163+
generateLedgerBackendOpt(&ledgerBackendStr, &ledgerBackendType),
159164
{
160165
Name: "datastore-config",
161166
ConfigKey: &storageBackendConfigPath,
@@ -239,7 +244,7 @@ func runDBDetectGaps(config horizon.Config) ([]history.LedgerRange, error) {
239244
return nil, err
240245
}
241246
defer horizonSession.Close()
242-
q := &history.Q{horizonSession}
247+
q := &history.Q{SessionInterface: horizonSession}
243248
return q.GetLedgerGaps(context.Background())
244249
}
245250

@@ -249,7 +254,7 @@ func runDBDetectGapsInRange(config horizon.Config, start, end uint32) ([]history
249254
return nil, err
250255
}
251256
defer horizonSession.Close()
252-
q := &history.Q{horizonSession}
257+
q := &history.Q{SessionInterface: horizonSession}
253258
return q.GetLedgerGapsInRange(context.Background(), start, end)
254259
}
255260

0 commit comments

Comments
 (0)