-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support setting headers for kv put #217
Comments
@williamstein currently our specification (unless it changed - will check) doesn't support user-specified headers on KV. |
Thanks. I assume this is the spec: https://github.com/nats-io/nats-architecture-and-design/blob/main/adr/ADR-8.md I don't think it mentions user-specified headers. Moreover, since at least one header is currently used for the implementation of KV, e.g., Nats-Expected-Last-Subject-Sequence, there could be a subtle conflict. All that said, I can't think of any good way of implementing arbitrary size values without using headers, whereas the implementation I already wrote using headers turned out very nice. So I'll stick with my workaround no matter what (yeah, open source). Please close this issue if you feel there is no chance of extending the spec to support user defined headers. But perhaps keep in mind that user-defined headers are a natural primitive that might be easy for you guys to support, and having them enables valuable things that are extremely painful otherwise. And I would be fine with a constraint like "only user defined headers that don't start with |
If you want to store arbitrary sized data, object store is the correct API. |
Thanks. Just to be clear, my request here is supporting headers, not storing arbitrarily large objects -- that was just an example application, of many. The object store API is difficult to work with in comparison to KV (e.g., this). Thanks for checking with the group that they actively don't want to support headers, which would make KV much more consistent with how streams work. It's a good thing NATS is open source, so that users like me still have the option to improve the tools along the edges, based on our experience building real world products on top of NATS. |
I just hit another application of headers for the kv store, which has nothing to do with storing large values. The keys that NATS supports are fairly restricted (UTF-8 minus some symbols), and I think this kv implementation dramatically restricts them further to a small subset of ASCII (for no apparent reason?). One could compute a key this is valid according this to this library, e.g., by computing the sha1 hash of the actual key, and also store the actual key in a header. Storing the actual key is required if you're iterating over your data, since you need to know what the keys are (not just their hashes). The only alternative to this would be to store the actual key in some other place in the key-value store, e.g., I suspect there are other applications of headers, which support giving users of kv even more power to build interesting things, going beyond what the NATS developers envision. |
Proposed change
If you are putting a value using the key:value store, NATS itself supports headers. However, this nats.js client does not. In particular, this function in
kv/src/kv.ts
obviously doesn't support setting arbitrary user-specified headers:I propose adding the following code after the if block above (and changing the typings appropriately):
This makes it possible to set a header whenever setting a key.
Use case
This is an extremely useful primitive to have. E.g., today (for cocalc.com) I implemented chunking on top of the kv store so that I could store arbitrarily large values transparently, even if the configured server message size is small. To implement this, I absolutely needed headers. As a workaround, I just copy/pasted the put function and made the suggested modification above.
Contribution
Yes.
The text was updated successfully, but these errors were encountered: