Open
Description
Feature Description
This RFC proposes a new golang interface is added to go/vt/vtorc/db
to allow:
- Easier mocking of the backend store, for tests, etc
- The ability to use a different implementation
- A full separation of VTOrc logic vs. data access - right now
go/vt/vtorc/logic
has some database logic in it
The move to this would involve:
- Defining the new interface, I'm thinking
type DB interface
- Make the existing logic an implementation of the new interface
- Update tests
I've done a quick scan over the code, and I probably missed something, but here is a rough draft interface that should support the existing code. There are some small tweaks such as:
- Moving long signatures to opts
struct
s - Using real
*topodatapb.TabletAlias
vs the opinionatedtabletAlias string
- Adding
ctx context.Context
to everything
cc @GuptaManan100 for thoughts 🙇
Rough draft:
type Backend interface {
// Discovery
DeleteDiscoveredTablets(ctx context.Context) error
GetShardPrimary(ctx context.Context, keyspace string, shard string) (*topodatapb.Tablet, error)
GetTabletAliasesByCell(ctx context.Context) ([]*topodatapb.TabletAlias, error)
GetTabletAliasesByKeyspaceShard(ctx context.Context) ([]*topodatapb.TabletAlias, error)
// Detection
AttemptFailureDetectionRegistration(ctx context.Context, analysisEntry *inst.ReplicationAnalysis) (bool, error)
ClearActiveFailureDetections(ctx context.Context) error
// Analysis
AuditInstanceAnalysisInChangelog(ctx context.Context, tabletAlias *topodatapb.TabletAlias, analysisCode AnalysisCode) error
ExpireAuditData(ctx context.Context) error
ExpireInstanceAnalysisChangelog(ctx context.Context) error
GetReplicationAnalysis(ctx context.Context, keyspace string, shard string, hints *inst.ReplicationAnalysisHints) ([]*inst.ReplicationAnalysis, error)
// Audit
AuditOperation(ctx context.Context, opts *AuditOperationOpts) error
// Instance
ExpireStaleInstanceBinlogCoordinates(ctx context.Context) error
ForgetInstance(ctx context.Context, tabletAlias *topodatapb.TabletAlias) error
ForgetLongUnseenInstances(ctx context.Context) error
GetKeyspaceShardName(ctx context.Context, tabletAlias *topodatapb.TabletAlias) (string, string, error) {
LegacyReadInstanceClusterAttributes(ctx context.Context, primaryHost string, primaryPort int) (*inst.Instance, error)
ReadInstanceClusterAttributes(ctx context.Context, primaryAlias *topodatapb.TabletAlias) (*inst.Instance, error)
ReadInstance(ctx context.Context, tabletAlias *topodatapb.TabletAlias) (*inst.Instance, bool, error)
ReadReplicaInstances(ctx context.Context, opts *ReadReplicaInstancesOpts) ([]*inst.Instance, error)
ReadProblemInstances(ctx context.Context, keyspace string, shard string) ([]*inst.Instance, error)
ReadOutdatedInstanceKeys(ctx context.Context) ([]*topodatapb.TabletAlias, error)
ReadInstancesWithErrantGTIDs(ctx context.Context, keyspace string, shard string) ([]*inst.Instance, error)
RecordStaleInstanceBinlogCoordinates(ctx context.Context, tabletAlias *topodatapb.TabletAlias, binlogCoordinates *inst.BinlogCoordinates) error
SnapshotTopologies(ctx context.Context) error
UpdateInstanceLastAttemptedCheck(ctx context.Context, tabletAlias *topodatapb.TabletAlias)
UpdateInstanceLastChecked(ctx context.Context, tabletAlias *topodatapb.TabletAlias, partialSuccess bool) error
WriteInstances(ctx context.Context, instances []*inst.Instance, instanceWasActuallyFound, updateLastSeen bool) error
// Keyspace
ReadKeyspace(ctx context.Context, keyspace string) (*topo.KeyspaceInfo, error)
SaveKeyspace(ctx context.Context, keyspace *topo.KeyspaceInfo) error
GetDurabilityPolicy(ctx context.Context, keyspace string) (reparentutil.Durabler, error)
// Shard
ReadShardPrimaryInformation(ctx context.Context, keyspaceName, shardName string) (*topodatapb.TabletAlias, string, error)
SaveShard(ctx context.Context, shard *topo.ShardInfo) error
// Tablet
ReadTablet(ctx context.Context, tabletAlias *topodatapb.TabletAlias) (*topodatapb.Tablet, error)
SaveTablet(ctx context.Context, tablet *topodatapb.Tablet) error
// Recovery
AcknowledgeRecoveries(ctx context.Context, opts *AcknowledgeRecoveriesOpts) (int64, error)
ClearActiveRecoveries(ctx context.Context) error
DisableRecovery(ctx context.Context) error
EnableRecovery(ctx context.Context) error
ExpireBlockedRecoveries(ctx context.Context) error
ExpireRecoveries(ctx context.Context) error
ExpireRecoverySteps(ctx context.Context) error
IsRecoveryDisabled(ctx context.Context) (bool, error)
ReadRecoveries(ctx context.Context, opts *ReadRecoveriesOpts) ([]*logic.TopologyRecovery, error)
RegisterBlockedRecoveries(ctx context.Context, analysisEntry *inst.ReplicationAnalysis, blockingRecoveries []*logic.TopologyRecovery) error
WriteResolveRecovery(ctx context.Context, topologyRecovery *logic.TopologyRecovery) error
WriteTopologyRecovery(ctx context.Context, topologyRecovery *logic.TopologyRecovery) (*logic.TopologyRecovery, error)
WriteTopologyRecoveryStep(ctx context.Context, topologyRecoveryStep *logic.TopologyRecoveryStep) error
}
type AcknowledgeRecoveriesOpts struct {
Owner string
Comment string
MarkEndRecovery bool
}
type AuditOperationOpts struct {
// TODO: define
}
type ReadRecoveriesOpts struct {
// TODO: define
}
type ReadReplicaInstancesOpts struct {
PrimaryHost string
PrimaryPort int
IncludeBinlogServerSubReplicas bool
}
Use Case(s)
Developers and indirectly users of vtorc