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

fix: if key/value store already exists use that #2293

Merged
merged 3 commits into from
Nov 11, 2022
Merged
Changes from 2 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
14 changes: 12 additions & 2 deletions eventbus/jetstream/sensor/sensor_jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,22 @@ func (stream *SensorJetstream) Initialize() error {
}
// create Key/Value store for this Sensor (seems to be okay to call this if it already exists)
stream.keyValueStore, err = stream.MgmtConnection.JSContext.CreateKeyValue(&nats.KeyValueConfig{Bucket: stream.sensorName})
if err != nil {
switch err {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we query first, if it's not existing, then create it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

case nats.ErrStreamNameAlreadyInUse:
// get the existing one
stream.keyValueStore, err = stream.MgmtConnection.JSContext.KeyValue(stream.sensorName)
if err != nil {
errStr := fmt.Sprintf("failed to get existing Key/Value Store for sensor %s, err: %v", stream.sensorName, err)
stream.Logger.Error(errStr)
return err
}
stream.Logger.Infof("found existing K/V store for sensor %s, using that", stream.sensorName)
case nil:
errStr := fmt.Sprintf("failed to Create Key/Value Store for sensor %s, err: %v", stream.sensorName, err)
stream.Logger.Error(errStr)
return err
}
stream.Logger.Infof("successfully created K/V store for sensor %s (if it doesn't already exist)", stream.sensorName)
stream.Logger.Infof("successfully created/located K/V store for sensor %s", stream.sensorName)

// Here we can take the sensor specification and clean up the K/V store so as to remove any old
// Triggers for this Sensor that no longer exist and any old Dependencies (and also Drain any corresponding Connections)
Expand Down