Skip to content

Conversation

@ramananeesh
Copy link

Adds support for STREAMS in Garnet.

Index Structure

Uses an in-memory B+tree (B-tree) index that has the following features:

  1. Fast insertions through the tail leaf node of the index, taking advantage of sorted data input.
  2. Maximizes leaf occupancy, taking advantage of sorted data input.
  3. Uses tombstones for deletes.
  4. Supports forward and reverse range scans.

Supported Operations in API

The following operations are currently supported:

  1. XADD - add using auto-generated id and user-defined id. Does not currently support [NOMKSTREAM], [MAXLEN], [MINID] and [threshold]
  2. XLEN
  3. XRANGE
  4. XDEL

STREAMID

Stream ID is a 128-bit ID for an entry in the Stream that is of a format ts-seq where ts is generally the timestamp and seq is the sequence number.

STREAM

The Stream Object that consists of an instance to its B-tree index and a Tsavorite log instance for persistence. Every entry added to a Stream is first inserted into the Tsavorite log that returns the added address. This address is added as the value to the index using the STREAMID as key.

StreamManager

A container/wrapper that holds all Streams in the server in a dictionary.

SessionStreamCache

A local cache of Streams added by the client for faster access. Currently capped at capacity and uses a simple FIFO policy for the initial version. Can be extended to support other eviction strategies (preferably LRU).

Copy link
Contributor

@PaulusParssinen PaulusParssinen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First thanks for contributing!

I see the PR is marked as draft, but there's misunderstanding about the nature of Unsafe.AsPointer I want to help with as early as possible: It's use is always a mistake and unnecessary. Embrace Span<T> and normal struct usage as much as possible. I left few preliminary comments.

@prvyk
Copy link
Contributor

prvyk commented Mar 24, 2025

Two nits:

  1. FLUSHDB/FLUSHALL should clear the sequence number.
  2. Return value is bulk string, not simple string.

@badrishc badrishc marked this pull request as ready for review July 9, 2025 01:22
@TalZaccai TalZaccai merged commit dc0e847 into microsoft:research Jul 10, 2025
1 check passed
@prvyk
Copy link
Contributor

prvyk commented Aug 11, 2025

Is closing this intentional? A tracking PR could be useful for this...

@davidglassborow
Copy link
Contributor

I'm also interested in it's status, streams allows us to use KEDA scaling in K8

@prvyk prvyk mentioned this pull request Sep 17, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants