Commit Graph

342 Commits

Author SHA1 Message Date
Derek Collison
adef8281a2 Updates to the way meta indexing is handled for filestore.
Historically we kept indexing information, either by sequence or by subject, as a per msg block operation. These were the "*.idx" and "*.fss" indexing files. When streams became very large this could have an impact on recovery time. Also, for encryption the fast path for determining if the indexing was current would require loading and decrypting the complete block.

This design moves to a more traditional WAL and snapshot approach. The snapshots for the complete stream, including sumary information, global per subject information maps (PSIM) and per msg block details including summary and dmap, are processed asynchronously. The snapshot includes the msh block and has for the last record considered in the snapshot. On recovery the snapshot is read and processed and any additional records past the point of the snapshot itself are processed. To this end, any removal of a message has to be expressed as a delete tombstone that is always added the the fs.lmb file. These are processed on recovery and our indexing layer knows to skip them.

Changing to this method drastically improves startup and recovery times, and has simplified the code. Some normal performance benefits have been seen as well.

Signed-off-by: Derek Collison <derek@nats.io>
2023-08-30 16:12:45 -07:00
Derek Collison
acfb593ed5 Merge branch 'main' into dev 2023-08-29 16:48:04 -07:00
Derek Collison
8865c2a703 Fix for update to max msgs per where recalculating first was not checking for seq < mb.first.seq
Signed-off-by: Derek Collison <derek@nats.io>
2023-08-29 16:02:52 -07:00
Derek Collison
fb8525b713 Merge branch 'main' into dev
Signed-off-by: Derek Collison <derek@nats.io>
2023-08-21 15:55:00 -07:00
Derek Collison
e018705a08 Fixed deadlock when checkAndSync was being called as part of storing message.
We violated the locking pattern, so we now make sure we do this in a separate Go routine and put checks to only run it once.

Signed-off-by: Derek Collison <derek@nats.io>
2023-08-21 12:12:36 -07:00
Jean-Noël Moyne
b839c53abc [ADDED] Full StreamSource (filters, transforms) functionality to stream mirror (#4354)
- [X] Tests added
- [X] Branch rebased on top of current main (`git pull --rebase origin
main`)
- [X] Changes squashed to a single commit (described
[here](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html))
 - [x] Build is green in Travis CI
- [X] You have certified that the contribution is your original work and
that you license the work to the project under the [Apache 2
license](https://github.com/nats-io/nats-server/blob/main/LICENSE)

Follow up to #4276 extending to Mirror the full StreamSource
functionality.

---------

Signed-off-by: Jean-Noël Moyne <jnmoyne@gmail.com>
2023-08-12 15:17:48 -07:00
Neil Twigg
d7f76da597 Allow switching from limits-based to interest-based retention in stream update
Signed-off-by: Neil Twigg <neil@nats.io>
2023-08-09 11:46:49 +01:00
Derek Collison
20532c28dd Merge branch 'main' into dev 2023-08-04 12:03:13 -07:00
Derek Collison
f2c7a9d37f Fix for flapping test
Signed-off-by: Derek Collison <derek@nats.io>
2023-08-04 12:02:59 -07:00
Jean-Noël Moyne
449b27535e [ADDED] Support for multi-filter in stream sources (#4276)
- [X] Tests added
- [X] Branch rebased on top of current main (`git pull --rebase origin
main`)
- [X] Changes squashed to a single commit (described
[here](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html))
 - [X] Build is green in Travis CI
- [X] You have certified that the contribution is your original work and
that you license the work to the project under the [Apache 2
license](https://github.com/nats-io/nats-server/blob/main/LICENSE)

### Changes proposed in this pull request:

Adds support for multi-filter (and associated transform destinations) to
stream sources

---------

Signed-off-by: Jean-Noël Moyne <jnmoyne@gmail.com>
2023-08-01 10:50:11 -07:00
Neil Twigg
3b9e8b96e5 Add TestJetStreamMirrorFirstSeqNotSupported unit test
Signed-off-by: Neil Twigg <neil@nats.io>
2023-07-28 17:11:02 +01:00
Tomasz Pietrek
4b72e37f27 Fix not validating single token filtered consumer
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
Signed-off-by: Neil Twigg <neil@nats.io>
2023-07-26 16:21:00 +01:00
Neil Twigg
bc78e86388 Update TestJetStreamServerReencryption to also test converting ciphers at the same time as changing keys
Signed-off-by: Neil Twigg <neil@nats.io>
2023-07-26 14:04:28 +01:00
Neil Twigg
3df08c3f89 Add support for re-encrypting streams with new key
Signed-off-by: Neil Twigg <neil@nats.io>
2023-07-26 14:04:28 +01:00
Derek Collison
efbfe217f4 Moved to end for merge with other branches, minor changes
Signed-off-by: Derek Collison <derek@nats.io>
2023-07-18 12:39:06 -07:00
Byron Ruth
16a336ead3 Add test case for concurrent expected last subject sequence
Signed-off-by: Byron Ruth <byron@nats.io>
2023-07-18 12:39:06 -07:00
Derek Collison
360f807cef Moved to end for merge with other branches, minor changes
Signed-off-by: Derek Collison <derek@nats.io>
2023-07-18 11:29:26 -07:00
Byron Ruth
e7bf1b3132 Add test case for concurrent expected last subject sequence
Signed-off-by: Byron Ruth <byron@nats.io>
2023-07-18 11:10:51 -04:00
Derek Collison
ecf0fff411 Merge branch 'main' into dev 2023-07-17 10:41:51 -07:00
Neil Twigg
abb47c9554 Only send one message in TestJetStreamRedeliverCount to prevent out-of-order redeliveries
Signed-off-by: Neil Twigg <neil@nats.io>
2023-07-14 16:56:01 +01:00
Neil Twigg
144abc0dd9 Make TestJetStreamAccountImportJSAdvisoriesAsService insensitive to event order
Signed-off-by: Neil Twigg <neil@nats.io>
2023-07-14 16:51:51 +01:00
Neil Twigg
b58204cff7 Use checkFor in TestJetStreamMsgHeaders
Signed-off-by: Neil Twigg <neil@nats.io>
2023-07-14 16:44:24 +01:00
Neil
40c5770cfc Use crypto/rand.Read instead of math/rand.Read (#4256)
As of Go 1.20, `math/rand.Read` is deprecated. In addition to that, it
also isn't recommended for use in combination with anything
cryptographic.

I haven't replaced all `math/rand` imports with `crypto/rand` imports
because there are still some legitimate uses for the `math/rand` package
in some places.

Signed-off-by: Neil Twigg <neil@nats.io>
2023-07-14 11:23:45 +01:00
Derek Collison
d5a91f43f3 Merge branch 'main' into dev 2023-07-13 07:29:40 -07:00
Neil Twigg
1527000d1f Use crypto/rand.Read instead of math/rand.Read
As of Go 1.20, `math/rand.Read` is deprecated. In addition to that, it also
isn't recommended for use in combination with anything cryptographic.

I haven't replaced all `math/rand` with `crypto/rand` imports because there
are still some legitimate uses for the `math/rand` package in some places.

Signed-off-by: Neil Twigg <neil@nats.io>
2023-07-13 12:04:58 +01:00
Piotr Piotrowski
e3b132ae34 Test for gathering JS advisories from multiple accounts on a single account
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
2023-07-12 13:26:18 +01:00
Jean-Noël Moyne
bd6c15d24e Adds a check that the stream name of a stream source is valid and associated new error if it isn't.
Adresses https://github.com/nats-io/nats-server/issues/4141

Signed-off-by: Jean-Noël Moyne <jnmoyne@gmail.com>
2023-06-08 07:49:46 -07:00
Derek Collison
4220502541 Merge branch 'main' into dev 2023-05-15 15:44:38 -07:00
Derek Collison
3602ff5146 Additional fix for #3734.
When the first block was truncated and missing any index info we would not properly rebuild the state.

Signed-off-by: Derek Collison <derek@nats.io>
2023-05-15 15:30:55 -07:00
Derek Collison
168fb22df5 Fix one more test that did not set ack policy to explicit
Signed-off-by: Derek Collison <derek@nats.io>
2023-05-06 22:05:31 -07:00
Derek Collison
08938034a5 Fix test that did not set ack policy to explicit
Signed-off-by: Derek Collison <derek@nats.io>
2023-05-06 19:54:42 -07:00
Derek Collison
18244ea8cb Fix test that did not set ack policy to explicit
Signed-off-by: Derek Collison <derek@nats.io>
2023-05-06 15:10:46 -07:00
Derek Collison
caa262513d Fix test that did not set ack policy which is needed
Signed-off-by: Derek Collison <derek@nats.io>
2023-05-06 14:15:44 -07:00
Derek Collison
4ebdb69daf Merge branch 'main' into dev 2023-04-26 11:34:37 -07:00
Derek Collison
47c6bfded4 Update server/jetstream_test.go
Fix spelling

Co-authored-by: Tomasz Pietrek <tomasz@nats.io>
2023-04-24 22:29:05 -07:00
Derek Collison
cae91b8cad In single server mode healthz could mistake a snapshot staging directory during a restore as an account.
If the restore took a long time, stalled, or was aborted, would cause healthz to fail.

Signed-off-by: Derek Collison <derek@nats.io>
2023-04-24 22:14:04 -07:00
Derek Collison
3f27b67791 Merge branch 'main' into dev 2023-04-15 10:47:29 -07:00
Derek Collison
034975e767 Fix for a regression in behavior, needed to make sure when we went back to 1 entry for a subject we cleared firstNeedsUpdate.
Signed-off-by: Derek Collison <derek@nats.io>
2023-04-15 10:00:44 -07:00
Tomasz Pietrek
82220d9103 Merge branch 'main' into dev
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
2023-04-14 22:38:45 +02:00
Tomasz Pietrek
a66c67baa5 Fix stream sourcing & mirroring overlap errors
When adding or updating sources/mirrors, server was checking if the stream with
a given name exists to check for subject overlaps, among other things.
However, if sourced/mirrored stream was `External`, checks should
not be executed, as not only stream would never be found,
but also, if `External` stream had the same name as the sourcing stream,
the check would be wrongly performed against itself.

Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
2023-04-14 21:00:11 +02:00
Derek Collison
a319d24345 Merge branch 'main' into dev 2023-04-13 21:03:05 -07:00
Tomasz Pietrek
692f384f2d Fix consumer reply subject escaping
If the Consumer had a name containing `%`, it could result in
reply subject failing to format with `fmt.Sprintf`, as the `%`
was not properly escaped with `%%`.

Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
2023-04-12 09:22:08 +02:00
Derek Collison
4525bdea0d [IMPROVE] Improvements and fixes to stream source consumer creation on leadership change or on stream config source updates (#4009)
- [X] Tests added
- [X] Branch rebased on top of current main (`git pull --rebase origin
main`)
- [X] Changes squashed to a single commit (described
[here](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html))
 - [x] Build is green in Travis CI
- [X] You have certified that the contribution is your original work and
that you license the work to the project under the [Apache 2
license](https://github.com/nats-io/nats-server/blob/main/LICENSE)
2023-04-04 20:09:15 -07:00
Jean-Noël Moyne
0420c6e317 - Improve and fix stream source consumer sequence number finding on leadership change or stream config update to work with the new stream sourcing
- Updates source index name format and adds two fields (source's filter and transform) to the `"Nats-Stream-Source"` message header
- Backwards compatibility for streams containing previous (2.9) message headers for seamless upgrade
- Update TestJetStreamSourceBasics as it could flap sometimes

Signed-off-by: Jean-Noël Moyne <jnmoyne@gmail.com>
2023-03-31 15:49:10 -07:00
Tomasz Pietrek
93c49c354e Fix bug in needAck
needAck has reverse logic for checking single subject-single filter
scenario.

Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
2023-03-31 23:55:50 +02:00
Ivan Kozlovic
db599ac875 Merge branch 'main' into dev 2023-03-30 15:45:51 -06:00
Ivan Kozlovic
a4df4f8727 Fixed some tests
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2023-03-30 15:02:59 -06:00
Derek Collison
9f69d8734f Merge branch 'main' into dev 2023-03-04 08:42:10 -06:00
Tomasz Pietrek
df282a221c Fix Pull Consumer not sending request timeout
Server did check for timeouts in `processWaiting`,
but that needs to be also checked in `nextWaiting` in case of
tight timings, as `nextWaiting` can remove Pull Request based on
timeouts too.

Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
2023-03-03 14:49:04 +01:00
Derek Collison
7bd7cda021 Merge branch 'main' into dev 2023-02-28 15:17:24 -08:00