What is a bookmark?
A bookmark is an entry in a stream, and therefore has an entry number, denoted by . A bookmark is essentially a string of bytes. It links an to a string of bytes in a way that is meaningful to an application. Stream clients can request stream servers to start the stream from a particular bookmark using the method. A bookmark is a type of a stream entry, used as an identifier. It points to a specific position in the stream from which the stream server must begin the streaming.
StartBookmark command
In addition to the and commands of the client-server protocol, a command called is added. In the similar way the and commands are identified by and , respectively, the command is identified with the number . The command is as follows: As previously seen with other commands, refers to the network associated with the stream source. When calling the function, and the corresponding message is sent to the stream server, the stream client must provide a bookmark. That is, a string of bytes together with the length of the string, denoted by . Example: Consider the Polygon zkEVM case, where entries are L2 blocks. As seen in the above diagram, a bookmark precedes events. In this context, the data of each block is preceded by a bookmark entry, and this bookmark entry contains among other things the block number. It is more meaningful to use the in the Polygon zkEVM context. That is, the of the block with which the streaming must begin as requested by the stream client.Bookmarks DB
Although stream entries are recorded in the stream file, there’s a database called Bookmarks DB, which is specifically for storing all bookmarks. The Bookmarks DB is a key-value database that maps a bookmark (used as a key) with its entry number (used as the value). The technology behind Bookmarks DB is LevelDB, which is an open-source, fast key-value storage library written by Google’s developers. So, when a stream client requests the stream server to start streaming from a specific bookmark, it provides the bookmark as a string of bytes. The stream server performs a binary search in order to locate the bookmark in the Bookmarks DB, and fetches the corresponding from the Bookmarks DB. It then begins to stream entries, starting from the onwards.