Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/horizon: Remove db2/core. #2759

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).x
## Unreleased

* Add `--parallel-workers` and `--parallel-job-size` to `horizon db reingest range`. `--parallel-workers` will parallelize reingestion using the supplied number of workers.
* Remove Stellar Core's database dependency for non-ingesting instances of Horizon ((#2759)[https://github.com/stellar/go/pull/2759]).
Horizon doesn't require access to a Stellar Core database if it is only serving HTTP request, this allows the separation of front-end and ingesting instances.
The following config parameters were removed:
- `core-db-max-open-connections`
- `core-db-max-idle-connections`

## v1.5.0

Expand Down
18 changes: 1 addition & 17 deletions services/horizon/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ var configOpts = support.ConfigOptions{
ConfigKey: &config.MaxDBConnections,
OptType: types.Int,
FlagDefault: 0,
Usage: "when set has a priority over horizon-db-max-open-connections, horizon-db-max-idle-connections, core-db-max-open-connections, core-db-max-idle-connections. max horizon database open connections. may need to be increased when responses are slow but DB CPU is normal",
Usage: "when set has a priority over horizon-db-max-open-connections, horizon-db-max-idle-connections. max horizon database open connections may need to be increased when responses are slow but DB CPU is normal",
},
&support.ConfigOption{
Name: "horizon-db-max-open-connections",
Expand All @@ -190,20 +190,6 @@ var configOpts = support.ConfigOptions{
FlagDefault: 20,
Usage: "max horizon database idle connections. may need to be set to the same value as horizon-db-max-open-connections when responses are slow and DB CPU is normal, because it may indicate that a lot of time is spent closing/opening idle connections. This can happen in case of high variance in number of requests. must be equal or lower than max open connections",
},
&support.ConfigOption{
Name: "core-db-max-open-connections",
ConfigKey: &config.CoreDBMaxOpenConnections,
OptType: types.Int,
FlagDefault: 20,
Usage: "max core database open connections. may need to be increased when responses are slow but DB CPU is normal",
},
&support.ConfigOption{
Name: "core-db-max-idle-connections",
ConfigKey: &config.CoreDBMaxIdleConnections,
OptType: types.Int,
FlagDefault: 20,
Usage: "max core database idle connections. may need to be set to the same value as core-db-max-open-connections when responses are slow and DB CPU is normal, because it may indicate that a lot of time is spent closing/opening idle connections. This can happen in case of high variance in number of requests. must be equal or lower than max open connections",
},
&support.ConfigOption{
Name: "sse-update-frequency",
ConfigKey: &config.SSEUpdateFrequency,
Expand Down Expand Up @@ -430,8 +416,6 @@ func initRootConfig() {
if config.MaxDBConnections != 0 {
config.HorizonDBMaxOpenConnections = config.MaxDBConnections
config.HorizonDBMaxIdleConnections = config.MaxDBConnections
config.CoreDBMaxOpenConnections = config.MaxDBConnections
config.CoreDBMaxIdleConnections = config.MaxDBConnections
}
}

Expand Down
18 changes: 0 additions & 18 deletions services/horizon/internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/stellar/go/clients/stellarcore"
proto "github.com/stellar/go/protocols/stellarcore"
horizonContext "github.com/stellar/go/services/horizon/internal/context"
"github.com/stellar/go/services/horizon/internal/db2/core"
"github.com/stellar/go/services/horizon/internal/db2/history"
"github.com/stellar/go/services/horizon/internal/expingest"
"github.com/stellar/go/services/horizon/internal/ledger"
Expand Down Expand Up @@ -61,7 +60,6 @@ type App struct {
config Config
web *web
historyQ *history.Q
coreQ *core.Q
ctx context.Context
cancel func()
horizonVersion string
Expand All @@ -79,7 +77,6 @@ type App struct {
historyElderLedgerGauge metrics.Gauge
horizonConnGauge metrics.Gauge
coreLatestLedgerGauge metrics.Gauge
coreConnGauge metrics.Gauge
goroutineGauge metrics.Gauge
}

Expand Down Expand Up @@ -181,7 +178,6 @@ func (a *App) Close() {
// closed" errors.
func (a *App) CloseDB() {
a.historyQ.Session.DB.Close()
a.coreQ.Session.DB.Close()
}

// HistoryQ returns a helper object for performing sql queries against the
Expand All @@ -196,18 +192,6 @@ func (a *App) HorizonSession(ctx context.Context) *db.Session {
return &db.Session{DB: a.historyQ.Session.DB, Ctx: ctx}
}

// CoreSession returns a new session that loads data from the stellar core
// database. The returned session is bound to `ctx`.
func (a *App) CoreSession(ctx context.Context) *db.Session {
return &db.Session{DB: a.coreQ.Session.DB, Ctx: ctx}
}

// CoreQ returns a helper object for performing sql queries aginst the
// stellar core database.
func (a *App) CoreQ() *core.Q {
return a.coreQ
}

// IsHistoryStale returns true if the latest history ledger is more than
// `StaleThreshold` ledgers behind the latest core ledger
func (a *App) IsHistoryStale() bool {
Expand Down Expand Up @@ -427,7 +411,6 @@ func (a *App) UpdateMetrics() {
a.coreLatestLedgerGauge.Update(int64(ls.CoreLatest))

a.horizonConnGauge.Update(int64(a.historyQ.Session.DB.Stats().OpenConnections))
a.coreConnGauge.Update(int64(a.coreQ.Session.DB.Stats().OpenConnections))
}

// DeleteUnretainedHistory forwards to the app's reaper. See
Expand Down Expand Up @@ -479,7 +462,6 @@ func (a *App) init() {

// horizon-db and core-db
mustInitHorizonDB(a)
mustInitCoreDB(a)

if a.config.Ingest {
// expingester
Expand Down
2 changes: 0 additions & 2 deletions services/horizon/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ type Config struct {
MaxDBConnections int
HorizonDBMaxOpenConnections int
HorizonDBMaxIdleConnections int
CoreDBMaxOpenConnections int
CoreDBMaxIdleConnections int

SSEUpdateFrequency time.Duration
ConnectionTimeout time.Duration
Expand Down
41 changes: 0 additions & 41 deletions services/horizon/internal/db2/core/main.go

This file was deleted.

63 changes: 0 additions & 63 deletions services/horizon/internal/db2/core/main_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,7 @@ As noted above, Horizon relies on Stellar Core to stay in sync with the Stellar
```shell
"stellar_core.latest_ledger": {
"value": 19203710
},
"stellar_core.open_connections": {
"value": 4
},
}
```

#### Transaction Submission
Expand Down
6 changes: 2 additions & 4 deletions services/horizon/internal/expingest/database_backend_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package expingest

import (
"github.com/stellar/go/network"
"testing"

"github.com/stellar/go/exp/ingest/ledgerbackend"
"github.com/stellar/go/services/horizon/internal/db2/core"
"github.com/stellar/go/network"
"github.com/stellar/go/services/horizon/internal/test"
)

Expand All @@ -23,12 +22,11 @@ func TestGetLatestLedger(t *testing.T) {
func TestGetLatestLedgerNotFound(t *testing.T) {
tt := test.Start(t).ScenarioWithoutHorizon("base")
defer tt.Finish()
q := &core.Q{tt.CoreSession()}

_, err := tt.CoreDB.Exec(`DELETE FROM ledgerheaders`)
tt.Assert.NoError(err, "failed to remove ledgerheaders")

backend, err := ledgerbackend.NewDatabaseBackendFromSession(q.Session, network.TestNetworkPassphrase)
backend, err := ledgerbackend.NewDatabaseBackendFromSession(tt.CoreSession(), network.TestNetworkPassphrase)
tt.Assert.NoError(err)
_, err = backend.GetLatestLedgerSequence()
tt.Assert.EqualError(err, "no ledgers exist in ledgerheaders table")
Expand Down
24 changes: 0 additions & 24 deletions services/horizon/internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/rcrowley/go-metrics"

"github.com/stellar/go/exp/orderbook"
"github.com/stellar/go/services/horizon/internal/db2/core"
"github.com/stellar/go/services/horizon/internal/db2/history"
"github.com/stellar/go/services/horizon/internal/expingest"
"github.com/stellar/go/services/horizon/internal/simplepath"
Expand Down Expand Up @@ -51,27 +50,6 @@ func mustInitHorizonDB(app *App) {
)}
}

func mustInitCoreDB(app *App) {
maxIdle := app.config.CoreDBMaxIdleConnections
maxOpen := app.config.CoreDBMaxOpenConnections
abuiles marked this conversation as resolved.
Show resolved Hide resolved
if app.config.Ingest {
maxIdle -= expingest.MaxDBConnections
maxOpen -= expingest.MaxDBConnections
if maxIdle <= 0 {
log.Fatalf("max idle connections to stellar-core db must be greater than %d", expingest.MaxDBConnections)
}
if maxOpen <= 0 {
log.Fatalf("max open connections to stellar-core db must be greater than %d", expingest.MaxDBConnections)
}
}

app.coreQ = &core.Q{mustNewDBSession(
app.config.StellarCoreDatabaseURL,
maxIdle,
maxOpen,
)}
}

func initExpIngester(app *App) {
var err error
app.expingester, err = expingest.NewSystem(expingest.Config{
Expand Down Expand Up @@ -144,14 +122,12 @@ func initDbMetrics(app *App) {
app.historyElderLedgerGauge = metrics.NewGauge()
app.coreLatestLedgerGauge = metrics.NewGauge()
app.horizonConnGauge = metrics.NewGauge()
app.coreConnGauge = metrics.NewGauge()
app.goroutineGauge = metrics.NewGauge()
app.metrics.Register("history.latest_ledger", app.historyLatestLedgerGauge)
app.metrics.Register("history.elder_ledger", app.historyElderLedgerGauge)
app.metrics.Register("stellar_core.latest_ledger", app.coreLatestLedgerGauge)
app.metrics.Register("order_book_stream.latest_ledger", app.orderBookStream.LatestLedgerGauge)
app.metrics.Register("history.open_connections", app.horizonConnGauge)
app.metrics.Register("stellar_core.open_connections", app.coreConnGauge)
app.metrics.Register("goroutines", app.goroutineGauge)
}

Expand Down