Skip to content
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
1 change: 1 addition & 0 deletions go/cmd/orchestrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func main() {
}
config.RuntimeCLIFlags.ConfiguredVersion = AppVersion
config.MarkConfigurationLoaded()
inst.InitializeInstanceDaoCaches()

if len(flag.Args()) == 0 && *command == "" {
// No command, no argument: just prompt
Expand Down
19 changes: 15 additions & 4 deletions go/inst/instance_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,23 @@ func init() {
go initializeInstanceDao()
}

var instanceDaoCachesOnce sync.Once

// InitializeInstanceDaoCaches creates the instance write buffer and the instance caches.
// It is called synchronously once the configuration is loaded, before anything (such as a
// raft snapshot restore) can read the caches; later calls do nothing.
func InitializeInstanceDaoCaches() {
instanceDaoCachesOnce.Do(func() {
instanceWriteBuffer = make(chan instanceUpdateObject, config.Config.InstanceWriteBufferSize)
instanceKeyInformativeClusterName = cache.New(time.Duration(config.Config.InstancePollSeconds/2)*time.Second, time.Second)
forgetInstanceKeys = cache.New(time.Duration(config.Config.InstancePollSeconds*3)*time.Second, time.Second)
clusterInjectedPseudoGTIDCache = cache.New(time.Minute, time.Second)
})
}

func initializeInstanceDao() {
config.WaitForConfigurationToBeLoaded()
instanceWriteBuffer = make(chan instanceUpdateObject, config.Config.InstanceWriteBufferSize)
instanceKeyInformativeClusterName = cache.New(time.Duration(config.Config.InstancePollSeconds/2)*time.Second, time.Second)
forgetInstanceKeys = cache.New(time.Duration(config.Config.InstancePollSeconds*3)*time.Second, time.Second)
clusterInjectedPseudoGTIDCache = cache.New(time.Minute, time.Second)
InitializeInstanceDaoCaches()
// spin off instance write buffer flushing
go func() {
flushTick := time.Tick(time.Duration(config.Config.InstanceFlushIntervalMilliseconds) * time.Millisecond)
Expand Down
13 changes: 13 additions & 0 deletions go/inst/instance_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,16 @@ func fmtArgs(args []interface{}) string {
}
return b.String()
}

func TestInitializeInstanceDaoCaches(t *testing.T) {
// The configuration is never marked loaded in unit tests, so the background
// initializeInstanceDao() goroutine never creates the caches; only the
// synchronous call can.
InitializeInstanceDaoCaches()
InitializeInstanceDaoCaches()
test.S(t).ExpectTrue(forgetInstanceKeys != nil)
test.S(t).ExpectTrue(instanceKeyInformativeClusterName != nil)
test.S(t).ExpectTrue(clusterInjectedPseudoGTIDCache != nil)
test.S(t).ExpectTrue(instanceWriteBuffer != nil)
test.S(t).ExpectFalse(InstanceIsForgotten(&i710k))
}
Loading