Commit Graph

237 Commits

Author SHA1 Message Date
Piotr Piotrowski
ffc3c71d21 Fix sending ack when AckNonePolicy is set 2022-06-02 15:30:49 +02:00
Ivan Kozlovic
9aaf72b01b [ADDED] Stream RePublish and some ConsumerConfig new fields
Namely for pull consumers: ability to override the replica count or storage type:
```
// Generally inherited by parent stream and other markers, now can be configured directly.
Replicas int `json:"num_replicas"`
// Force memory storage.
MemoryStorage bool `json:"mem_storage,omitempty"`
```

For the stream, this new StreamConfig option:
```
// Allow republish of the message after being sequenced and stored.
RePublish *SubjectMapping `json:"republish,omitempty"`
```
Where SubjectMapping is:
```
// SubjectMapping allows a source subject to be mapped to a destination subject for republishing.
type SubjectMapping struct {
	Source      string `json:"src,omitempty"`
	Destination string `json:"dest"`
}
```

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-05-24 19:42:24 -06:00
Phil Pennock
9b8bfefb08 spelling fix & dictionary updates
Fix a spelling mistake which made it through to go docs.

gospel 1.13.0 is now out, and it added features which let us remove some old
words (eg, pluralizations of types we define), but it also errored out on
seeing a comment in .words which used to be acceptable.
So remove comments from .words and introduce .words.readme instead.

We lose the section-introducer comments.  Which is a shame.
2022-05-05 17:28:06 -04:00
Waldemar Quevedo
5be4ec526b js: handle 408 fetch requests pending status
Skip 408 errors thrown to client no wait + expires requests

Signed-off-by: Waldemar Quevedo <wally@nats.io>
2022-05-03 15:58:23 -07:00
Byron Ruth
7ce02bfbb2 Change expected last sequence pub options to pointers
This allows for differentiating between the zero value and whether it was intentionally
set to a sequence of zero.

Signed-off-by: Byron Ruth <b@devel.io>
2022-04-14 08:23:26 -04:00
Ivan Kozlovic
8af932f207 Merge pull request #933 from mfaizanse/backoff_sub_opt
Added BackOff helper method to set backoff through subOpts
2022-04-04 14:26:32 -06:00
Waldemar Quevedo
dd3a012c0f Set async pub ack inflight pending default to 4K, add StallWait option
Signed-off-by: Waldemar Quevedo <wally@nats.io>
2022-03-29 16:22:04 -07:00
Waldemar Quevedo
f658a93098 Add ClientTrace struct for JS tracing
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2022-03-28 22:55:03 -07:00
Muhammad Faizan
f0dcbad53d Added BackOff helper method to set backoff through subOpts 2022-03-22 14:09:28 +01:00
Derek Collison
2a5ee5ff33 Allow JetStream Publish retries iff ErrNoResponders was returned.
This is to avoid small blips from leader changes surfacing to the end application.

Signed-off-by: Derek Collison <derek@nats.io>
2022-03-17 11:38:01 -07:00
Ivan Kozlovic
30ecb5dafd JetStream: revert some change made to ordered consumer
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-03-06 11:35:03 -07:00
Ivan Kozlovic
a68a1faac5 [CHANGED] JS: Do not set MaxAckPending to high value on Subscribe
When calling js.Subscribe() (or equivalent) and the library ended-up
creating the JS consumer, a MaxAckPending was set to a very high
value in some cases. We now let the server pick the default if the
value is not explicitly set by the user.
The NATS subscription pending limits are set in a way to ensure
that the subscription can store at least the max ack pending value.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-03-01 14:32:48 -07:00
Ivan Kozlovic
7d7a4feab6 Remove the capture of pending when having a consumer already exist error
Should be done really only when the library successfully created
the consumer.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-02-09 15:46:31 -07:00
Ivan Kozlovic
cc6c8b1d4a Different approach to address initial pending == 0
This is undoing changes done in PR https://github.com/nats-io/nats.go/pull/901
and makes the changes dicussed in the comments of that PR.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-02-09 14:21:31 -07:00
Ivan Kozlovic
85e8c7f7c6 Updates to KV
Relying on ConsumerInfo.NumPending on create was not realiable
if the NATS subscription exists before (which is normal case)
due to a design in the server that process the add consumer
request and then computes the consumer info (after the consumer
is setup which means it could start to deliver messages).

Changed a bit so that we add a JS consumer without attached
subscription and use internal option to allow a js.Subscribe()
with a bind to existing consumer.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-02-08 17:40:31 -07:00
Derek Collison
6cbe82760f Merge pull request #900 from nats-io/watcher_updates
Updates to KV Watcher.
2022-02-07 17:23:05 -08:00
Derek Collison
16c1c768dc Updates to KV Watcher.
1. If the underlying stream was very busy pending might not go to zero, so snapshot and mark initial state done when received >= init pending or delta == 0
2. When a watcher was cancelled with a context we would not signal to allow and range w.Updates() calls to exit.
3. General flow control checks were timing sensitive after the initial checks, needed to be 2x HB interval always, not just beginning.

Signed-off-by: Derek Collison <derek@nats.io>
2022-02-05 20:17:25 -08:00
Phil Pennock
bf1b00513e Spelling fixes, mostly comments
The new `gospel` tool, <https://github.com/kortschak/gospel>, uses hunspell
libraries but pre-registers as acceptable words every symbol from the Go
source, massively reducing the noise and making comment spell-checking a
tractable problem.  It recently gained support for a `.words` file located in
the same directory as the `go.mod` file, to define local words.  With this, we
can fix real issues too.

This PR reduces the complaints down to 4:
 1. A reference to `syncSubscribers` which I can't figure out
 2. A reference to a `pubArg`
 3. Two references to `splitArgs`.

I made two actual code changes:
 1. Fixing a **non-exported** const type for consistency with all the others:
    `apiStreamList` -> `apiStreamListT`.
 2. Changing an error message to refer to a field which exist

Lots of typo fixes; references to since-renamed fields; etc.

A reference to `PublishAsynMsg` might have been intended to be
`PublishAsyncMsg` but that doesn't exist either, so I removed it.
Similarly, `SubjectIsDelivery` lived briefly but a stale reference was left in
a comment, so I removed that.

To reproduce:

    go install github.com/kortschak/gospel@latest
    gospel .
2022-02-05 21:26:46 -05:00
Ivan Kozlovic
d34c12d8a5 Passed nakDelay as an option to internal ackReply() function
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-01-31 18:48:48 -07:00
Ivan Kozlovic
f1d50b84af Remove NakDelay() option and instead add Msg.NakWithDelay()
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-01-31 18:25:00 -07:00
Ivan Kozlovic
fd2a47640d [ADDED] JetStream: Nak delay and BackOff lists
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-01-31 17:56:08 -07:00
Ivan Kozlovic
63b8e8bcc1 [ADDED] JetStream: UpdateConsumer and new consumer config's options
Namely: MaxRequestBatch, MaxRequestExpires and InactiveThreshold

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-01-31 15:02:55 -07:00
Matthew DeVenny
492c3bd206 Fix activityCheck to handle case when timer has been stopped
Signed-off-by: Matthew DeVenny <matt@boxboat.com>
2021-12-15 14:57:17 -07:00
Waldemar Quevedo
16d26f8e7b js: make js.Subscribe context aware
Can now attach a context to a subscription so that it is
unsubscribed and/or consumer deleted via propagation of
cancellation via parent context.

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2021-12-14 13:13:23 -08:00
Bartosz Behring
67333f2fa1 Introducing ErrMsgAlreadyAckd to have more detailed error msg when trying to ack msg that was already acknowledged. 2021-11-14 10:28:36 +01:00
Casper Beyer
3d1af3f44c Fix typo in Bind documentation comments 2021-11-10 14:19:59 +08:00
R.I.Pienaar
2554593026 support tracing JS api calls
Signed-off-by: R.I.Pienaar <rip@devco.net>
2021-10-14 10:17:18 +02:00
Ivan Kozlovic
51d43e46a5 [FIXED] JetStream: ordered consumers handling of auto unsub
If user creates an ordered consumer and uses AutoUnsubscribe()
with the returned subscription, and if the ordered consumer was
reset (due to a gap detection), the library should resend an
UNSUB with adjusted max for the new subscription ID.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-10-13 13:59:40 -06:00
R.I.Pienaar
4b5b7cfbc1 add kv and object status functionality
Signed-off-by: R.I.Pienaar <rip@devco.net>
2021-10-12 16:54:44 +02:00
R.I.Pienaar
d7eb0d8f98 ensure get returns a nil and key not found as per spec
Signed-off-by: R.I.Pienaar <rip@devco.net>
2021-10-11 17:12:58 +02:00
Derek Collison
141643a344 [ADDED] KeyValue and ObjectStore support for JetStream.
Also:
- Fixed message reply in PublishMsgAsync
- Ability to seal streams
- Ability for consumer to get message headers only, no msg payload
- GetLastMsg and purgeStream by subject

Signed-off-by: Derek Collison <derek@nats.io>
2021-10-07 16:29:26 -06:00
Ivan Kozlovic
e30a74532e [FIXED] JetStream: queue name cannot contain "." when used as durable
When calling `js.QueueSubscribe[Sync](subject, queue_name)`, if
no durable name is provided, the queue name is used as the durable
name, so the same restriction applies

Resolves #840

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-10-07 11:56:25 -06:00
Ivan Kozlovic
630522759f Merge pull request #837 from nats-io/js_fix_fc
[FIXED] JetStream flow control may stall in some conditions
2021-10-05 16:31:09 -06:00
Ivan Kozlovic
c564a49724 Updates based on code review
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-10-05 15:14:47 -06:00
Waldemar Quevedo
8f86c1d37a js: Fix context usage with sub.Fetch and msg.Ack
The deadline of a context is now used to calculate
the time used for `expires` instead of the default `ttl`
of the JetStream context which was 5s.  This was preventing
library users from passing a context with a custom timeout.

This also disallows the usage of `context.Background`
to make it explicit that `sub.Fetch` has to be used
with a context that has a timeout since each fetch
request has to include an expire time anyway.

In case `context.WithCancel` is used, then a child context
with the same duration as the JetStream context default
timeout will be created.

Also in case msg.Ack it was possible to pass both timeout
and a context which would have been ambiguous and only
context option being used.

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2021-10-05 13:28:14 -07:00
Ivan Kozlovic
66ba98e14f [FIXED] JetStream flow control may stall in some conditions
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-10-05 09:53:32 -06:00
Waldemar Quevedo
76690683f2 js: unblock batch requests on 408 with at least a message
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2021-09-16 14:33:58 -07:00
Ivan Kozlovic
8ec6f2c7b1 [UPDATED] JetStream go doc in the interface
Copied the go doc from implementation to interface, and reworded
some sections.

I decided to copy versus move because some IDE (for instance VS code)
seem to show the doc (when hovering) from the implementation, not
the interface.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-09-08 18:07:33 -06:00
Ivan Kozlovic
f3a531d051 [FIXED] Fetch() could return immediately with a timeout error
This would happen when pull requests would have filled the waiting
queue in the JetStream consumer and a 408 status was returned.

Resolves #809

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-09-02 08:12:36 -06:00
Ivan Kozlovic
33433c95d4 Fixed check for JS.ACK tokens count
Do not reject if it has only 11 tokens.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-25 09:57:01 -06:00
Ivan Kozlovic
d5b5768e78 [IMPROVED] Subscribe returns error if consumer config does not match
This is done to alert the user that consumer config is not changed
as one would expect.

This change is more tricky than expected. We can't simply compare
user's consumer config with what is returned from the server.
For once, there are configurations that may not be set by the
user that were set when the consumer was created, that the lib
should not fail. Let's say the consumer is created with a description,
why fail the user if they don't pass the Description() option at all?

The Description() option was actually missing, but this is a good
example. But same could be say with for instance "optional start
sequence". This may be something that is set when the consumer
is first created (possibly outside of the app with CLI), but when
user calls js.Subscribe(), that option should not have to be
set to the value that was used when creating the consumer.

I had to add "not set" values for replay and deliver policy, similar
to ack policy.

I added an extensive test that checks proper error when trying
to make configuration changes, but also that if the options are
not set, then the lib does not fail the subscribe call.

Resolves #796

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-23 17:11:31 -06:00
Ivan Kozlovic
d6590e7b27 [CHANGED] ConsumerInfo Delivered and AckFloor are now SequenceInfo
A new object `SequenceInfo` is added for `Delivered` and `AckFloor`'s
`ConsumerInfo` fields. This object contains `Last` which represents
the last activity time (in UTC).
Having this field under `SequencePair` was wrong since we used
`SequencePair` in other object, namely `MsgMetadata`, and in
that context, `Last` did not make sense.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-23 13:06:52 -06:00
Ivan Kozlovic
5a2962709c Removed new option SubjectIsDelivery and some other changes
This is to align with newer version of the ADR describing the
subscription workflow:
- Removed option SubjectIsDelivery that was introduced in main branch
(but not released yet).
- Take into consideration the new ACK layout
- Make sure that OrderedConsumer rejects user configuring DeliverSubject

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-18 17:48:05 -06:00
Ivan Kozlovic
9d3a000c8a Merge pull request #798 from nats-io/add_last_per_subject_delivery_policy
[ADDED] Last per subject delivery policy
2021-08-17 11:17:28 -06:00
Ivan Kozlovic
81f06013ba [ADDED] Last per subject delivery policy
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-17 09:56:42 -06:00
Ivan Kozlovic
ea700ff6ec [ADDED] ExpectLastSequencePerSubject() publish option
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-17 09:20:06 -06:00
Ivan Kozlovic
73d14e17c5 [ADDED] Description in StreamConfig and ConsumerConfig
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-16 19:20:42 -06:00
Ivan Kozlovic
4b8ebba8a3 Replaced BindDeliverSubject with SubjectIsDelivery
As discussed with Matthias who came up with the idea, this is
better because then we make use of the provided subject. Otherwise
it was looking weird to have something which meaning was:
```
js.SubscribeSync("ignored", nats.BindDeliverSubject("p.d4"))
```
Instead you would now have:
```
sub, err = js.SubscribeSync("p.d4", nats.SubjectIsDelivery())
```

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-16 18:54:34 -06:00
Ivan Kozlovic
e077154668 Addresses comments change requests based on code review
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-16 12:18:15 -06:00
Ivan Kozlovic
f730c0230b Add Domain to PubAck
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-16 09:23:53 -06:00