nats-io / nats-streaming-server

NATS Streaming System Server
https://nats.io
Apache License 2.0
2.51k stars 284 forks source link

sub/pub on similar-named channels (on Windows) #1265

Closed nvol closed 2 years ago

nvol commented 2 years ago

some strange behavior encountered when tried to use some channels with similar names (like 'boo' and 'Boo')
the experiment was as follows:

 1) pub msg 1 to channel 'BearD'
 2) pub msg 2 to channel 'bEARd'
 3) pub msgs 3 to channel 'beard'
 4) pub msgs 4 to channel 'beard' again
 5) pub msg 5 to channel 'BEARD'

sub to all msgs (from the first one, non-durable) of the channel 'beard' - got msg 1 with seq 1 (expected 3 and 4)
sub to all msgs (from the first one, non-durable) of the channel 'BEARD' - got msg 1 with seq 1 (expected 5)
other variants give the msg 1 with seq 1 as well
but if we try to subscribe to 'bEaRd' for example, we'll got no msgs! ok!

so i proceeded:

the subscriber were stopped
 6) pub msg 6 to channel 'BearD'
then i subscribed to msgs of 'BearD' and still got only the msg 1 with seq 1 (didn't got msg 6)
 7) pub msg 7 to channel 'beard' - no reaction
 8) pub msg 8 to channel 'BearD' again... and got another one msg for the subscriber - msg 8 with seq 3 (!)

summary: a) when use similar-named channels, you got only the first msg in this channel, regardless of which channel (used before) you subscribed to b) with the subscription staying alive, you got the msgs exactly from that channel you subscribed to c) each channel has its own seq numbering, despite the fact that everything is put in one folder (folder is named by the first channel name we published to - 'BearD')

kozlovic commented 2 years ago

We have a big problem here: the server is treating the channel name case-sensitive, but the file system is not. Meaning that if we create a directory called "Foo" (because of creating channel "Foo"), then creating channel "foo" and then trying to create directory "foo" would result in "directory already exists".

Since channels translate to directories on disk, I have no other choice than make the server fail a new channel that is "case-insensitive" already present. That is, in the description above, the time an application would try to create channel "foo", it should fail saying that "Foo" already exists. Not sure what will happen if users have already be running into this without knowing that there is really only 1 channel on disk.

nvol commented 2 years ago

didn't you think about making all the channels to be case insensitive?
for example, publishing to channels 'BearD', 'bEaRd' and so on results into creating just one channel and then you could read from any of the variants receiving the all published messages by any of the similar names

nvol commented 2 years ago

it seems that actually all of the messages of all of the similar-named channels are stored in the dat-file, but every individual channel has it's own seq numbering
so we have a problem very similar to the one that was described in issue #1264
subscription 'stops' on the seq-jump (here i mean not only 'seq resetting' but rather 'seq is not growing' case)
in the example above we have the very first message with seq=1, then goes the message with seq=1 again and this is not normal (it's a seq-jump if i may say so)