aboutsummaryrefslogtreecommitdiffstats
path: root/include/IStorageBackend.h
blob: e408c95f59539d78d739c3035e9c516adc2f79d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once

#include <cstdint>
#include <optional>
#include <string>
#include <vector>

/**
 * @file IStorageBackend.h
 * @brief Abstract KV storage backend consumed by CursorManager and Merkle.
 *
 * Storage is strictly content-addressed: every value is stored under its
 * SHA256 hex digest.  Relation membership (which tuple hashes belong to a
 * given relation) is now tracked via the Merkle B-tree maintained by the
 * Merkle class, not by this interface.  Only Put and Get are required.
 */

namespace nt
{
    /**
     * @interface IStorageBackend
     * @brief Contract between CursorManager / Merkle and a physical storage engine.
     *
     * Two primitives are sufficient:
     *   - Put: store bytes, get back the content-address (SHA256 hex).
     *   - Get: retrieve bytes by content-address.
     *
     * Both are idempotent.  The Merkle class stores node blobs via Put/Get and
     * maintains insertion-order-independent relation membership on top of these
     * two primitives.
     */
    class IStorageBackend
    {
    public:
        virtual ~IStorageBackend() = default;

        /**
         * @brief Stores a serialized value and returns its SHA256 hex hash.
         *
         * Idempotent: storing the same bytes twice does not create a duplicate.
         * The returned hash is the only valid key for subsequent Get calls.
         */
        virtual std::string Put(std::vector<uint8_t> value) = 0;

        /**
         * @brief Retrieves bytes by their SHA256 hex hash.
         * @return The stored bytes, or std::nullopt when the hash is unknown.
         */
        virtual std::optional<std::vector<uint8_t>> Get(const std::string& hash) = 0;
    };
}