Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(ha): ha limit for subscription (#18882)

ecmadao970b2b83c2ae
diff --git a/backend/api/mcp/gen/openapi.yaml b/backend/api/mcp/gen/openapi.yaml
index 02d474e61c..5f46c1c2ff 100644
--- a/backend/api/mcp/gen/openapi.yaml
+++ b/backend/api/mcp/gen/openapi.yaml
@@ -6340,6 +6340,11 @@ components:
type: boolean
title: external_url_from_flag
description: Whether the external URL is set via command-line flag (and thus cannot be changed via UI).
+ replicaCount:
+ type: integer
+ title: replica_count
+ format: int32
+ description: The number of active replicas (servers sharing the same database).
title: ActuatorInfo
additionalProperties: false
description: |-
@@ -15343,6 +15348,10 @@ components:
orgName:
type: string
title: org_name
+ ha:
+ type: boolean
+ title: ha
+ description: Whether high availability (multiple replicas) is enabled.
title: Subscription
additionalProperties: false
bytebase.v1.SyncDatabaseRequest:
diff --git a/backend/api/v1/actuator_service.go b/backend/api/v1/actuator_service.go
index 63254d37db..a363ebf42a 100644
--- a/backend/api/v1/actuator_service.go
+++ b/backend/api/v1/actuator_service.go
@@ -153,6 +153,7 @@ func (s *ActuatorService) getServerInfo(ctx context.Context) (*v1pb.ActuatorInfo
UnlicensedFeatures: unlicensedFeaturesString,
EnableSample: hasSampleInstances,
ExternalUrlFromFlag: s.profile.ExternalURL != "",
+ ReplicaCount: int32(s.licenseService.CountActiveReplicas(ctx)),
}
stats, err := s.store.StatUsers(ctx)
diff --git a/backend/enterprise/license.go b/backend/enterprise/license.go
index fc50f8b194..175c5d1596 100644
--- a/backend/enterprise/license.go
+++ b/backend/enterprise/license.go
@@ -11,10 +11,10 @@ import (
"log/slog"
"math"
"slices"
- "sync/atomic"
"time"
"github.com/golang-jwt/jwt/v5"
+ "github.com/hashicorp/golang-lru/v2/expirable"
"github.com/pkg/errors"
"golang.org/x/sync/singleflight"
"google.golang.org/protobuf/encoding/protojson"
@@ -122,12 +122,7 @@ type LicenseService struct {
store *store.Store
config *Config
sfGroup singleflight.Group
- cache atomic.Pointer[cachedState]
-}
-
-type cachedState struct {
- subscription *v1pb.Subscription
- loadedAt time.Time
+ cache *expirable.LRU[string, *v1pb.Subscription]
}
// claims creates a struct that will be encoded to a JWT.
@@ -136,6 +131,7 @@ type claims struct {
ActiveInstances int `json:"instanceCount"`
Instances int `json:"instance"`
Seats int `json:"seat"`
+ HA bool `json:"ha"`
Trialing bool `json:"trialing"`
Plan string `json:"plan"`
OrgName string `json:"orgName"`
@@ -153,89 +149,76 @@ func NewLicenseService(mode common.ReleaseMode, store *store.Store) (*LicenseSer
return &LicenseService{
store: store,
config: config,
+ cache: expirable.NewLRU[string, *v1pb.Subscription](1, nil, 5*time.Second),
}, nil
}
-const cacheTTL = time.Minute
+const (
+ cacheKey = "license"
+)
// LoadSubscription will load subscription.
// If there is no license, we will return a free plan subscription without expiration time.
// If there is expired license, we will return a free plan subscription with the expiration time of the expired license.
func (s *LicenseService) LoadSubscription(ctx context.Context) *v1pb.Subscription {
- // 1. Fast path: Atomic load
- if state := s.cache.Load(); state != nil && time.Since(state.loadedAt) < cacheTTL {
- return state.subscription
+ // Fast path: cache hit (TTL handled automatically by expirable.LRU)
+ if sub, ok := s.cache.Get(cacheKey); ok {
+ return sub
}
- // 2. Slow path: Singleflight
- // key "license" ensures strict serialization of reloads
- v, err, _ := s.sfGroup.Do("license", func() (any, error) {
- // Double check after entering singleflight (optimization, though standard singleflight doesn't double-check cache implicitly)
- if state := s.cache.Load(); state != nil && time.Since(state.loadedAt) < cacheTTL {
- return state.subscription, nil
+ // Slow path: load from DB with singleflight to prevent thundering herd
+ v, _, _ := s.sfGroup.Do(cacheKey, func() (any, error) {
+ // Double check after entering singleflight
+ if sub, ok := s.cache.Get(cacheKey); ok {
+ return sub, nil
}
- // Try to load the subscription from the store.
- // We use an IIFE (Immediately Invoked Function Expression) to handle the error return flow cleanly
- // before we decide on the fallback.
- subscription, err := func() (*v1pb.Subscription, error) {
- setting, err := s.store.GetSystemSetting(ctx)
- if err != nil {
- return nil, errors.Wrapf(err, "failed to get system setting")
- }
-
- if setting.License == "" {
- return defaultFreeSubscription, nil
- }
-
- subscription, err := s.parseLicense(setting.License, setting.WorkspaceId)
- if err != nil {
- return nil, errors.Wrapf(err, "failed to parse enterprise license")
- }
-
- slog.Debug(
- "Load valid license",
- slog.String("plan", subscription.Plan.String()),
- slog.Time("expiresAt", subscription.ExpiresTime.AsTime()),
- slog.Int("activeInstances", int(subscription.ActiveInstances)),
- slog.Int("instances", int(subscription.Instances)),
- slog.Int("seats", int(subscription.Seats)),
- )
- return subscription, nil
- }()
-
- if err != nil {
- slog.Debug("failed to load enterprise license", log.BBError(err))
- subscription = defaultFreeSubscription
- }
+ subscription := s.loadSubscriptionFromDB(ctx)
+ s.cache.Add(cacheKey, subscription)
+ return subscription, nil
+ })
- // Switch to free plan if the subscription is expired.
- if isExpired(subscription) {
- subscription = &v1pb.Subscription{
- Plan: v1pb.PlanType_FREE,
- ExpiresTime: subscription.ExpiresTime,
- }
- }
+ if sub, ok := v.(*v1pb.Subscription); ok {
+ return sub
+ }
+ return defaultFreeSubscription
+}
- s.cache.Store(&cachedState{
- subscription: subscription,
- loadedAt: time.Now(),
- })
+func (s *LicenseService) loadSubscriptionFromDB(ctx context.Context) *v1pb.Subscription {
+ setting, err := s.store.GetSystemSetting(ctx)
+ if err != nil {
+ slog.Debug("failed to get system setting", log.BBError(err))
+ return defaultFreeSubscription
+ }
- return subscription, nil
- })
+ if setting.License == "" {
+ return defaultFreeSubscription
+ }
+ subscription, err := s.parseLicense(setting.License, setting.WorkspaceId)
if err != nil {
- // This should theoretically not happen as our func above suppresses errors and returns defaultFreeSubscription
- // but singleflight signature returns error.
+ slog.Debug("failed to parse enterprise license", log.BBError(err))
return defaultFreeSubscription
}
- if sub, ok := v.(*v1pb.Subscription); ok {
- return sub
+ slog.Debug(
+ "Load valid license",
+ slog.String("plan", subscription.Plan.String()),
+ slog.Time("expiresAt", subscription.ExpiresTime.AsTime()),
+ slog.Int("activeInstances", int(subscription.ActiveInstances)),
+ slog.Int("instances", int(subscription.Instances)),
+ slog.Int("seats", int(subscription.Seats)),
+ )
+
+ // Switch to free plan if the subscription is expired.
+ if isExpired(subscription) {
+ return &v1pb.Subscription{
+ Plan: v1pb.PlanType_FREE,
+ ExpiresTime: subscription.ExpiresTime,
+ }
}
- // Fallback in case of unexpected type mismatch
- return defaultFreeSubscription
+
+ return subscription
}
func isExpired(sub *v1pb.Subscription) bool {
@@ -347,8 +330,8 @@ func (s *LicenseService) StoreLicense(ctx context.Context, license string) error
return err
}
- // Invalidate cache atomically
- s.cache.Store(nil)
+ // Invalidate cache
+ s.cache.Remove(cacheKey)
return nil
}
@@ -383,6 +366,44 @@ func (s *LicenseService) GetAuditLogRetentionCutoff() *time.Time {
return &cutoff
}
+// CountActiveReplicas returns the count of active replicas.
+// A replica is considered active if it has sent a heartbeat within the last 30 seconds.
+// Returns at least 1 (the current replica is always counted).
+func (s *LicenseService) CountActiveReplicas(ctx context.Context) int {
+ count, err := s.store.CountActiveReplicas(ctx, replicaActiveWindow)
+ if err != nil {
+ slog.Warn("failed to count active replicas", log.BBError(err))
+ return 1
+ }
+ if count < 1 {
+ return 1
+ }
+ return count
+}
+
+// replicaActiveWindow is the time window for considering a replica active.
+// Replicas without heartbeats within this window are considered inactive.
+// This should be at least 3x the heartbeat interval (10s) to tolerate missed heartbeats.
+const replicaActiveWindow = 30 * time.Second
+
+// CheckReplicaLimit checks if the current replica count exceeds the allowed limit.
+// Returns error if HA is not allowed and there are multiple active replicas.
+func (s *LicenseService) CheckReplicaLimit(ctx context.Context) error {
+ if s.LoadSubscription(ctx).Ha {
+ return nil // HA license, no limit
+ }
+
+ count := s.CountActiveReplicas(ctx)
+ if count > 1 {
+ return errors.Errorf(
+ "multiple replicas detected (%d) but HA is not enabled in license",
+ count,
+ )
+ }
+
+ return nil
+}
+
func (s *LicenseService) parseLicense(license, workspaceID string) (*v1pb.Subscription, error) {
claim := &claims{}
token, err := jwt.ParseWithClaims(license, claim, func(token *jwt.Token) (any, error) {
@@ -450,5 +471,6 @@ func (s *LicenseService) parseLicense(license, workspaceID string) (*v1pb.Subscr
Plan: planType,
Trialing: claim.Trialing,
OrgName: claim.OrgName,
+ Ha: claim.HA,
}, nil
}
diff --git a/backend/generated-go/v1/actuator_service.pb.go b/backend/generated-go/v1/actuator_service.pb.go
index 73dc9633fb..c17ced1477 100644
--- a/backend/generated-go/v1/actuator_service.pb.go
+++ b/backend/generated-go/v1/actuator_service.pb.go
@@ -258,8 +258,10 @@ type ActuatorInfo struct {
EnableSample bool `protobuf:"varint,22,opt,name=enable_sample,json=enableSample,proto3" json:"enable_sample,omitempty"`
// Whether the external URL is set via command-line flag (and thus cannot be changed via UI).
ExternalUrlFromFlag bool `protobuf:"varint,23,opt,name=external_url_from_flag,json=externalUrlFromFlag,proto3" json:"external_url_from_flag,omitempty"`
- unknownFields protoimpl.UnknownFields
- sizeCache protoimpl.SizeCache
+ // The number of active replicas (servers sharing the same database).
+ ReplicaCount int32 `protobuf:"varint,24,opt,name=replica_count,json=replicaCount,proto3" json:"replica_count,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
}
func (x *ActuatorInfo) Reset() {
@@ -418,6 +420,13 @@ func (x *ActuatorInfo) GetExternalUrlFromFlag() bool {
return false
}
+func (x *ActuatorInfo) GetReplicaCount() int32 {
+ if x != nil {
+ return x.ReplicaCount
+ }
+ return 0
+}
+
// User statistics by type and state.
type ActuatorInfo_StatUser struct {
state protoimpl.MessageState `protogen:"open.v1"`
@@ -492,7 +501,7 @@ const file_v1_actuator_service_proto_rawDesc = "" +
"\x04logo\x18\x01 \x01(\fR\x04logo\"\x14\n" +
"\x12SetupSampleRequest\"\x18\n" +
"\x16GetActuatorInfoRequest\"\x14\n" +
- "\x12DeleteCacheRequest\"\xb3\a\n" +
+ "\x12DeleteCacheRequest\"\xdd\a\n" +
"\fActuatorInfo\x12\x1d\n" +
"\aversion\x18\x01 \x01(\tB\x03\xe0A\x03R\aversion\x12\"\n" +
"\n" +
@@ -513,7 +522,8 @@ const file_v1_actuator_service_proto_rawDesc = "" +
"\x18activated_instance_count\x18\x14 \x01(\x05B\x03\xe0A\x03R\x16activatedInstanceCount\x125\n" +
"\x14total_instance_count\x18\x15 \x01(\x05B\x03\xe0A\x03R\x12totalInstanceCount\x12(\n" +
"\renable_sample\x18\x16 \x01(\bB\x03\xe0A\x03R\fenableSample\x128\n" +
- "\x16external_url_from_flag\x18\x17 \x01(\bB\x03\xe0A\x03R\x13externalUrlFromFlag\x1a~\n" +
+ "\x16external_url_from_flag\x18\x17 \x01(\bB\x03\xe0A\x03R\x13externalUrlFromFlag\x12(\n" +
+ "\rreplica_count\x18\x18 \x01(\x05B\x03\xe0A\x03R\freplicaCount\x1a~\n" +
"\bStatUser\x122\n" +
"\tuser_type\x18\x01 \x01(\x0e2\x15.bytebase.v1.UserTypeR\buserType\x12(\n" +
"\x05state\x18\x02 \x01(\x0e2\x12.bytebase.v1.StateR\x05state\x12\x14\n" +
diff --git a/backend/generated-go/v1/actuator_service_equal.pb.go b/backend/generated-go/v1/actuator_service_equal.pb.go
index db8b03edf8..797fc3cfb6 100644
--- a/backend/generated-go/v1/actuator_service_equal.pb.go
+++ b/backend/generated-go/v1/actuator_service_equal.pb.go
@@ -146,5 +146,8 @@ func (x *ActuatorInfo) Equal(y *ActuatorInfo) bool {
if x.ExternalUrlFromFlag != y.ExternalUrlFromFlag {
return false
}
+ if x.ReplicaCount != y.ReplicaCount {
+ return false
+ }
return true
}
diff --git a/backend/generated-go/v1/subscription_service.pb.go b/backend/generated-go/v1/subscription_service.pb.go
index 7893ba733c..9aff0667e6 100644
--- a/backend/generated-go/v1/subscription_service.pb.go
+++ b/backend/generated-go/v1/subscription_service.pb.go
@@ -436,8 +436,10 @@ type Subscription struct {
ExpiresTime *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=expires_time,json=expiresTime,proto3" json:"expires_time,omitempty"`
Trialing bool `protobuf:"varint,6,opt,name=trialing,proto3" json:"trialing,omitempty"`
OrgName string `protobuf:"bytes,7,opt,name=org_name,json=orgName,proto3" json:"org_name,omitempty"`
- unknownFields protoimpl.UnknownFields
- sizeCache protoimpl.SizeCache
+ // Whether high availability (multiple replicas) is enabled.
+ Ha bool `protobuf:"varint,8,opt,name=ha,proto3" json:"ha,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
}
func (x *Subscription) Reset() {
@@ -519,6 +521,13 @@ func (x *Subscription) GetOrgName() string {
return ""
}
+func (x *Subscription) GetHa() bool {
+ if x != nil {
+ return x.Ha
+ }
+ return false
+}
+
// PlanConfig represents the configuration for all plans loaded from plan.yaml
type PlanConfig struct {
state protoimpl.MessageState `protogen:"open.v1"`
@@ -649,7 +658,7 @@ const file_v1_subscription_service_proto_rawDesc = "" +
"\x16GetSubscriptionRequest\"Z\n" +
"\x19UpdateSubscriptionRequest\x12\x18\n" +
"\alicense\x18\x01 \x01(\tR\alicense\x12#\n" +
- "\rallow_missing\x18\x02 \x01(\bR\fallowMissing\"\xb1\x02\n" +
+ "\rallow_missing\x18\x02 \x01(\bR\fallowMissing\"\xc6\x02\n" +
"\fSubscription\x12.\n" +
"\x04plan\x18\x01 \x01(\x0e2\x15.bytebase.v1.PlanTypeB\x03\xe0A\x03R\x04plan\x12\x19\n" +
"\x05seats\x18\x02 \x01(\x05B\x03\xe0A\x03R\x05seats\x12!\n" +
@@ -657,7 +666,8 @@ const file_v1_subscription_service_proto_rawDesc = "" +
"\x10active_instances\x18\x04 \x01(\x05B\x03\xe0A\x03R\x0factiveInstances\x12B\n" +
"\fexpires_time\x18\x05 \x01(\v2\x1a.google.protobuf.TimestampB\x03\xe0A\x03R\vexpiresTime\x12\x1f\n" +
"\btrialing\x18\x06 \x01(\bB\x03\xe0A\x03R\btrialing\x12\x1e\n" +
- "\borg_name\x18\a \x01(\tB\x03\xe0A\x03R\aorgName\"\x87\x01\n" +
+ "\borg_name\x18\a \x01(\tB\x03\xe0A\x03R\aorgName\x12\x13\n" +
+ "\x02ha\x18\b \x01(\bB\x03\xe0A\x03R\x02ha\"\x87\x01\n" +
"\n" +
"PlanConfig\x122\n" +
"\x05plans\x18\x01 \x03(\v2\x1c.bytebase.v1.PlanLimitConfigR\x05plans\x12E\n" +
diff --git a/backend/generated-go/v1/subscription_service_equal.pb.go b/backend/generated-go/v1/subscription_service_equal.pb.go
index 67e2248d5a..9c7c33488e 100644
--- a/backend/generated-go/v1/subscription_service_equal.pb.go
+++ b/backend/generated-go/v1/subscription_service_equal.pb.go
@@ -57,6 +57,9 @@ func (x *Subscription) Equal(y *Subscription) bool {
if x.OrgName != y.OrgName {
return false
}
+ if x.Ha != y.Ha {
+ return false
+ }
return true
}
diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.go
index 13bd2d98af..7e9a2bd626 100644
--- a/backend/runner/approval/runner.go
+++ b/backend/runner/approval/runner.go
@@ -49,6 +49,10 @@ func (r *Runner) Run(ctx context.Context, wg *sync.WaitGroup) {
for {
select {
case issueUID := <-r.bus.ApprovalCheckChan:
+ if err := r.licenseService.CheckReplicaLimit(ctx); err != nil {
+ slog.Warn("Approval runner skipped due to HA license restriction", log.BBError(err))
+ continue
+ }
r.processIssue(ctx, issueUID)
case <-ctx.Done():
return
diff --git a/backend/runner/cleaner/data_cleaner.go b/backend/runner/cleaner/data_cleaner.go
index 64683977dc..23e9e94ef4 100644
--- a/backend/runner/cleaner/data_cleaner.go
+++ b/backend/runner/cleaner/data_cleaner.go
@@ -7,6 +7,7 @@ import (
"time"
"github.com/bytebase/bytebase/backend/common/log"
+ "github.com/bytebase/bytebase/backend/enterprise"
"github.com/bytebase/bytebase/backend/store"
)
@@ -22,13 +23,15 @@ const (
// DataCleaner periodically cleans up expired data from the database.
type DataCleaner struct {
- store *store.Store
+ store *store.Store
+ licenseService *enterprise.LicenseService
}
// NewDataCleaner creates a new DataCleaner.
-func NewDataCleaner(store *store.Store) *DataCleaner {
+func NewDataCleaner(store *store.Store, licenseService *enterprise.LicenseService) *DataCleaner {
return &DataCleaner{
- store: store,
+ store: store,
+ licenseService: licenseService,
}
}
@@ -54,8 +57,16 @@ func (c *DataCleaner) Run(ctx context.Context, wg *sync.WaitGroup) {
for {
select {
case <-cleanupTicker.C:
+ if err := c.licenseService.CheckReplicaLimit(ctx); err != nil {
+ slog.Warn("Data cleaner skipped due to HA license restriction", log.BBError(err))
+ continue
+ }
c.cleanup(ctx)
case <-staleTicker.C:
+ if err := c.licenseService.CheckReplicaLimit(ctx); err != nil {
+ slog.Warn("Stale detection skipped due to HA license restriction", log.BBError(err))
+ continue
+ }
c.detectStaleTaskRuns(ctx)
c.detectStalePlanCheckRuns(ctx)
case <-ctx.Done():
diff --git a/backend/runner/plancheck/scheduler.go b/backend/runner/plancheck/scheduler.go
index 14ce31ca28..33a8f852c0 100644
--- a/backend/runner/plancheck/scheduler.go
+++ b/backend/runner/plancheck/scheduler.go
@@ -13,6 +13,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/component/bus"
+ "github.com/bytebase/bytebase/backend/enterprise"
storepb "github.com/bytebase/bytebase/backend/generated-go/store"
v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
"github.com/bytebase/bytebase/backend/store"
@@ -24,19 +25,21 @@ const (
)
// NewScheduler creates a new plan check scheduler.
-func NewScheduler(s *store.Store, bus *bus.Bus, executor *CombinedExecutor) *Scheduler {
+func NewScheduler(s *store.Store, bus *bus.Bus, executor *CombinedExecutor, licenseService *enterprise.LicenseService) *Scheduler {
return &Scheduler{
- store: s,
- bus: bus,
- executor: executor,
+ store: s,
+ bus: bus,
+ executor: executor,
+ licenseService: licenseService,
}
}
// Scheduler is the plan check run scheduler.
type Scheduler struct {
- store *store.Store
- bus *bus.Bus
- executor *CombinedExecutor
+ store *store.Store
+ bus *bus.Bus
+ executor *CombinedExecutor
+ licenseService *enterprise.LicenseService
}
// Run runs the scheduler.
@@ -48,8 +51,16 @@ func (s *Scheduler) Run(ctx context.Context, wg *sync.WaitGroup) {
for {
select {
case <-ticker.C:
+ if err := s.licenseService.CheckReplicaLimit(ctx); err != nil {
+ slog.Warn("Plan check scheduler skipped due to HA license restriction", log.BBError(err))
+ continue
+ }
s.runOnce(ctx)
case <-s.bus.PlanCheckTickleChan:
+ if err := s.licenseService.CheckReplicaLimit(ctx); err != nil {
+ slog.Warn("Plan check scheduler skipped due to HA license restriction", log.BBError(err))
+ continue
+ }
s.runOnce(ctx)
case <-ctx.Done():
return
diff --git a/backend/runner/schemasync/syncer.go b/backend/runner/schemasync/syncer.go
index 89a095c922..5e6f411c46 100644
--- a/backend/runner/schemasync/syncer.go
+++ b/backend/runner/schemasync/syncer.go
@@ -20,6 +20,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/component/dbfactory"
+ "github.com/bytebase/bytebase/backend/enterprise"
storepb "github.com/bytebase/bytebase/backend/generated-go/store"
"github.com/bytebase/bytebase/backend/plugin/db"
"github.com/bytebase/bytebase/backend/store"
@@ -36,10 +37,11 @@ const (
)
// NewSyncer creates a schema syncer.
-func NewSyncer(stores *store.Store, dbFactory *dbfactory.DBFactory) *Syncer {
+func NewSyncer(stores *store.Store, dbFactory *dbfactory.DBFactory, licenseService *enterprise.LicenseService) *Syncer {
return &Syncer{
- store: stores,
- dbFactory: dbFactory,
+ store: stores,
+ dbFactory: dbFactory,
+ licenseService: licenseService,
}
}
@@ -49,6 +51,7 @@ type Syncer struct {
store *store.Store
dbFactory *dbfactory.DBFactory
+ licenseService *enterprise.LicenseService
databaseSyncMap sync.Map // map[string]*store.DatabaseMessage
}
@@ -65,6 +68,10 @@ func (s *Syncer) Run(ctx context.Context, wg *sync.WaitGroup) {
for {
select {
case <-ticker.C:
+ if err := s.licenseService.CheckReplicaLimit(ctx); err != nil {
+ slog.Warn("Schema syncer skipped due to HA license restriction", log.BBError(err))
+ continue
+ }
s.trySyncAll(ctx)
case <-ctx.Done(): // if cancel() execute
return
@@ -78,6 +85,10 @@ func (s *Syncer) Run(ctx context.Context, wg *sync.WaitGroup) {
for {
select {
case <-ticker.C:
+ if err := s.licenseService.CheckReplicaLimit(ctx); err != nil {
+ slog.Warn("Database sync checker skipped due to HA license restriction", log.BBError(err))
+ continue
+ }
instances, err := s.store.ListInstances(ctx, &store.FindInstanceMessage{})
if err != nil {
slog.Error("Failed to list instance", log.BBError(err))
diff --git a/backend/runner/taskrun/pending_scheduler.go b/backend/runner/taskrun/pending_scheduler.go
index a1b775d1ff..9efa8a0e86 100644
--- a/backend/runner/taskrun/pending_scheduler.go
+++ b/backend/runner/taskrun/pending_scheduler.go
@@ -25,10 +25,18 @@ func (s *Scheduler) runPendingTaskRunsScheduler(ctx context.Context, wg *sync.Wa
for {
select {
case <-ticker.C:
+ if err := s.licenseService.CheckReplicaLimit(ctx); err != nil {
+ slog.Warn("Pending task runs scheduler skipped due to HA license restriction", log.BBError(err))
+ continue
+ }
if err := s.schedulePendingTaskRuns(ctx); err != nil {
slog.Error("failed to schedule pending task runs", log.BBError(err))
}
case <-s.bus.TaskRunTickleChan:
+ if err := s.licenseService.CheckReplicaLimit(ctx); err != nil {
+ slog.Warn("Pending task runs scheduler skipped due to HA license restriction", log.BBError(err))
+ continue
+ }
if err := s.schedulePendingTaskRuns(ctx); err != nil {
slog.Error("failed to schedule pending task runs", log.BBError(err))
}
diff --git a/backend/runner/taskrun/running_scheduler.go b/backend/runner/taskrun/running_scheduler.go
index 4c95bfd6be..5aab9a9471 100644
--- a/backend/runner/taskrun/running_scheduler.go
+++ b/backend/runner/taskrun/running_scheduler.go
@@ -29,10 +29,18 @@ func (s *Scheduler) runRunningTaskRunsScheduler(ctx context.Context, wg *sync.Wa
for {
select {
case <-ticker.C:
+ if err := s.licenseService.CheckReplicaLimit(ctx); err != nil {
+ slog.Warn("Running task runs scheduler skipped due to HA license restriction", log.BBError(err))
+ continue
+ }
if err := s.scheduleRunningTaskRuns(ctx); err != nil {
slog.Error("failed to schedule running task runs", log.BBError(err))
}
case <-s.bus.TaskRunTickleChan:
+ if err := s.licenseService.CheckReplicaLimit(ctx); err != nil {
+ slog.Warn("Running task runs scheduler skipped due to HA license restriction", log.BBError(err))
+ continue
+ }
if err := s.scheduleRunningTaskRuns(ctx); err != nil {
slog.Error("failed to schedule running task runs", log.BBError(err))
}
diff --git a/backend/runner/taskrun/scheduler.go b/backend/runner/taskrun/scheduler.go
index 7dbf548d5a..343b3a31a1 100644
--- a/backend/runner/taskrun/scheduler.go
+++ b/backend/runner/taskrun/scheduler.go
@@ -12,6 +12,7 @@ import (
"github.com/bytebase/bytebase/backend/component/bus"
"github.com/bytebase/bytebase/backend/component/config"
"github.com/bytebase/bytebase/backend/component/webhook"
+ "github.com/bytebase/bytebase/backend/enterprise"
storepb "github.com/bytebase/bytebase/backend/generated-go/store"
"github.com/bytebase/bytebase/backend/store"
)
@@ -25,6 +26,7 @@ type Scheduler struct {
store *store.Store
bus *bus.Bus
webhookManager *webhook.Manager
+ licenseService *enterprise.LicenseService
executorMap map[storepb.Task_Type]Executor
profile *config.Profile
}
@@ -34,12 +36,14 @@ func NewScheduler(
store *store.Store,
bus *bus.Bus,
webhookManager *webhook.Manager,
+ licenseService *enterprise.LicenseService,
profile *config.Profile,
) *Scheduler {
return &Scheduler{
store: store,
bus: bus,
webhookManager: webhookManager,
+ licenseService: licenseService,
profile: profile,
executorMap: map[storepb.Task_Type]Executor{},
}
diff --git a/backend/server/server.go b/backend/server/server.go
index 70cb740691..c925438a4d 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -201,20 +201,20 @@ func NewServer(ctx context.Context, profile *config.Profile) (*Server, error) {
// Configure echo server.
s.echoServer = echo.New()
- s.schemaSyncer = schemasync.NewSyncer(stores, s.dbFactory)
+ s.schemaSyncer = schemasync.NewSyncer(stores, s.dbFactory, s.licenseService)
s.approvalRunner = approval.NewRunner(stores, s.bus, s.webhookManager, s.licenseService)
- s.taskScheduler = taskrun.NewScheduler(stores, s.bus, s.webhookManager, profile)
+ s.taskScheduler = taskrun.NewScheduler(stores, s.bus, s.webhookManager, s.licenseService, profile)
s.taskScheduler.Register(storepb.Task_DATABASE_CREATE, taskrun.NewDatabaseCreateExecutor(stores, s.dbFactory, s.schemaSyncer))
s.taskScheduler.Register(storepb.Task_DATABASE_MIGRATE, taskrun.NewDatabaseMigrateExecutor(stores, s.dbFactory, s.bus, s.schemaSyncer, profile))
s.taskScheduler.Register(storepb.Task_DATABASE_EXPORT, taskrun.NewDataExportExecutor(stores, s.dbFactory, s.licenseService))
combinedExecutor := plancheck.NewCombinedExecutor(stores, sheetManager, s.dbFactory)
- s.planCheckScheduler = plancheck.NewScheduler(stores, s.bus, combinedExecutor)
+ s.planCheckScheduler = plancheck.NewScheduler(stores, s.bus, combinedExecutor, s.licenseService)
s.notifyListener = notifylistener.NewListener(stores.GetDB(), s.bus)
// Data cleaner
- s.dataCleaner = cleaner.NewDataCleaner(stores)
+ s.dataCleaner = cleaner.NewDataCleaner(stores, s.licenseService)
// Heartbeat runner
s.heartbeatRunner = heartbeat.NewRunner(stores, profile)
diff --git a/backend/store/replica_heartbeat.go b/backend/store/replica_heartbeat.go
index 52771be508..b0ea48c450 100644
--- a/backend/store/replica_heartbeat.go
+++ b/backend/store/replica_heartbeat.go
@@ -47,3 +47,24 @@ func (s *Store) DeleteStaleReplicaHeartbeats(ctx context.Context, olderThan time
}
return result.RowsAffected()
}
+
+// CountActiveReplicas returns the count of replicas with recent heartbeats.
+// The `within` parameter defines the time window for considering a replica active.
+// Replicas without heartbeats within this window are considered inactive.
+func (s *Store) CountActiveReplicas(ctx context.Context, within time.Duration) (int, error) {
+ q := qb.Q().Space(`
+ SELECT COUNT(*) FROM replica_heartbeat
+ WHERE last_heartbeat > now() - ?::INTERVAL
+ `, within.String())
+
+ query, args, err := q.ToSQL()
+ if err != nil {
+ return 0, errors.Wrapf(err, "failed to build sql")
+ }
+
+ var count int
+ if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan(&count); err != nil {
+ return 0, errors.Wrapf(err, "failed to count active replicas")
+ }
+ return count, nil
+}
diff --git a/frontend/src/components/BannersWrapper.vue b/frontend/src/components/BannersWrapper.vue
index 0ac57901cc..dc469faf40 100644
--- a/frontend/src/components/BannersWrapper.vue
+++ b/frontend/src/components/BannersWrapper.vue
@@ -3,6 +3,8 @@
<BannerDemo v-if="shouldShowDemoBanner" />
<BannerSubscription v-if="shouldShowSubscriptionBanner" />
<BannerExternalUrl v-if="shouldShowExternalUrlBanner" />
+ <!-- TODO(ed): remove the isDev when HA is ready -->
+ <BannerHA v-if="isDev() && shouldShowHABanner" />
<BannerAnnouncement />
</template>
@@ -19,14 +21,15 @@ import { isDev } from "@/utils";
import BannerAnnouncement from "@/views/BannerAnnouncement.vue";
import BannerDemo from "@/views/BannerDemo.vue";
import BannerExternalUrl from "@/views/BannerExternalUrl.vue";
+import BannerHA from "@/views/BannerHA.vue";
import BannerSubscription from "@/views/BannerSubscription.vue";
import BannerUpgradeSubscription from "@/views/BannerUpgradeSubscription.vue";
const actuatorStore = useActuatorV1Store();
const subscriptionStore = useSubscriptionV1Store();
-const { needConfigureExternalUrl } = storeToRefs(actuatorStore);
-const { isExpired, isTrialing, currentPlan, daysBeforeExpire } =
+const { needConfigureExternalUrl, replicaCount } = storeToRefs(actuatorStore);
+const { isExpired, isTrialing, currentPlan, daysBeforeExpire, isHAAllowed } =
storeToRefs(subscriptionStore);
const shouldShowDemoBanner = computed(() => {
@@ -46,4 +49,8 @@ const shouldShowSubscriptionBanner = computed(() => {
const shouldShowExternalUrlBanner = computed(() => {
return !isDev() && needConfigureExternalUrl.value;
});
+
+const shouldShowHABanner = computed(() => {
+ return !isHAAllowed.value && replicaCount.value > 1;
+});
</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 37a19ee466..7402349824 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -406,7 +406,8 @@
"deploy": "Self Host",
"cloud": "Cloud",
"request-demo": "Book a 30-minute product demo.",
- "external-url": "Bytebase has not configured --external-url"
+ "external-url": "Bytebase has not configured --external-url",
+ "ha-not-licensed": "Multiple replicas detected without HA license. Backend runners are disabled."
},
"bbkit": {
"confirm-button": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 58714b7fe6..e44b0b5fa5 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -406,7 +406,8 @@
"deploy": "Auto Hospedaje",
"cloud": "Cloud",
"request-demo": "Reserva una demo de producto de 30 minutos.",
- "external-url": "Bytebase no ha configurado --external-url"
+ "external-url": "Bytebase no ha configurado --external-url",
+ "ha-not-licensed": "Se detectaron múltiples réplicas sin licencia HA. Los ejecutores del backend están deshabilitados."
},
"bbkit": {
"confirm-button": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 0ea557b8e0..d513a445bd 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -406,7 +406,8 @@
"deploy": "ローカル展開",
"cloud": "クラウドサービス",
"request-demo": "30 分間の製品デモを予約してください。",
- "external-url": "Bytebase は --extern-url を設定していません"
+ "external-url": "Bytebase は --extern-url を設定していません",
+ "ha-not-licensed": "HAライセンスなしで複数のレプリカが検出されました。バックエンドランナーは無効です。"
},
"bbkit": {
"confirm-button": {
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index a244fddb93..d90bcaed4a 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -406,7 +406,8 @@
"deploy": "Tự lưu trữ",
"cloud": "Đám mây",
"request-demo": "Đặt lịch giới thiệu sản phẩm 30 phút.",
- "external-url": "Bytebase chưa được cấu hình --external-url"
+ "external-url": "Bytebase chưa được cấu hình --external-url",
+ "ha-not-licensed": "Phát hiện nhiều bản sao mà không có giấy phép HA. Trình chạy backend đã bị tắt."
},
"bbkit": {
"confirm-button": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index e66ddf169c..72ce025017 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -406,7 +406,8 @@
"deploy": "本地部署",
"cloud": "云服务",
"request-demo": "预约一个 30 分钟的产品演示。",
- "external-url": "Bytebase 还没有配置 --external-url"
+ "external-url": "Bytebase 还没有配置 --external-url",
+ "ha-not-licensed": "检测到多个副本但没有 HA 许可证。后端任务运行器已禁用。"
},
"bbkit": {
"confirm-button": {
diff --git a/frontend/src/store/modules/v1/actuator.ts b/frontend/src/store/modules/v1/actuator.ts
index 2967cf9879..e6e0a66dac 100644
--- a/frontend/src/store/modules/v1/actuator.ts
+++ b/frontend/src/store/modules/v1/actuator.ts
@@ -108,6 +108,8 @@ export const useActuatorV1Store = defineStore("actuator_v1", () => {
() => serverInfo.value?.totalInstanceCount ?? 0
);
+ const replicaCount = computed(() => serverInfo.value?.replicaCount ?? 1);
+
const inactiveUserCount = computed(() => {
return (serverInfo.value?.userStats ?? []).reduce((count, stat) => {
if (stat.state === State.DELETED) {
@@ -274,6 +276,7 @@ export const useActuatorV1Store = defineStore("actuator_v1", () => {
hasNewRelease,
activatedInstanceCount,
totalInstanceCount,
+ replicaCount,
inactiveUserCount,
quickStartEnabled,
// Actions
diff --git a/frontend/src/store/modules/v1/setting.ts b/frontend/src/store/modules/v1/setting.ts
index 3fd4d3db3e..8648c34657 100644
--- a/frontend/src/store/modules/v1/setting.ts
+++ b/frontend/src/store/modules/v1/setting.ts
@@ -9,7 +9,6 @@ import { settingNamePrefix } from "@/store/modules/v1/common";
import {
type DataClassificationSetting_DataClassificationConfig,
GetSettingRequestSchema,
- ListSettingsRequestSchema,
type Setting,
Setting_SettingName,
SettingSchema,
@@ -19,7 +18,6 @@ import {
type WorkspaceProfileSetting,
WorkspaceProfileSettingSchema,
} from "@/types/proto-es/v1/setting_service_pb";
-import { hasWorkspacePermissionV2 } from "@/utils";
import { useActuatorV1Store } from "./actuator";
export const useSettingV1Store = defineStore("setting_v1", () => {
@@ -92,17 +90,6 @@ export const useSettingV1Store = defineStore("setting_v1", () => {
return fetchSettingByName(name, silent);
};
- const fetchSettingList = async () => {
- if (!hasWorkspacePermissionV2("bb.settings.list")) {
- return;
- }
- const request = create(ListSettingsRequestSchema, {});
- const response = await settingServiceClientConnect.listSettings(request);
- for (const setting of response.settings) {
- settingMapByName.set(setting.name, setting);
- }
- };
-
const upsertSetting = async ({
name,
value,
@@ -166,7 +153,6 @@ export const useSettingV1Store = defineStore("setting_v1", () => {
fetchSettingByName,
getSettingByName,
getOrFetchSettingByName,
- fetchSettingList,
upsertSetting,
updateWorkspaceProfile,
};
diff --git a/frontend/src/store/modules/v1/subscription.ts b/frontend/src/store/modules/v1/subscription.ts
index a6baecb81a..b941a9b24a 100644
--- a/frontend/src/store/modules/v1/subscription.ts
+++ b/frontend/src/store/modules/v1/subscription.ts
@@ -2,7 +2,7 @@ import { create } from "@bufbuild/protobuf";
import dayjs from "dayjs";
import { defineStore } from "pinia";
import type { Ref } from "vue";
-import { computed } from "vue";
+import { computed, ref } from "vue";
import { subscriptionServiceClientConnect } from "@/connect";
import {
hasFeature as checkFeature,
@@ -28,197 +28,226 @@ import {
// Default is 7 days.
export const LICENSE_EXPIRATION_THRESHOLD = 7;
-interface SubscriptionState {
- subscription: Subscription | undefined;
- trialingDays: number;
-}
-
-export const useSubscriptionV1Store = defineStore("subscription_v1", {
- state: (): SubscriptionState => ({
- subscription: undefined,
- trialingDays: 14,
- }),
- getters: {
- instanceCountLimit(state): number {
- let limit = state.subscription?.instances ?? 0;
- if (limit > 0) {
- return limit;
- }
+export const useSubscriptionV1Store = defineStore("subscription_v1", () => {
+ // State
+ const subscription = ref<Subscription | undefined>(undefined);
+ const trialingDays = ref(14);
- limit =
- PLANS.find((plan) => plan.type === this.currentPlan)
- ?.maximumInstanceCount ?? 0;
- if (limit < 0) {
- const instanceLimitInLicense = state.subscription?.instances ?? 0;
- if (instanceLimitInLicense > 0) {
- return instanceLimitInLicense;
- }
- return Number.MAX_VALUE;
- }
+ // Getters
+ const currentPlan = computed(() => {
+ if (!subscription.value) {
+ return PlanType.FREE;
+ }
+ return subscription.value.plan;
+ });
+
+ const isFreePlan = computed(() => currentPlan.value === PlanType.FREE);
+
+ const instanceCountLimit = computed(() => {
+ let limit = subscription.value?.instances ?? 0;
+ if (limit > 0) {
return limit;
- },
- userCountLimit(state): number {
- let limit =
- PLANS.find((plan) => plan.type === this.currentPlan)
- ?.maximumSeatCount ?? 0;
- if (limit < 0) {
- limit = Number.MAX_VALUE;
- }
+ }
- const seatCount = state.subscription?.seats ?? 0;
- if (seatCount < 0) {
- return Number.MAX_VALUE;
- }
- if (seatCount === 0) {
- return limit;
- }
- return seatCount;
- },
- instanceLicenseCount(state): number {
- const count = state.subscription?.activeInstances ?? 0;
- if (count < 0) {
- return Number.MAX_VALUE;
- }
- return count;
- },
- currentPlan(state): PlanType {
- if (!state.subscription) {
- return PlanType.FREE;
- }
- return state.subscription.plan;
- },
- isFreePlan(): boolean {
- return this.currentPlan == PlanType.FREE;
- },
- expireAt(state): string {
- if (
- !state.subscription ||
- !state.subscription.expiresTime ||
- this.isFreePlan
- ) {
- return "";
+ limit =
+ PLANS.find((plan) => plan.type === currentPlan.value)
+ ?.maximumInstanceCount ?? 0;
+ if (limit < 0) {
+ const instanceLimitInLicense = subscription.value?.instances ?? 0;
+ if (instanceLimitInLicense > 0) {
+ return instanceLimitInLicense;
}
+ return Number.MAX_VALUE;
+ }
+ return limit;
+ });
- return dayjs(
- getDateForPbTimestampProtoEs(state.subscription.expiresTime)
- ).format("YYYY/MM/DD HH:mm:ss");
- },
- isTrialing(state): boolean {
- return !!state.subscription?.trialing;
- },
- isExpired(state): boolean {
- if (
- !state.subscription ||
- !state.subscription.expiresTime ||
- this.isFreePlan
- ) {
- return false;
- }
- return dayjs(
- getDateForPbTimestampProtoEs(state.subscription.expiresTime)
- ).isBefore(new Date());
- },
- daysBeforeExpire(state): number {
- if (
- !state.subscription ||
- !state.subscription.expiresTime ||
- this.isFreePlan
- ) {
- return -1;
- }
+ const userCountLimit = computed(() => {
+ let limit =
+ PLANS.find((plan) => plan.type === currentPlan.value)?.maximumSeatCount ??
+ 0;
+ if (limit < 0) {
+ limit = Number.MAX_VALUE;
+ }
- const expiresTime = dayjs(
- getDateForPbTimestampProtoEs(state.subscription.expiresTime)
- );
- return Math.max(expiresTime.diff(new Date(), "day"), 0);
- },
- showTrial(state): boolean {
- if (!this.isSelfHostLicense) {
- return false;
- }
- if (!state.subscription || this.isFreePlan) {
- return true;
- }
- return false;
- },
- isSelfHostLicense(): boolean {
- return import.meta.env.MODE.toLowerCase() !== "release-aws";
- },
- purchaseLicenseUrl(): string {
- return import.meta.env.BB_PURCHASE_LICENSE_URL;
- },
- },
- actions: {
- setSubscription(subscription: Subscription) {
- this.subscription = subscription;
- },
- hasFeature(feature: PlanFeature) {
- if (this.isExpired) {
- return false;
- }
- return checkFeature(this.currentPlan, feature);
- },
- hasInstanceFeature(
- feature: PlanFeature,
- instance: Instance | InstanceResource | undefined = undefined
+ const seatCount = subscription.value?.seats ?? 0;
+ if (seatCount < 0) {
+ return Number.MAX_VALUE;
+ }
+ if (seatCount === 0) {
+ return limit;
+ }
+ return seatCount;
+ });
+
+ const instanceLicenseCount = computed(() => {
+ const count = subscription.value?.activeInstances ?? 0;
+ if (count < 0) {
+ return Number.MAX_VALUE;
+ }
+ return count;
+ });
+
+ const expireAt = computed(() => {
+ if (
+ !subscription.value ||
+ !subscription.value.expiresTime ||
+ isFreePlan.value
) {
- // For FREE plan, don't check instance activation
- if (this.currentPlan === PlanType.FREE) {
- return this.hasFeature(feature);
- }
+ return "";
+ }
- // If no instance provided or feature is not instance-limited
- if (!instance || !instanceLimitFeature.has(feature)) {
- return this.hasFeature(feature);
- }
+ return dayjs(
+ getDateForPbTimestampProtoEs(subscription.value.expiresTime)
+ ).format("YYYY/MM/DD HH:mm:ss");
+ });
+
+ const isTrialing = computed(() => !!subscription.value?.trialing);
- return checkInstanceFeature(
- this.currentPlan,
- feature,
- instance.activation
- );
- },
- instanceMissingLicense(
- feature: PlanFeature,
- instance: Instance | InstanceResource | undefined = undefined
+ const isExpired = computed(() => {
+ if (
+ !subscription.value ||
+ !subscription.value.expiresTime ||
+ isFreePlan.value
) {
- // Only relevant for instance-limited features
- if (!instanceLimitFeature.has(feature)) {
- return false;
- }
- if (!instance) {
- return false;
- }
- // Feature is available in plan but instance is not activated
- return this.hasFeature(feature) && !instance.activation;
- },
- currentPlanGTE(plan: PlanType): boolean {
- return this.currentPlan >= plan;
- },
- getMinimumRequiredPlan(feature: PlanFeature): PlanType {
- return getMinimumRequiredPlan(feature);
- },
- async fetchSubscription() {
- try {
- const request = create(GetSubscriptionRequestSchema, {});
- const subscription =
- await subscriptionServiceClientConnect.getSubscription(request);
- this.setSubscription(subscription);
- return subscription;
- } catch (e) {
- console.error(e);
- }
- },
- async patchSubscription(license: string) {
- const request = create(UpdateSubscriptionRequestSchema, {
- license,
- });
- const subscription =
- await subscriptionServiceClientConnect.updateSubscription(request);
- this.setSubscription(subscription);
- return subscription;
- },
- },
+ return false;
+ }
+ return dayjs(
+ getDateForPbTimestampProtoEs(subscription.value.expiresTime)
+ ).isBefore(new Date());
+ });
+
+ const daysBeforeExpire = computed(() => {
+ if (
+ !subscription.value ||
+ !subscription.value.expiresTime ||
+ isFreePlan.value
+ ) {
+ return -1;
+ }
+
+ const expiresTime = dayjs(
+ getDateForPbTimestampProtoEs(subscription.value.expiresTime)
+ );
+ return Math.max(expiresTime.diff(new Date(), "day"), 0);
+ });
+
+ const isSelfHostLicense = computed(
+ () => import.meta.env.MODE.toLowerCase() !== "release-aws"
+ );
+
+ const showTrial = computed(() => {
+ if (!isSelfHostLicense.value) {
+ return false;
+ }
+ if (!subscription.value || isFreePlan.value) {
+ return true;
+ }
+ return false;
+ });
+
+ const isHAAllowed = computed(() => subscription.value?.ha ?? false);
+
+ const purchaseLicenseUrl = computed(
+ () => import.meta.env.BB_PURCHASE_LICENSE_URL as string
+ );
+
+ // Actions
+ const setSubscription = (sub: Subscription) => {
+ subscription.value = sub;
+ };
+
+ const hasFeature = (feature: PlanFeature) => {
+ if (isExpired.value) {
+ return false;
+ }
+ return checkFeature(currentPlan.value, feature);
+ };
+
+ const hasInstanceFeature = (
+ feature: PlanFeature,
+ instance: Instance | InstanceResource | undefined = undefined
+ ) => {
+ // For FREE plan, don't check instance activation
+ if (currentPlan.value === PlanType.FREE) {
+ return hasFeature(feature);
+ }
+
+ // If no instance provided or feature is not instance-limited
+ if (!instance || !instanceLimitFeature.has(feature)) {
+ return hasFeature(feature);
+ }
+
+ return checkInstanceFeature(
+ currentPlan.value,
+ feature,
+ instance.activation
+ );
+ };
+
+ const instanceMissingLicense = (
+ feature: PlanFeature,
+ instance: Instance | InstanceResource | undefined = undefined
+ ) => {
+ // Only relevant for instance-limited features
+ if (!instanceLimitFeature.has(feature)) {
+ return false;
+ }
+ if (!instance) {
+ return false;
+ }
+ // Feature is available in plan but instance is not activated
+ return hasFeature(feature) && !instance.activation;
+ };
+
+ const fetchSubscription = async () => {
+ try {
+ const request = create(GetSubscriptionRequestSchema, {});
+ const sub =
+ await subscriptionServiceClientConnect.getSubscription(request);
+ setSubscription(sub);
+ return sub;
+ } catch (e) {
+ console.error(e);
+ }
+ };
+
+ const patchSubscription = async (license: string) => {
+ const request = create(UpdateSubscriptionRequestSchema, {
+ license,
+ });
+ const sub =
+ await subscriptionServiceClientConnect.updateSubscription(request);
+ setSubscription(sub);
+ return sub;
+ };
+
+ return {
+ // State
+ subscription,
+ trialingDays,
+ // Getters
+ currentPlan,
+ isFreePlan,
+ instanceCountLimit,
+ userCountLimit,
+ instanceLicenseCount,
+ expireAt,
+ isTrialing,
+ isExpired,
+ daysBeforeExpire,
+ isSelfHostLicense,
+ showTrial,
+ isHAAllowed,
+ purchaseLicenseUrl,
+ // Actions
+ hasFeature,
+ hasInstanceFeature,
+ instanceMissingLicense,
+ getMinimumRequiredPlan,
+ fetchSubscription,
+ patchSubscription,
+ };
});
export const hasFeature = (feature: PlanFeature) => {
diff --git a/frontend/src/types/proto-es/v1/actuator_service_pb.d.ts b/frontend/src/types/proto-es/v1/actuator_service_pb.d.ts
index 5b92c5cd40..cb49a818af 100644
--- a/frontend/src/types/proto-es/v1/actuator_service_pb.d.ts
+++ b/frontend/src/types/proto-es/v1/actuator_service_pb.d.ts
@@ -221,6 +221,13 @@ export declare type ActuatorInfo = Message<"bytebase.v1.ActuatorInfo"> & {
* @generated from field: bool external_url_from_flag = 23;
*/
externalUrlFromFlag: boolean;
+
+ /**
+ * The number of active replicas (servers sharing the same database).
+ *
+ * @generated from field: int32 replica_count = 24;
+ */
+ replicaCount: number;
};
/**
diff --git a/frontend/src/types/proto-es/v1/actuator_service_pb.js b/frontend/src/types/proto-es/v1/actuator_service_pb.js
index d42c98984e..65c04ab90b 100644
--- a/frontend/src/types/proto-es/v1/actuator_service_pb.js
+++ b/frontend/src/types/proto-es/v1/actuator_service_pb.js
@@ -15,7 +15,7 @@ import { file_v1_user_service } from "./user_service_pb";
* Describes the file v1/actuator_service.proto.
*/
export const file_v1_actuator_service = /*@__PURE__*/
- fileDesc("Chl2MS9hY3R1YXRvcl9zZXJ2aWNlLnByb3RvEgtieXRlYmFzZS52MSIbChlHZXRSZXNvdXJjZVBhY2thZ2VSZXF1ZXN0Ih8KD1Jlc291cmNlUGFja2FnZRIMCgRsb2dvGAEgASgMIhQKElNldHVwU2FtcGxlUmVxdWVzdCIYChZHZXRBY3R1YXRvckluZm9SZXF1ZXN0IhQKEkRlbGV0ZUNhY2hlUmVxdWVzdCK1BQoMQWN0dWF0b3JJbmZvEhQKB3ZlcnNpb24YASABKAlCA+BBAxIXCgpnaXRfY29tbWl0GAIgASgJQgPgQQMSFQoIcmVhZG9ubHkYAyABKAhCA+BBAxIRCgRzYWFzGAQgASgIQgPgQQMSEQoEZGV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zLmNyZWF0ZZDqMAGC0+STAhoiGC92MS9hY3R1YXRvcjpzZXR1cFNhbXBsZRJmCgtEZWxldGVDYWNoZRIfLmJ5dGViYXNlLnYxLkRlbGV0ZUNhY2hlUmVxdWVzdBoWLmdvb2dsZS5wcm90b2J1Zi5FbXB0eSIegOowAYLT5JMCFCoSL3YxL2FjdHVhdG9yL2NhY2hlEoEBChJHZXRSZXNvdXJjZVBhY2thZ2USJi5ieXRlYmFzZS52MS5HZXRSZXNvdXJjZVBhY2thZ2VSZXF1ZXN0GhwuYnl0ZWJhc2UudjEuUmVzb3VyY2VQYWNrYWdlIiXaQQCA6jABgtPkkwIYEhYvdjEvYWN0dWF0b3IvcmVzb3VyY2VzQqoBCg9jb20uYnl0ZWJhc2UudjFCFEFjdHVhdG9yU2VydmljZVByb3RvUAFaNGdpdGh1Yi5jb20vYnl0ZWJhc2UvYnl0ZWJhc2UvYmFja2VuZC9nZW5lcmF0ZWQtZ28vdjGiAgNCWFiqAgtCeXRlYmFzZS5WMcoCC0J5dGViYXNlXFYx4gIXQnl0ZWJhc2VcVjFcR1BCTWV0YWRhdGHqAgxCeXRlYmFzZTo6VjFiBnByb3RvMw", [file_google_api_annotations, file_google_api_client, file_google_api_field_behavior, file_google_protobuf_empty, file_google_protobuf_timestamp, file_v1_annotation, file_v1_common, file_v1_user_service]);
+ fileDesc("Chl2MS9hY3R1YXRvcl9zZXJ2aWNlLnByb3RvEgtieXRlYmFzZS52MSIbChlHZXRSZXNvdXJjZVBhY2thZ2VSZXF1ZXN0Ih8KD1Jlc291cmNlUGFja2FnZRIMCgRsb2dvGAEgASgMIhQKElNldHVwU2FtcGxlUmVxdWVzdCIYChZHZXRBY3R1YXRvckluZm9SZXF1ZXN0IhQKEkRlbGV0ZUNhY2hlUmVxdWVzdCLRBQoMQWN0dWF0b3JJbmZvEhQKB3ZlcnNpb24YASABKAlCA+BBAxIXCgpnaXRfY29tbWl0GAIgASgJQgPgQQMSFQoIcmVhZG9ubHkYAyABK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FzZS52MS5TZXR1cFNhbXBsZVJlcXVlc3QaFi5nb29nbGUucHJvdG9idWYuRW1wdHkiOorqMBJiYi5wcm9qZWN0cy5jcmVhdGWQ6jABgtPkkwIaIhgvdjEvYWN0dWF0b3I6c2V0dXBTYW1wbGUSZgoLRGVsZXRlQ2FjaGUSHy5ieXRlYmFzZS52MS5EZWxldGVDYWNoZVJlcXVlc3QaFi5nb29nbGUucHJvdG9idWYuRW1wdHkiHoDqMAGC0+STAhQqEi92MS9hY3R1YXRvci9jYWNoZRKBAQoSR2V0UmVzb3VyY2VQYWNrYWdlEiYuYnl0ZWJhc2UudjEuR2V0UmVzb3VyY2VQYWNrYWdlUmVxdWVzdBocLmJ5dGViYXNlLnYxLlJlc291cmNlUGFja2FnZSIl2kEAgOowAYLT5JMCGBIWL3YxL2FjdHVhdG9yL3Jlc291cmNlc0KqAQoPY29tLmJ5dGViYXNlLnYxQhRBY3R1YXRvclNlcnZpY2VQcm90b1ABWjRnaXRodWIuY29tL2J5dGViYXNlL2J5dGViYXNlL2JhY2tlbmQvZ2VuZXJhdGVkLWdvL3YxogIDQlhYqgILQnl0ZWJhc2UuVjHKAgtCeXRlYmFzZVxWMeICF0J5dGViYXNlXFYxXEdQQk1ldGFkYXRh6gIMQnl0ZWJhc2U6OlYxYgZwcm90bzM", [file_google_api_annotations, file_google_api_client, file_google_api_field_behavior, file_google_protobuf_empty, file_google_protobuf_timestamp, file_v1_annotation, file_v1_common, file_v1_user_service]);
/**
* Describes the message bytebase.v1.GetResourcePackageRequest.
diff --git a/frontend/src/types/proto-es/v1/subscription_service_pb.d.ts b/frontend/src/types/proto-es/v1/subscription_service_pb.d.ts
index b78fe60e4f..71eed039e5 100644
--- a/frontend/src/types/proto-es/v1/subscription_service_pb.d.ts
+++ b/frontend/src/types/proto-es/v1/subscription_service_pb.d.ts
@@ -85,6 +85,13 @@ export declare type Subscription = Message<"bytebase.v1.Subscription"> & {
* @generated from field: string org_name = 7;
*/
orgName: string;
+
+ /**
+ * Whether high availability (multiple replicas) is enabled.
+ *
+ * @generated from field: bool ha = 8;
+ */
+ ha: boolean;
};
/**
diff --git a/frontend/src/types/proto-es/v1/subscription_service_pb.js b/frontend/src/types/proto-es/v1/subscription_service_pb.js
index 6f7afa11d9..6c9cc3f191 100644
--- a/frontend/src/types/proto-es/v1/subscription_service_pb.js
+++ b/frontend/src/types/proto-es/v1/subscription_service_pb.js
@@ -13,7 +13,7 @@ import { file_v1_annotation } from "./annotation_pb";
* Describes the file v1/subscription_service.proto.
*/
export const file_v1_subscription_service = /*@__PURE__*/
- fileDesc("Ch12MS9zdWJzY3JpcHRpb25fc2VydmljZS5wcm90bxILYnl0ZWJhc2UudjEiGAoWR2V0U3Vic2NyaXB0aW9uUmVxdWVzdCJDChlVcGRhdGVTdWJzY3JpcHRpb25SZXF1ZXN0Eg8KB2xpY2Vuc2UYASABKAkSFQoNYWxsb3dfbWlzc2luZxgCIAEoCCLoAQoMU3Vic2NyaXB0aW9uEigKBHBsYW4YASABKA4yFS5ieXRlYmFzZS52MS5QbGFuVHlwZUID4EEDEhIKBXNlYXRzGAIgASgFQgPgQQMSFgoJaW5zdGFuY2VzGAMgASgFQgPgQQMSHQoQYWN0aXZlX2luc3RhbmNlcxgEIAEoBUID4EEDEjUKDGV4cGlyZXNfdGltZRgFIAEoCzIaLmdvb2dsZS5wcm90b2J1Zi5UaW1lc3RhbXBCA+BBAxIVCgh0cmlhbGluZxgGIAEoCEID4EEDEhUKCG9yZ19uYW1lGAcgASgJQgPgQQMibgoKUGxhbkNvbmZpZxIrCgVwbGFucxgBIAMoCzIcLmJ5dGViYXNlLnYxLlBsYW5MaW1pdENvbmZpZxIzChFpbnN0YW5jZV9mZWF0dXJlcxgCIAMoDjIYLmJ5dGViYXNlLnYxLlBsYW5GZWF0dXJlIp4BCg9QbGFuTGltaXRDb25maWcSIwoEdHlwZRgBIAEoDjIVLmJ5dGViYXNlLnYxLlBsYW5UeXBlEh4KFm1heGltdW1faW5zdGFuY2Vf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fV0FURVJNQVJLEEESIgoeRkVBVFVSRV9ST0FETUFQX1BSSU9SSVRJWkFUSU9OEEISFgoSRkVBVFVSRV9DVVNUT01fTVNBEEMSHQoZRkVBVFVSRV9DT01NVU5JVFlfU1VQUE9SVBBEEhkKFUZFQVRVUkVfRU1BSUxfU1VQUE9SVBBFEiYKIkZFQVRVUkVfREVESUNBVEVEX1NVUFBPUlRfV0lUSF9TTEEQRjKlAgoTU3Vic2NyaXB0aW9uU2VydmljZRJyCg9HZXRTdWJzY3JpcHRpb24SIy5ieXRlYmFzZS52MS5HZXRTdWJzY3JpcHRpb25SZXF1ZXN0GhkuYnl0ZWJhc2UudjEuU3Vic2NyaXB0aW9uIh/aQQCA6jABgtPkkwISEhAvdjEvc3Vic2NyaXB0aW9uEpkBChJVcGRhdGVTdWJzY3JpcHRpb24SJi5ieXRlYmFzZS52MS5VcGRhdGVTdWJzY3JpcHRpb25SZXF1ZXN0GhkuYnl0ZWJhc2UudjEuU3Vic2NyaXB0aW9uIkDaQQVwYXRjaIrqMA9iYi5zZXR0aW5ncy5zZXSQ6jABgtPkkwIbOgdsaWNlbnNlMhAvdjEvc3Vic2NyaXB0aW9uQq4BCg9jb20uYnl0ZWJhc2UudjFCGFN1YnNjcmlwdGlvblNlcnZpY2VQcm90b1ABWjRnaXRodWIuY29tL2J5dGViYXNlL2J5dGViYXNlL2JhY2tlbmQvZ2VuZXJhdGVkLWdvL3YxogIDQlhYqgILQnl0ZWJhc2UuVjHKAgtCeXRlYmFzZVxWMeICF0J5dGViYXNlXFYxXEdQQk1ldGFkYXRh6gIMQnl0ZWJhc2U6OlYxYgZwcm90bzM", [file_google_api_annotations, file_google_api_client, file_google_api_field_behavior, file_google_protobuf_timestamp, file_v1_annotation]);
+ fileDesc("Ch12MS9zdWJzY3JpcHRpb25fc2VydmljZS5wcm90bxILYnl0ZWJhc2UudjEiGAoWR2V0U3Vic2NyaXB0aW9uUmVxdWVzdCJDChlVcGRhdGVTdWJzY3JpcHRpb25S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nNjcmlwdGlvbhImLmJ5dGViYXNlLnYxLlVwZGF0ZVN1YnNjcmlwdGlvblJlcXVlc3QaGS5ieXRlYmFzZS52MS5TdWJzY3JpcHRpb24iQNpBBXBhdGNoiuowD2JiLnNldHRpbmdzLnNldJDqMAGC0+STAhs6B2xpY2Vuc2UyEC92MS9zdWJzY3JpcHRpb25CrgEKD2NvbS5ieXRlYmFzZS52MUIYU3Vic2NyaXB0aW9uU2VydmljZVByb3RvUAFaNGdpdGh1Yi5jb20vYnl0ZWJhc2UvYnl0ZWJhc2UvYmFja2VuZC9nZW5lcmF0ZWQtZ28vdjGiAgNCWFiqAgtCeXRlYmFzZS5WMcoCC0J5dGViYXNlXFYx4gIXQnl0ZWJhc2VcVjFcR1BCTWV0YWRhdGHqAgxCeXRlYmFzZTo6VjFiBnByb3RvMw", [file_google_api_annotations, file_google_api_client, file_google_api_field_behavior, file_google_protobuf_timestamp, file_v1_annotation]);
/**
* Describes the message bytebase.v1.GetSubscriptionRequest.
diff --git a/frontend/src/views/BannerHA.vue b/frontend/src/views/BannerHA.vue
new file mode 100644
index 0000000000..93d77b94dd
--- /dev/null
+++ b/frontend/src/views/BannerHA.vue
@@ -0,0 +1,16 @@
+<template>
+ <div class="bg-warning flex items-center justify-center p-3">
+ <TriangleAlertIcon
+ class="h-6 w-6 text-white shrink-0"
+ />
+ <p class="ml-3 font-medium text-white truncate">
+ <span>
+ {{ $t("banner.ha-not-licensed") }}
+ </span>
+ </p>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { TriangleAlertIcon } from "lucide-vue-next";
+</script>
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index c7c22ea059..2c7d030737 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -7761,6 +7761,11 @@ components:
readOnly: true
type: boolean
description: Whether the external URL is set via command-line flag (and thus cannot be changed via UI).
+ replicaCount:
+ readOnly: true
+ type: integer
+ description: The number of active replicas (servers sharing the same database).
+ format: int32
description: |-
System information and configuration for the Bytebase instance.
Actuator concept is similar to the Spring Boot Actuator.
@@ -13504,6 +13509,10 @@ components:
orgName:
readOnly: true
type: string
+ ha:
+ readOnly: true
+ type: boolean
+ description: Whether high availability (multiple replicas) is enabled.
SyncDatabaseRequest:
required:
- name
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index b13b9f4b60..f49a78e8fe 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -1280,6 +1280,7 @@ Actuator concept is similar to the Spring Boot Actuator.
| total_instance_count | [int32](#int32) | | The total number of database instances. |
| enable_sample | [bool](#bool) | | Whether sample data setup is enabled. |
| external_url_from_flag | [bool](#bool) | | Whether the external URL is set via command-line flag (and thus cannot be changed via UI). |
+| replica_count | [int32](#int32) | | The number of active replicas (servers sharing the same database). |
@@ -10319,6 +10320,7 @@ PlanLimitConfig represents a single plan&#39;s configuration
| expires_time | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
| trialing | [bool](#bool) | | |
| org_name | [string](#string) | | |
+| ha | [bool](#bool) | | Whether high availability (multiple replicas) is enabled. |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 9e25d7122d..0ff2ee063d 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -4532,6 +4532,13 @@ Permissions required: bb.users.updateEmail</p></td>
<td><p>Whether the external URL is set via command-line flag (and thus cannot be changed via UI). </p></td>
</tr>
+ <tr>
+ <td>replica_count</td>
+ <td><a href="#int32">int32</a></td>
+ <td></td>
+ <td><p>The number of active replicas (servers sharing the same database). </p></td>
+ </tr>
+
</tbody>
</table>
@@ -28955,6 +28962,13 @@ Permissions required: bb.sheets.get</p></td>
<td><p> </p></td>
</tr>
+ <tr>
+ <td>ha</td>
+ <td><a href="#bool">bool</a></td>
+ <td></td>
+ <td><p>Whether high availability (multiple replicas) is enabled. </p></td>
+ </tr>
+
</tbody>
</table>
diff --git a/proto/v1/v1/actuator_service.proto b/proto/v1/v1/actuator_service.proto
index 266c35ce7f..074804c4ea 100644
--- a/proto/v1/v1/actuator_service.proto
+++ b/proto/v1/v1/actuator_service.proto
@@ -136,4 +136,7 @@ message ActuatorInfo {
// Whether the external URL is set via command-line flag (and thus cannot be changed via UI).
bool external_url_from_flag = 23 [(google.api.field_behavior) = OUTPUT_ONLY];
+
+ // The number of active replicas (servers sharing the same database).
+ int32 replica_count = 24 [(google.api.field_behavior) = OUTPUT_ONLY];
}
diff --git a/proto/v1/v1/subscription_service.proto b/proto/v1/v1/subscription_service.proto
index 4f4ddefd0a..3a7eb2721b 100644
--- a/proto/v1/v1/subscription_service.proto
+++ b/proto/v1/v1/subscription_service.proto
@@ -73,6 +73,9 @@ message Subscription {
bool trialing = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
string org_name = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
+
+ // Whether high availability (multiple replicas) is enabled.
+ bool ha = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
}
// PlanFeature represents the available features in Bytebase