Commit Graph

127 Commits

Author SHA1 Message Date
Derek Collison
df02e0be71 Consumers would process next message batches inline.
In clustered mode this could block a route or gateway processor.

Signed-off-by: Derek Collison <derek@nats.io>
2021-03-02 18:28:17 -08:00
Derek Collison
27090975d9 Fix for leaked subs on non-leader change
Signed-off-by: Derek Collison <derek@nats.io>
2021-03-02 07:19:18 -08:00
Derek Collison
b9e1a921ff Use internal wildcard inbox for stream and consumer info requests.
More gateway friendly but suffers from no echo, so added new client based internal send.

Signed-off-by: Derek Collison <derek@nats.io>
2021-02-28 10:01:01 -08:00
Derek Collison
6a03ab9629 Inline flow in clustered mode was flaky, removed that path.
Changed up accounting.

Signed-off-by: Derek Collison <derek@nats.io>
2021-02-28 05:11:59 -08:00
Matthias Hanel
c73d3b21eb changing NEXT expires field from time to duration in nanoseconds
Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-02-26 20:45:44 -05:00
R.I.Pienaar
45a42864f6 always store the filter subject
This avoids a situation where a consumer asks for
ORDERS.new today on a stream of ORDERS.new but later
someone makes the same stream ORDERS.* and the new
consumer would then get messages for other purposes
as well

Signed-off-by: R.I.Pienaar <rip@devco.net>
2021-02-25 18:29:21 +01:00
Derek Collison
78bdc34637 General stability improvements. Fixes to subscription state not cleaning up.
Signed-off-by: Derek Collison <derek@nats.io>
2021-02-24 08:44:34 -08:00
Derek Collison
dd19f620a9 Does not need receiver
Signed-off-by: Derek Collison <derek@nats.io>
2021-02-23 10:57:18 -08:00
Ivan Kozlovic
61bd1b8d86 MQTT clustering
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-02-19 08:50:00 -07:00
Derek Collison
afea79610a Consumer interest was not properly handled cross cluster.
Signed-off-by: Derek Collison <derek@nats.io>
2021-02-18 18:29:59 -08:00
Derek Collison
e21c7097f3 General stability improvements.
Original thought to move to memory based WALs was ill-advised and caused issues with stability around restarts.
Returned to file based but with async flush for the WAL itself.
Also the raft inline catchup has been improved.

Signed-off-by: Derek Collison <derek@nats.io>
2021-02-17 19:56:16 -08:00
Derek Collison
5ef4d138cb Interest based retention did not work correctly with wildcards or multiple subjects and filtered consumers.
This allows that to work properly, needed for MQTT.

Signed-off-by: Derek Collison <derek@nats.io>
2021-02-11 20:59:20 -08:00
Derek Collison
d70ae1fb97 Fix for interest policy based retention for streams in clusters.
Signed-off-by: Derek Collison <derek@nats.io>
2021-02-11 18:52:37 -08:00
Derek Collison
fa8a95a06a Improved snapshots and compactions.
Various bug fixes and stability improvements.

Signed-off-by: Derek Collison <derek@nats.io>
2021-02-11 11:16:00 -08:00
Derek Collison
c16f6e193d Move JetStream direct APIs to private.
Signed-off-by: Derek Collison <derek@nats.io>
2021-02-07 15:19:22 -08:00
Derek Collison
6d32c307ef Remove pretty indent for json.
Signed-off-by: Derek Collison <derek@nats.io>
2021-02-06 20:09:44 -08:00
Matthias Hanel
7b7543d298 [added] jsz nats and http monitoring endpoint for jetstream (#1881)
The new endpoints are /jsz on http and "$SYS.REQ.SERVER.PING.JSZ" and "$SYS.REQ.SERVER.%s.JSZ".
$SYS.REQ.ACCOUNT.%s.JSZ will only return info for the particular account

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-02-05 18:46:04 -05:00
Ivan Kozlovic
6eeb9d2361 Fixed some issues with JS consumers
- Should check if there is interest at top of deleteNotActive timer
callback.
- Use RLock/RUnlock for no interest check
- Remove some checks in cluster mode regarding internal stream/consumers

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-02-03 20:12:06 -07:00
Derek Collison
e5c1d65fff Added in JS disable per server on reload. Also removing peerw from a stream and leader stepdown for streams and consumers.
Various bug fixes, stability improvments.

Signed-off-by: Derek Collison <derek@nats.io>
2021-02-01 19:39:08 -08:00
Derek Collison
095a83bc2a Make sure to suppress duplicate create/delete audit events
Signed-off-by: Derek Collison <derek@nats.io>
2021-01-31 09:16:16 -08:00
Derek Collison
d2a92221fb Duplicate leader elect and lost advisories to the system account as well.
Also suppress lost quorums to at most once every 10 secs.

Signed-off-by: Derek Collison <derek@nats.io>
2021-01-29 08:51:20 -08:00
Derek Collison
8b79114168 Add in advisories for leader elected and quorum lost advisories.
Note that quorum lost only fires if the old leader steps down.
If the leader itself fails and that causes the loss of quorum currently no advisory is sent.

Signed-off-by: Derek Collison <derek@nats.io>
2021-01-28 08:37:54 -08:00
Derek Collison
5148bbf898 Fixes based on PR feedback, cleanup
Signed-off-by: Derek Collison <derek@nats.io>
2021-01-25 10:04:21 -08:00
Derek Collison
117607ef11 Fix for race and test for issue R.I. was seeing in nightly. Also fixed flappers.
Signed-off-by: Derek Collison <derek@nats.io>
2021-01-24 21:21:02 -08:00
Derek Collison
9c858d197a Added ability to properly restore consumers from a snapshot.
This made us add forwarding proposals functionality in the raft layer.
More general cleanup and bug fixes as well.

Signed-off-by: Derek Collison <derek@nats.io>
2021-01-24 19:30:34 -08:00
Derek Collison
cad0db2aec Cleanup the consumer assignments when consumers become inactive.
This involved extending our raft implementation to forward proposals to the current leader.

Signed-off-by: Derek Collison <derek@nats.io>
2021-01-23 13:44:10 -08:00
Derek Collison
a43a69a403 Fix for interest only, broken test
Signed-off-by: Derek Collison <derek@nats.io>
2021-01-22 11:04:06 -08:00
Derek Collison
e7414a0b11 Fix data race
Signed-off-by: Derek Collison <derek@nats.io>
2021-01-20 12:00:22 -08:00
Derek Collison
ff54c9dc9c Reworked snapshot and restore.
Underestimated the effort to get stream restore working properly in cluster mode.
Some good bug fixes and stability improvments.

Signed-off-by: Derek Collison <derek@nats.io>
2021-01-20 11:58:31 -08:00
Derek Collison
a1730f1b31 Report on RAFT group information.
This adds in optional reporting to stream and consumer info when running in clsutered mode.

Signed-off-by: Derek Collison <derek@nats.io>
2021-01-20 11:58:31 -08:00
Ivan Kozlovic
a1f0117474 Fixed consumer sending to nil channel on shutdown/leader change.
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-01-20 10:05:15 -07:00
Ivan Kozlovic
c4a284b58f Fix stop of consumer's delivery loop
I noticed that some consumer go routines were left running at the end
of the test suite.
It turns out that there was a race the way the consumer's qch was closed.
Since it was closed and then set to nil, it is possible that the go
routines that are started and then try to capture o.qch would actually
get qch==nil, wich then when doing a select on that nil channel would
block forever.

So we know pass the qch to the 2 go routines loopAndGatherMsgs() and
loopAndDeliverMsgs() so that when we close the channel there is
no risk of that race happening.

I do believe that there is still something that should be looked at:
it seems that a consumer's delivery loop can now be started/stopped
many times based on leadership acquired/lost. If that is the case,
I think that the consumer should wait for previous go routine to
complete before trying to start new ones.

Also moved 3 JetStream tests to the test/norace_test.go file because
they would consumer several GB of memory when running with the -race flag.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-01-19 17:39:32 -07:00
Derek Collison
fe9e45bbd2 Updates based on PR comments
Signed-off-by: Derek Collison <derek@nats.io>
2021-01-17 12:08:35 -08:00
Derek Collison
a18a6803c1 Added support for stream and consumer lists.
This utilizes a scatter and gather approach.

Signed-off-by: Derek Collison <derek@nats.io>
2021-01-16 12:42:45 -08:00
Derek Collison
b606dceb59 Stabilize restart/catchup for raft.
Signed-off-by: Derek Collison <derek@nats.io>
2021-01-16 05:47:48 -08:00
Derek Collison
f0cdf89c61 JetStream Clustering WIP
Signed-off-by: Derek Collison <derek@nats.io>
2021-01-14 01:14:52 -08:00
Ivan Kozlovic
b048b6b3de Merge pull request #1754 from nats-io/mqtt
[ADDED] MQTT Support
2020-12-07 09:06:12 -07:00
Derek Collison
0f7d18d6e8 Fixes https://github.com/nats-io/jetstream/issues/396
Had a deadlock with new preconditions. We need to hold lock across Store() call but that call could call into storeUpdate() such that we may need to acquire the lock. We can enter this callback from the storage layer itself and the lock would not be held so added an atomic.

Signed-off-by: Derek Collison <derek@nats.io>
2020-12-02 16:18:00 -08:00
Ivan Kozlovic
3e91ef75ab Some updates based on code review
- Added non-public stream and consumer configuration options to
achieve the "no subject" and "no interest" capabilities. Had
to implement custom FileStreamInfo and FileConsumerInfo marshal/
unmarshal methods so that those non public fields can be
persisted/recovered properly.
- Restored some of JS original code (since now can use config
instead of passing booleans to the functions).
- Use RLock for deliveryFormsCycle() check (unrelated to MQTT).
- Removed restriction on creating streams with MQTT prefix.
- Preventing API deletion of internal streams and their consumers.
- Added comment on Sublist's ReverseMatch method.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-12-01 14:05:54 -07:00
Ivan Kozlovic
1dba6418ed [ADDED] MQTT Support
This PR introduces native support for MQTT clients. It requires use
of accounts with JetStream enabled. Since as of now clustering is
not available, MQTT will be limited to single instance.

Only QoS 0 and 1 are supported at the moment. MQTT clients can
exchange messages with NATS clients and vice-versa.

Since JetStream is required, accounts with JetStream enabled must
exist in order for an MQTT client to connect to the NATS Server.
The administrator can limit the users that can use MQTT with the
allowed_connection_types option in the user section. For instance:
```
accounts {
  mqtt {
    users [
      {user: all, password: pwd, allowed_connection_types: ["STANDARD", "WEBSOCKET", "MQTT"]}
      {user: mqtt_only, password: pwd, allowed_connection_types: "MQTT"}
    ]
    jetstream: enabled
  }
}
```
The "mqtt_only" can only be used for MQTT connections, which the user
"all" accepts standard, websocket and MQTT clients.

Here is what a configuration to enable MQTT looks like:
```
mqtt {
  # Specify a host and port to listen for websocket connections
  #
  # listen: "host:port"

  # It can also be configured with individual parameters,
  # namely host and port.
  #
  # host: "hostname"
  port: 1883

  # TLS configuration section
  #
  # tls {
  #  cert_file: "/path/to/cert.pem"
  #  key_file: "/path/to/key.pem"
  #  ca_file: "/path/to/ca.pem"
  #
  #  # Time allowed for the TLS handshake to complete
  #  timeout: 2.0
  #
  #  # Takes the user name from the certificate
  #  #
  #  # verify_an_map: true
  #}

  # Authentication override. Here are possible options.
  #
  # authorization {
  #   # Simple username/password
  #   #
  #   user: "some_user_name"
  #   password: "some_password"
  #
  #   # Token. The server will check the MQTT's password in the connect
  #   # protocol against this token.
  #   #
  #   # token: "some_token"
  #
  #   # Time allowed for the client to send the MQTT connect protocol
  #   # after the TCP connection is established.
  #   #
  #   timeout: 2.0
  #}

  # If an MQTT client connects and does not provide a username/password and
  # this option is set, the server will use this client (and therefore account).
  #
  # no_auth_user: "some_user_name"

  # This is the time after which the server will redeliver a QoS 1 message
  # sent to a subscription that has not acknowledged (PUBACK) the message.
  # The default is 30 seconds.
  #
  # ack_wait: "1m"

  # This limits the number of QoS1 messages sent to a session without receiving
  # acknowledgement (PUBACK) from that session. MQTT specification defines
  # a packet identifier as an unsigned int 16, which means that the maximum
  # value is 65535. The default value is 1024.
  #
  # max_ack_pending: 100
}
```

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-11-30 20:08:44 -07:00
Derek Collison
4532447908 Remove limitation on ackall for filtered consumers
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-28 07:18:17 -08:00
Derek Collison
5d8b9eb608 Merge pull request #1748 from nats-io/fs_consumer_bug
Fixed bug restoring consumer state
2020-11-25 14:17:02 -08:00
Derek Collison
bcf295dd51 Changed dcount -> dc
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-25 13:30:29 -08:00
Derek Collison
44a1373f89 JetStream changes.
Made several changes based on feedback.

1. Made PubAckResponse only optionally include an ApiError and not force an API type.
2. Allow FilterSubject to be set on a consumer config and cleared if it matches the only stream subject.
3. Remove LookupStream by subject, and add in filters for stream names API.

Signed-off-by: Derek Collison <derek@nats.io>
2020-11-25 06:50:25 -08:00
Derek Collison
bcb777150a Fix race
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-22 10:24:32 -08:00
Derek Collison
aa35d0818d Optimize ackReply parsing
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-17 10:36:14 -08:00
Derek Collison
67f4bf1ac1 Make sure to honor MaxAckPending when streaming directly to consumers
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-16 16:51:34 -08:00
Derek Collison
cccb96097a Release lock for sending non-consumer messages as well
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-16 05:29:55 -08:00
Derek Collison
e93f448d32 Decouple consumer from using stream's sendq
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-15 15:26:30 -08:00
Derek Collison
9893aac8cb Add support for MaxAckPending
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-14 06:28:07 -08:00