mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Merge pull request #2145 from nats-io/overlap
Check for overlapping subjects on stream update.
This commit is contained in:
@@ -3466,6 +3466,22 @@ func (s *Server) jsClusteredStreamUpdateRequest(ci *ClientInfo, acc *Account, su
|
||||
return
|
||||
}
|
||||
|
||||
// Check for subject collisions here.
|
||||
for _, sa := range cc.streams[acc.Name] {
|
||||
if sa == osa {
|
||||
continue
|
||||
}
|
||||
for _, subj := range sa.Config.Subjects {
|
||||
for _, tsubj := range newCfg.Subjects {
|
||||
if SubjectsCollide(tsubj, subj) {
|
||||
resp.Error = jsError(fmt.Errorf("subjects overlap with an existing stream"))
|
||||
s.sendAPIErrResponse(ci, acc, subject, reply, string(rmsg), s.jsonResponse(&resp))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sa := &streamAssignment{Group: osa.Group, Config: newCfg, Subject: subject, Reply: reply, Client: ci}
|
||||
cc.meta.Propose(encodeUpdateStreamAssignment(sa))
|
||||
}
|
||||
|
||||
@@ -5880,6 +5880,43 @@ func TestJetStreamClusterCreateConcurrentDurableConsumers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/nats-io/nats-server/issues/2144
|
||||
func TestJetStreamClusterUpdateStreamToExisting(t *testing.T) {
|
||||
c := createJetStreamClusterExplicit(t, "MSL", 3)
|
||||
defer c.shutdown()
|
||||
|
||||
// Client for API requests.
|
||||
nc, js := jsClientConnect(t, c.randomServer())
|
||||
defer nc.Close()
|
||||
|
||||
_, err := js.AddStream(&nats.StreamConfig{
|
||||
Name: "ORDERS1",
|
||||
Replicas: 3,
|
||||
Subjects: []string{"foo"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
_, err = js.AddStream(&nats.StreamConfig{
|
||||
Name: "ORDERS2",
|
||||
Replicas: 3,
|
||||
Subjects: []string{"bar"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
_, err = js.UpdateStream(&nats.StreamConfig{
|
||||
Name: "ORDERS2",
|
||||
Replicas: 3,
|
||||
Subjects: []string{"foo"},
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("Expected an error but got none")
|
||||
}
|
||||
}
|
||||
|
||||
// Support functions
|
||||
|
||||
// Used to setup superclusters for tests.
|
||||
|
||||
Reference in New Issue
Block a user