Skip to content

Commit 0ada5bc

Browse files
wskozlowskiWojtek
andauthored
Feature/1276 (#762)
* embedded member access by offset * compact o_list + integration --------- Co-authored-by: Wojtek <wskozlowski@dbzero.io>
1 parent c5362e2 commit 0ada5bc

29 files changed

Lines changed: 1943 additions & 133 deletions

‎AGENTS.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ Types derived from `v_object` should follow the project-wide constructor pattern
4747
- New durable instances are constructed from `Memspace &` plus any type-specific creation arguments.
4848
- Existing durable instances are reopened from `mptr` plus any type-specific runtime dependencies.
4949

50+
### Overlaid type inheritance
51+
52+
Variable-size overlaid types that derive from another overlaid type must use `db0::o_ext<Derived, BaseOverlay, VER, STORE_VER>` rather than directly inheriting from an `o_base`-derived overlay such as `o_list`. Direct inheritance bypasses `o_ext` sizing, version, and dynamic-area handling and can corrupt overlaid layout assumptions.
53+
5054
### C++ style
5155

5256
- Use camelCase for local helper variables, lambdas, and method names in C++ code.

‎design/IMMUTABLE_OBJECTS_DESIGN.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,13 @@ Implementation requirements:
106106
- Field retrieval returns an object view of the root object that exposes only the nested fields for read access.
107107
- The view must maintain the lock or lifetime guard of the top-level object while nested fields are accessed.
108108
- References to embedded objects point to a memory location inside the root allocation and also carry the nested member offset. The offset may be deeply nested.
109+
- Embedded object offsets are byte offsets relative to the persisted `o_immutable_object` data structure overlaid on the root allocation, not relative to the C++ `ObjectImmutableImpl` wrapper instance.
109110
- The lifecycle of an embedded object is tied to the root instance because the root owns the allocation containing the full embedded tree.
110111
- The embedded member is identified by its own address, but that address is inside the allocation and is not the allocation start.
111112
- The allocator must be able to recover allocation metadata from an inner address. This allows embedded object addresses to use the same 50-bit representation as regular object addresses.
112113
- A parent object can still be referenced by the parent allocation address.
114+
- Root immutable objects store an exact compact index of valid nested embedded-object offsets. Lookup by offset must validate against this index and raise a bad-address error for invalid, out-of-range, or non-object offsets.
115+
- The offset index uses packed integer encoding grouped by packed size class so offsets remain compact while supporting logarithmic exact membership checks. Most offsets are expected to fit in 3-4 packed bytes, but the representation must support larger offsets.
113116

114117
## Object Views
115118

‎src/dbzero/bindings/python/embedded/EmbeddedObject.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <dbzero/object_model/class/Class.hpp>
1616
#include <dbzero/object_model/class/ClassFactory.hpp>
1717
#include <dbzero/object_model/dict/o_py_dict.hpp>
18+
#include <dbzero/object_model/object/ObjectInitializer.hpp>
1819
#include <dbzero/object_model/object/ObjectImmutableImpl.hpp>
1920
#include <dbzero/object_model/object/o_embedded_object.hpp>
2021
#include <dbzero/object_model/set/o_py_set.hpp>
@@ -629,6 +630,7 @@ namespace db0::python
629630
if (PyObject_GC_IsTracked(object)) {
630631
PyObject_GC_UnTrack(object);
631632
}
633+
InitManager::instance.tryCloseInitializer(object->ext());
632634
object->destroy();
633635
new ((void *)const_cast<MemoImmutableObject::ExtT *>(&object->ext()))
634636
EmbeddedObjectRef(rootObject, &embeddedObject, std::move(type));

‎src/dbzero/core/serialization/Types.cpp‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,23 @@ namespace db0
3232
std::copy(data.data(), data.data() + m_bytes, &m_buf);
3333
}
3434

35-
o_binary::o_binary(std::size_t size, void (*write)(void *, const void *), const void *source)
35+
o_binary::o_binary(
36+
std::size_t size,
37+
void (*write)(void *, const void *, db0::object_model::EmbeddedObjectOffsetCollector *),
38+
const void *source
39+
)
40+
: o_binary(size, write, source, nullptr)
41+
{
42+
}
43+
44+
o_binary::o_binary(
45+
std::size_t size,
46+
void (*write)(void *, const void *, db0::object_model::EmbeddedObjectOffsetCollector *),
47+
const void *source, db0::object_model::EmbeddedObjectOffsetCollector *context
48+
)
3649
: m_bytes(size)
3750
{
38-
write(&m_buf, source);
51+
write(&m_buf, source, context);
3952
}
4053

4154
o_binary &o_binary::operator=(const o_binary &binary)

‎src/dbzero/core/serialization/Types.hpp‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
#include <dbzero/core/serialization/Fixed.hpp>
99
#include <dbzero/core/compiler_attributes.hpp>
1010

11+
namespace db0::object_model
12+
{
13+
struct EmbeddedObjectOffsetCollector;
14+
}
15+
1116
namespace db0
1217

1318
{
@@ -116,7 +121,19 @@ DB0_PACKED_BEGIN
116121

117122
o_binary(const std::vector<std::byte> &);
118123

119-
o_binary(std::size_t size, void (*write)(void *, const void *), const void *source);
124+
// Optional context lets writer-backed payloads receive construction-only state.
125+
// A null context is used by measurement and ordinary copy paths.
126+
o_binary(
127+
std::size_t size,
128+
void (*write)(void *, const void *, db0::object_model::EmbeddedObjectOffsetCollector *),
129+
const void *source
130+
);
131+
132+
o_binary(
133+
std::size_t size,
134+
void (*write)(void *, const void *, db0::object_model::EmbeddedObjectOffsetCollector *),
135+
const void *source, db0::object_model::EmbeddedObjectOffsetCollector *context
136+
);
120137

121138
public:
122139
/**

0 commit comments

Comments
 (0)