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

Events/cfg enable publisher #8916

Merged
merged 3 commits into from
Sep 17, 2020
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: 0 additions & 1 deletion nomad/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func NewFSM(config *FSMConfig) (*nomadFSM, error) {

// Close is used to cleanup resources associated with the FSM
func (n *nomadFSM) Close() error {
n.state.Abandon()
return nil
}

Expand Down
17 changes: 12 additions & 5 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type StateStoreConfig struct {

// Region is the region of the server embedding the state store.
Region string

EnablePublisher bool
}

// The StateStore is responsible for maintaining all the Nomad
Expand Down Expand Up @@ -86,11 +88,16 @@ func NewStateStore(config *StateStoreConfig) (*StateStore, error) {
abandonCh: make(chan struct{}),
stopEventPublisher: cancel,
}
publisher := stream.NewEventPublisher(ctx, stream.EventPublisherCfg{
EventBufferTTL: 1 * time.Hour,
EventBufferSize: 250,
})
s.db = NewChangeTrackerDB(db, publisher, processDBChanges)

if config.EnablePublisher {
publisher := stream.NewEventPublisher(ctx, stream.EventPublisherCfg{
EventBufferTTL: 1 * time.Hour,
EventBufferSize: 250,
})
s.db = NewChangeTrackerDB(db, publisher, processDBChanges)
} else {
s.db = NewChangeTrackerDB(db, &noOpPublisher{}, processDBChanges)
}

// Initialize the state store with required enterprise objects
if err := s.enterpriseInit(); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions nomad/stream/event_publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ func NewEventPublisher(ctx context.Context, cfg EventPublisherCfg) *EventPublish
if cfg.EventBufferTTL == 0 {
cfg.EventBufferTTL = 1 * time.Hour
}

buffer := newEventBuffer(cfg.EventBufferSize, cfg.EventBufferTTL)
e := &EventPublisher{
eventBuf: buffer,
publishCh: make(chan changeEvents),
subscriptions: &subscriptions{
byToken: make(map[string]map[*SubscribeRequest]*Subscription),
},
pruneTick: 5 * time.Second,
}

go e.handleUpdates(ctx)
Expand Down