-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init from etcd: basic support (#590)
change router initialization in clustered setup mechanics. Router requests current metadata setup from qdb on start. Router sync metadata routine now sync only current coordinator address for router proxy queries.
- Loading branch information
Showing
22 changed files
with
358 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
log_level: debug | ||
|
||
host: '::1' | ||
router_port: '6432' | ||
admin_console_port: '7432' | ||
grpc_api_port: '7010' | ||
|
||
world_shard_fallback: true | ||
router_mode: PROXY | ||
|
||
use_coordinator_init: true | ||
|
||
with_coordinator: true | ||
|
||
frontend_tls: | ||
key_file: /etc/odyssey/ssl/server.key | ||
cert_file: /etc/odyssey/ssl/server.crt | ||
sslmode: disable | ||
|
||
frontend_rules: | ||
- usr: user1 | ||
db: db1 | ||
pool_mode: TRANSACTION | ||
pool_prepared_statement: true | ||
auth_rule: | ||
auth_method: ok | ||
password: strong | ||
- pool_mode: TRANSACTION | ||
pool_default: true | ||
pool_prepared_statement: false | ||
auth_rule: | ||
auth_method: ok | ||
|
||
backend_rules: | ||
- usr: user1 | ||
db: db1 | ||
pool_discard: false | ||
pool_rollback: true | ||
- pool_default: true | ||
pool_discard: false | ||
pool_rollback: true | ||
|
||
shards: | ||
sh1: | ||
tls: | ||
key_file: /etc/odyssey/ssl/server.key | ||
sslmode: disable | ||
cert_file: /etc/odyssey/ssl/server.crt | ||
db: db1 | ||
usr: user1 | ||
pwd: 12345678 | ||
type: DATA | ||
hosts: | ||
- 'localhost:5550' | ||
sh2: | ||
tls: | ||
key_file: /etc/odyssey/ssl/server.key | ||
sslmode: disable | ||
cert_file: /etc/odyssey/ssl/server.crt | ||
db: db1 | ||
usr: user1 | ||
pwd: 12345678 | ||
type: DATA | ||
hosts: | ||
- 'localhost:5551' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,80 @@ | ||
package instance | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/pg-sharding/spqr/pkg/models/distributions" | ||
"github.com/pg-sharding/spqr/pkg/models/kr" | ||
"github.com/pg-sharding/spqr/pkg/spqrlog" | ||
"github.com/pg-sharding/spqr/qdb" | ||
) | ||
|
||
type EtcdMetadataBootstraper struct { | ||
RouterMetadataBootstraper | ||
QdbAddr string | ||
} | ||
|
||
// InitializeMetadata implements RouterMetadataBootstraper. | ||
func (e *EtcdMetadataBootstraper) InitializeMetadata(ctx context.Context, r RouterInstance) error { | ||
etcdConn, err := qdb.NewEtcdQDB(e.QdbAddr) | ||
if err != nil { | ||
return err | ||
} | ||
defer etcdConn.Client().Close() | ||
|
||
/* Initialize distributions */ | ||
ds, err := etcdConn.ListDistributions(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, d := range ds { | ||
if err := r.Console().Mgr().CreateDistribution(ctx, distributions.DistributionFromDB(d)); err != nil { | ||
spqrlog.Zero.Error().Err(err).Msg("failed to initialize instance") | ||
return err | ||
} | ||
|
||
/* initialize key ranges within distribution */ | ||
krs, err := etcdConn.ListKeyRanges(ctx, d.ID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, ckr := range krs { | ||
if err := r.Console().Mgr().CreateKeyRange(ctx, kr.KeyRangeFromDB(ckr)); err != nil { | ||
spqrlog.Zero.Error().Err(err).Msg("failed to initialize instance") | ||
return err | ||
} | ||
} | ||
} | ||
|
||
retryCnt := 50 | ||
|
||
for { | ||
c, err := etcdConn.GetCoordinator(ctx) | ||
if err != nil { | ||
if retryCnt > 0 { | ||
/* await the roiter to appear */ | ||
time.Sleep(time.Second) | ||
retryCnt-- | ||
continue | ||
} | ||
return err | ||
} | ||
|
||
err = r.Console().Mgr().UpdateCoordinator(ctx, c) | ||
|
||
if err == nil { | ||
break | ||
} | ||
return err | ||
} | ||
|
||
r.Initialize() | ||
|
||
return nil | ||
} | ||
|
||
func NewEtcdMetadataBootstraper(QdbAddr string) RouterMetadataBootstraper { | ||
return &EtcdMetadataBootstraper{QdbAddr: QdbAddr} | ||
} |
Oops, something went wrong.