grumpydb 5.0.0

A disk-based object storage engine with B+Tree indexing and page-based storage
Documentation
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
//! Binary codec for Value serialization/deserialization.
//!
//! Each value is prefixed by a 1-byte type tag. Nested structures are
//! encoded recursively. All integers use little-endian byte order.

use std::collections::BTreeMap;

use uuid::Uuid;

use crate::document::value::Value;
use crate::error::{GrumpyError, Result};

// ── Type tags ───────────────────────────────────────────────────────────

const TAG_NULL: u8 = 0x00;
const TAG_BOOL: u8 = 0x01;
const TAG_INTEGER: u8 = 0x02;
const TAG_FLOAT: u8 = 0x03;
const TAG_STRING: u8 = 0x04;
const TAG_BYTES: u8 = 0x05;
const TAG_ARRAY: u8 = 0x06;
const TAG_OBJECT: u8 = 0x07;
const TAG_REF: u8 = 0x08;
/// Tombstone marker (Phase 40d). Format-locking — DO NOT REUSE in v6+.
const TAG_TOMBSTONE: u8 = 0x09;

/// Maximum collection name length in a Ref (from naming rules).
const MAX_REF_NAME_LEN: u32 = 64;

/// Maximum encoded vector-clock length stored inside a tombstone payload.
/// Defensive cap (matches `MAX_VCLOCK_ENTRIES * 24 + 2` ≈ 100 KiB) so
/// malformed input cannot cause unbounded allocations.
const MAX_TOMBSTONE_VCLOCK_LEN: u32 = 128 * 1024;

// ── Safety limits ───────────────────────────────────────────────────────

/// Maximum nesting depth for decode (prevents stack overflow).
const MAX_NESTING_DEPTH: usize = 64;
/// Maximum string/bytes length (16 MiB).
const MAX_BLOB_LEN: u32 = 16 * 1024 * 1024;
/// Maximum array element count.
const MAX_ARRAY_LEN: u32 = 1_000_000;
/// Maximum object key count.
const MAX_OBJECT_KEYS: u32 = 100_000;

// ── Encode ──────────────────────────────────────────────────────────────

/// Encodes a `Value` into a byte buffer.
pub fn encode(value: &Value, buf: &mut Vec<u8>) {
    match value {
        Value::Null => buf.push(TAG_NULL),
        Value::Bool(b) => {
            buf.push(TAG_BOOL);
            buf.push(u8::from(*b));
        }
        Value::Integer(n) => {
            buf.push(TAG_INTEGER);
            buf.extend_from_slice(&n.to_le_bytes());
        }
        Value::Float(f) => {
            buf.push(TAG_FLOAT);
            buf.extend_from_slice(&f.to_le_bytes());
        }
        Value::String(s) => {
            buf.push(TAG_STRING);
            buf.extend_from_slice(&(s.len() as u32).to_le_bytes());
            buf.extend_from_slice(s.as_bytes());
        }
        Value::Bytes(b) => {
            buf.push(TAG_BYTES);
            buf.extend_from_slice(&(b.len() as u32).to_le_bytes());
            buf.extend_from_slice(b);
        }
        Value::Array(arr) => {
            buf.push(TAG_ARRAY);
            buf.extend_from_slice(&(arr.len() as u32).to_le_bytes());
            for item in arr {
                encode(item, buf);
            }
        }
        Value::Object(map) => {
            buf.push(TAG_OBJECT);
            buf.extend_from_slice(&(map.len() as u32).to_le_bytes());
            for (key, val) in map {
                buf.extend_from_slice(&(key.len() as u32).to_le_bytes());
                buf.extend_from_slice(key.as_bytes());
                encode(val, buf);
            }
        }
        Value::Ref(collection, uuid) => {
            buf.push(TAG_REF);
            buf.extend_from_slice(&(collection.len() as u32).to_le_bytes());
            buf.extend_from_slice(collection.as_bytes());
            buf.extend_from_slice(uuid.as_bytes());
        }
        Value::Tombstone {
            deleted_at_hlc,
            vector_clock,
        } => {
            buf.push(TAG_TOMBSTONE);
            buf.extend_from_slice(&deleted_at_hlc.to_le_bytes());
            buf.extend_from_slice(&(vector_clock.len() as u32).to_le_bytes());
            buf.extend_from_slice(vector_clock);
        }
    }
}

/// Convenience: encode a value into a new Vec.
pub fn encode_to_vec(value: &Value) -> Vec<u8> {
    let mut buf = Vec::with_capacity(encoded_size(value));
    encode(value, &mut buf);
    buf
}

// ── Encoded size ────────────────────────────────────────────────────────

/// Computes the encoded byte size of a value without allocating.
pub fn encoded_size(value: &Value) -> usize {
    match value {
        Value::Null => 1,
        Value::Bool(_) => 2,
        Value::Integer(_) | Value::Float(_) => 9,
        Value::String(s) => 1 + 4 + s.len(),
        Value::Bytes(b) => 1 + 4 + b.len(),
        Value::Array(arr) => 1 + 4 + arr.iter().map(encoded_size).sum::<usize>(),
        Value::Object(map) => {
            1 + 4
                + map
                    .iter()
                    .map(|(k, v)| 4 + k.len() + encoded_size(v))
                    .sum::<usize>()
        }
        Value::Ref(collection, _) => 1 + 4 + collection.len() + 16,
        Value::Tombstone { vector_clock, .. } => 1 + 8 + 4 + vector_clock.len(),
    }
}

// ── Decode ──────────────────────────────────────────────────────────────

/// Decodes a `Value` from a byte slice.
pub fn decode(data: &[u8]) -> Result<Value> {
    let mut cursor = data;
    let value = decode_recursive(&mut cursor, 0)?;
    Ok(value)
}

/// Decodes from a cursor, returning the value and advancing the cursor.
/// Also used by Document::decode which needs to track position.
pub fn decode_from_cursor(cursor: &mut &[u8]) -> Result<Value> {
    decode_recursive(cursor, 0)
}

fn decode_recursive(cursor: &mut &[u8], depth: usize) -> Result<Value> {
    if depth > MAX_NESTING_DEPTH {
        return Err(GrumpyError::Codec(format!(
            "nesting depth exceeds maximum ({MAX_NESTING_DEPTH})"
        )));
    }

    let tag = read_u8(cursor)?;
    match tag {
        TAG_NULL => Ok(Value::Null),
        TAG_BOOL => {
            let b = read_u8(cursor)?;
            Ok(Value::Bool(b != 0))
        }
        TAG_INTEGER => {
            let n = read_i64_le(cursor)?;
            Ok(Value::Integer(n))
        }
        TAG_FLOAT => {
            let f = read_f64_le(cursor)?;
            Ok(Value::Float(f))
        }
        TAG_STRING => {
            let len = read_u32_le(cursor)?;
            if len > MAX_BLOB_LEN {
                return Err(GrumpyError::Codec(format!(
                    "string length {len} exceeds maximum ({MAX_BLOB_LEN})"
                )));
            }
            let s = read_string(cursor, len as usize)?;
            Ok(Value::String(s))
        }
        TAG_BYTES => {
            let len = read_u32_le(cursor)?;
            if len > MAX_BLOB_LEN {
                return Err(GrumpyError::Codec(format!(
                    "bytes length {len} exceeds maximum ({MAX_BLOB_LEN})"
                )));
            }
            let b = read_bytes(cursor, len as usize)?;
            Ok(Value::Bytes(b))
        }
        TAG_ARRAY => {
            let count = read_u32_le(cursor)?;
            if count > MAX_ARRAY_LEN {
                return Err(GrumpyError::Codec(format!(
                    "array length {count} exceeds maximum ({MAX_ARRAY_LEN})"
                )));
            }
            let mut arr = Vec::with_capacity(count as usize);
            for _ in 0..count {
                arr.push(decode_recursive(cursor, depth + 1)?);
            }
            Ok(Value::Array(arr))
        }
        TAG_OBJECT => {
            let count = read_u32_le(cursor)?;
            if count > MAX_OBJECT_KEYS {
                return Err(GrumpyError::Codec(format!(
                    "object key count {count} exceeds maximum ({MAX_OBJECT_KEYS})"
                )));
            }
            let mut map = BTreeMap::new();
            for _ in 0..count {
                let key_len = read_u32_le(cursor)?;
                if key_len > MAX_BLOB_LEN {
                    return Err(GrumpyError::Codec(format!(
                        "object key length {key_len} exceeds maximum ({MAX_BLOB_LEN})"
                    )));
                }
                let key = read_string(cursor, key_len as usize)?;
                let val = decode_recursive(cursor, depth + 1)?;
                map.insert(key, val);
            }
            Ok(Value::Object(map))
        }
        TAG_REF => {
            let name_len = read_u32_le(cursor)?;
            if name_len > MAX_REF_NAME_LEN {
                return Err(GrumpyError::Codec(format!(
                    "ref collection name length {name_len} exceeds maximum ({MAX_REF_NAME_LEN})"
                )));
            }
            let collection = read_string(cursor, name_len as usize)?;
            let uuid_bytes = read_bytes(cursor, 16)?;
            let uuid = {
                let mut arr = [0u8; 16];
                arr.copy_from_slice(&uuid_bytes);
                Uuid::from_bytes(arr)
            };
            Ok(Value::Ref(collection, uuid))
        }
        TAG_TOMBSTONE => {
            // 8 bytes packed HLC + length-prefixed encoded vector clock.
            let mut hlc_bytes = [0u8; 8];
            if cursor.len() < 8 {
                return Err(GrumpyError::Codec(
                    "unexpected end of data reading tombstone HLC".into(),
                ));
            }
            hlc_bytes.copy_from_slice(&cursor[..8]);
            let deleted_at_hlc = u64::from_le_bytes(hlc_bytes);
            *cursor = &cursor[8..];

            let vc_len = read_u32_le(cursor)?;
            if vc_len > MAX_TOMBSTONE_VCLOCK_LEN {
                return Err(GrumpyError::Codec(format!(
                    "tombstone vector clock length {vc_len} exceeds maximum \
                     ({MAX_TOMBSTONE_VCLOCK_LEN})"
                )));
            }
            let vector_clock = read_bytes(cursor, vc_len as usize)?;
            Ok(Value::Tombstone {
                deleted_at_hlc,
                vector_clock,
            })
        }
        _ => Err(GrumpyError::Codec(format!("unknown type tag: 0x{tag:02x}"))),
    }
}

// ── Cursor helpers ──────────────────────────────────────────────────────

fn read_u8(cursor: &mut &[u8]) -> Result<u8> {
    if cursor.is_empty() {
        return Err(GrumpyError::Codec("unexpected end of data".into()));
    }
    let val = cursor[0];
    *cursor = &cursor[1..];
    Ok(val)
}

fn read_u32_le(cursor: &mut &[u8]) -> Result<u32> {
    if cursor.len() < 4 {
        return Err(GrumpyError::Codec(
            "unexpected end of data reading u32".into(),
        ));
    }
    let val = u32::from_le_bytes([cursor[0], cursor[1], cursor[2], cursor[3]]);
    *cursor = &cursor[4..];
    Ok(val)
}

fn read_i64_le(cursor: &mut &[u8]) -> Result<i64> {
    if cursor.len() < 8 {
        return Err(GrumpyError::Codec(
            "unexpected end of data reading i64".into(),
        ));
    }
    let val = i64::from_le_bytes([
        cursor[0], cursor[1], cursor[2], cursor[3], cursor[4], cursor[5], cursor[6], cursor[7],
    ]);
    *cursor = &cursor[8..];
    Ok(val)
}

fn read_f64_le(cursor: &mut &[u8]) -> Result<f64> {
    if cursor.len() < 8 {
        return Err(GrumpyError::Codec(
            "unexpected end of data reading f64".into(),
        ));
    }
    let val = f64::from_le_bytes([
        cursor[0], cursor[1], cursor[2], cursor[3], cursor[4], cursor[5], cursor[6], cursor[7],
    ]);
    *cursor = &cursor[8..];
    Ok(val)
}

fn read_bytes(cursor: &mut &[u8], len: usize) -> Result<Vec<u8>> {
    if cursor.len() < len {
        return Err(GrumpyError::Codec(format!(
            "unexpected end of data: need {len} bytes, have {}",
            cursor.len()
        )));
    }
    let val = cursor[..len].to_vec();
    *cursor = &cursor[len..];
    Ok(val)
}

fn read_string(cursor: &mut &[u8], len: usize) -> Result<String> {
    let bytes = read_bytes(cursor, len)?;
    String::from_utf8(bytes).map_err(|e| GrumpyError::Codec(format!("invalid UTF-8: {e}")))
}

#[cfg(test)]
mod tests {
    use super::*;

    fn round_trip(value: &Value) {
        let encoded = encode_to_vec(value);
        assert_eq!(
            encoded.len(),
            encoded_size(value),
            "encoded_size mismatch for {value:?}"
        );
        let decoded = decode(&encoded).unwrap();
        assert_eq!(*value, decoded);
    }

    #[test]
    fn test_null_round_trip() {
        round_trip(&Value::Null);
    }

    #[test]
    fn test_bool_round_trip() {
        round_trip(&Value::Bool(true));
        round_trip(&Value::Bool(false));
    }

    #[test]
    fn test_integer_round_trip() {
        round_trip(&Value::Integer(0));
        round_trip(&Value::Integer(42));
        round_trip(&Value::Integer(-1));
        round_trip(&Value::Integer(i64::MAX));
        round_trip(&Value::Integer(i64::MIN));
    }

    #[test]
    fn test_float_round_trip() {
        round_trip(&Value::Float(0.0));
        round_trip(&Value::Float(std::f64::consts::PI));
        round_trip(&Value::Float(-1.0e100));
        round_trip(&Value::Float(f64::INFINITY));
        round_trip(&Value::Float(f64::NEG_INFINITY));
    }

    #[test]
    fn test_string_round_trip() {
        round_trip(&Value::String(String::new()));
        round_trip(&Value::String("hello".into()));
        round_trip(&Value::String("émoji: 🦀".into()));
        round_trip(&Value::String("a".repeat(10_000)));
    }

    #[test]
    fn test_bytes_round_trip() {
        round_trip(&Value::Bytes(vec![]));
        round_trip(&Value::Bytes(vec![0, 1, 2, 255]));
        round_trip(&Value::Bytes(vec![0xAB; 5000]));
    }

    #[test]
    fn test_array_round_trip() {
        round_trip(&Value::Array(vec![]));
        round_trip(&Value::Array(vec![
            Value::Integer(1),
            Value::String("two".into()),
            Value::Null,
        ]));
    }

    #[test]
    fn test_object_round_trip() {
        round_trip(&Value::Object(BTreeMap::new()));
        round_trip(&Value::Object(BTreeMap::from([
            ("name".into(), Value::String("grumpy".into())),
            ("version".into(), Value::Integer(1)),
        ])));
    }

    #[test]
    fn test_nested_complex_document() {
        let value = Value::Object(BTreeMap::from([
            ("name".into(), Value::String("GrumpyDB".into())),
            ("version".into(), Value::Integer(1)),
            ("active".into(), Value::Bool(true)),
            ("score".into(), Value::Float(99.5)),
            ("data".into(), Value::Bytes(vec![0xDE, 0xAD])),
            (
                "tags".into(),
                Value::Array(vec![
                    Value::String("db".into()),
                    Value::String("rust".into()),
                    Value::Null,
                ]),
            ),
            (
                "metadata".into(),
                Value::Object(BTreeMap::from([
                    ("created".into(), Value::Integer(1234567890)),
                    (
                        "nested".into(),
                        Value::Object(BTreeMap::from([("deep".into(), Value::Bool(true))])),
                    ),
                ])),
            ),
        ]));
        round_trip(&value);
    }

    #[test]
    fn test_encoded_size_matches() {
        let values = vec![
            Value::Null,
            Value::Bool(true),
            Value::Integer(42),
            Value::Float(std::f64::consts::PI),
            Value::String("test".into()),
            Value::Bytes(vec![1, 2, 3]),
            Value::Array(vec![Value::Integer(1), Value::Integer(2)]),
            Value::Object(BTreeMap::from([("k".into(), Value::Null)])),
        ];
        for v in &values {
            let encoded = encode_to_vec(v);
            assert_eq!(encoded.len(), encoded_size(v), "mismatch for {v:?}");
        }
    }

    #[test]
    fn test_decode_unknown_tag() {
        let data = [0xFF];
        let result = decode(&data);
        assert!(result.is_err());
        let msg = result.unwrap_err().to_string();
        assert!(msg.contains("unknown type tag"));
    }

    #[test]
    fn test_decode_truncated_string() {
        // Encode a string, then truncate
        let encoded = encode_to_vec(&Value::String("hello".into()));
        let truncated = &encoded[..3]; // tag + partial len
        assert!(decode(truncated).is_err());
    }

    #[test]
    fn test_decode_truncated_integer() {
        let encoded = encode_to_vec(&Value::Integer(42));
        let truncated = &encoded[..5]; // tag + 4 bytes instead of 8
        assert!(decode(truncated).is_err());
    }

    #[test]
    fn test_decode_empty_data() {
        assert!(decode(&[]).is_err());
    }

    #[test]
    fn test_decode_invalid_utf8() {
        // Manually craft a String tag with invalid UTF-8
        let mut data = vec![TAG_STRING];
        data.extend_from_slice(&3u32.to_le_bytes());
        data.extend_from_slice(&[0xFF, 0xFE, 0xFD]); // invalid UTF-8
        let result = decode(&data);
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("UTF-8"));
    }

    #[test]
    fn test_nesting_depth_limit() {
        // Build a deeply nested array: [[[[...]]]]
        let mut value = Value::Null;
        for _ in 0..MAX_NESTING_DEPTH + 5 {
            value = Value::Array(vec![value]);
        }
        let encoded = encode_to_vec(&value);
        let result = decode(&encoded);
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("nesting depth"));
    }

    #[test]
    fn test_nesting_at_max_depth_ok() {
        // Exactly at MAX_NESTING_DEPTH should work
        let mut value = Value::Null;
        for _ in 0..MAX_NESTING_DEPTH {
            value = Value::Array(vec![value]);
        }
        let encoded = encode_to_vec(&value);
        assert!(decode(&encoded).is_ok());
    }

    #[test]
    fn test_empty_containers() {
        round_trip(&Value::String(String::new()));
        round_trip(&Value::Bytes(vec![]));
        round_trip(&Value::Array(vec![]));
        round_trip(&Value::Object(BTreeMap::new()));
    }

    #[test]
    fn test_float_nan() {
        // NaN encodes/decodes but NaN != NaN, so we check manually
        let encoded = encode_to_vec(&Value::Float(f64::NAN));
        let decoded = decode(&encoded).unwrap();
        match decoded {
            Value::Float(f) => assert!(f.is_nan()),
            _ => panic!("expected Float"),
        }
    }

    #[test]
    fn test_ref_round_trip() {
        let uuid = Uuid::from_u128(12345);
        round_trip(&Value::Ref("users".into(), uuid));
    }

    #[test]
    fn test_ref_in_object_round_trip() {
        let uuid = Uuid::from_u128(42);
        let value = Value::Object(BTreeMap::from([
            ("name".into(), Value::String("Order #1".into())),
            ("owner".into(), Value::Ref("users".into(), uuid)),
        ]));
        round_trip(&value);
    }

    #[test]
    fn test_ref_in_array_round_trip() {
        let value = Value::Array(vec![
            Value::Ref("a".into(), Uuid::from_u128(1)),
            Value::Ref("b".into(), Uuid::from_u128(2)),
        ]);
        round_trip(&value);
    }

    #[test]
    fn test_ref_encoded_size() {
        let v = Value::Ref("users".into(), Uuid::from_u128(1));
        let encoded = encode_to_vec(&v);
        assert_eq!(encoded.len(), encoded_size(&v));
        // tag(1) + name_len(4) + "users"(5) + uuid(16) = 26
        assert_eq!(encoded.len(), 26);
    }

    #[test]
    fn test_tombstone_codec_round_trip() {
        // Empty vclock.
        let v = Value::Tombstone {
            deleted_at_hlc: 0,
            vector_clock: vec![],
        };
        round_trip(&v);
        // Realistic vclock: u16 num_entries=1 + (u128 + u64) = 26 bytes.
        let mut vc_bytes = Vec::new();
        vc_bytes.extend_from_slice(&1u16.to_le_bytes());
        vc_bytes.extend_from_slice(&12345u128.to_le_bytes());
        vc_bytes.extend_from_slice(&7u64.to_le_bytes());
        let v2 = Value::Tombstone {
            deleted_at_hlc: 0xdeadbeef_cafebabe,
            vector_clock: vc_bytes.clone(),
        };
        round_trip(&v2);

        // Sanity: tag(1) + hlc(8) + vc_len(4) + vc(26) = 39 bytes.
        let encoded = encode_to_vec(&v2);
        assert_eq!(encoded.len(), 1 + 8 + 4 + vc_bytes.len());
        assert_eq!(encoded[0], TAG_TOMBSTONE);
    }

    #[test]
    fn test_tombstone_decode_truncated_hlc() {
        // Tag + only 4 bytes of the 8-byte HLC.
        let mut data = vec![TAG_TOMBSTONE];
        data.extend_from_slice(&[0u8; 4]);
        let err = decode(&data).unwrap_err();
        assert!(err.to_string().contains("tombstone HLC"));
    }

    #[test]
    fn test_tombstone_decode_oversize_vclock_rejected() {
        let mut data = vec![TAG_TOMBSTONE];
        data.extend_from_slice(&0u64.to_le_bytes());
        // Claim a vclock far above the cap.
        data.extend_from_slice(&(MAX_TOMBSTONE_VCLOCK_LEN + 1).to_le_bytes());
        let err = decode(&data).unwrap_err();
        assert!(err.to_string().contains("vector clock length"));
    }
}