kitedb 0.2.2

High-performance embedded graph database
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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
//! Node CRUD operations
//!
//! Provides functions for creating, deleting, and querying nodes.

use crate::error::{RayError, Result};
use crate::mvcc::visibility::{get_visible_version, node_exists as mvcc_node_exists};
use crate::types::*;

use super::tx::TxHandle;

// ============================================================================
// Node Options
// ============================================================================

/// Options for creating a node
#[derive(Debug, Default, Clone)]
pub struct NodeOpts {
  /// Optional unique key for the node
  pub key: Option<String>,
  /// Initial labels for the node
  pub labels: Option<Vec<LabelId>>,
  /// Initial properties for the node
  pub props: Option<Vec<(PropKeyId, PropValue)>>,
}

impl NodeOpts {
  pub fn new() -> Self {
    Self::default()
  }

  pub fn with_key(mut self, key: impl Into<String>) -> Self {
    self.key = Some(key.into());
    self
  }

  pub fn with_label(mut self, label: LabelId) -> Self {
    self.labels.get_or_insert_with(Vec::new).push(label);
    self
  }

  pub fn with_prop(mut self, key: PropKeyId, value: PropValue) -> Self {
    self.props.get_or_insert_with(Vec::new).push((key, value));
    self
  }
}

// ============================================================================
// Node Operations
// ============================================================================

/// Create a new node
pub fn create_node(handle: &mut TxHandle, opts: NodeOpts) -> Result<NodeId> {
  if handle.tx.read_only {
    return Err(RayError::ReadOnly);
  }

  let node_id = handle.db.alloc_node_id();

  let mut node_delta = NodeDelta {
    key: opts.key.clone(),
    labels: None,
    labels_deleted: None,
    props: None,
  };

  if let Some(labels) = opts.labels {
    let mut set = std::collections::HashSet::new();
    for label_id in labels {
      set.insert(label_id);
    }
    node_delta.labels = Some(set);
  }

  handle.tx.pending_created_nodes.insert(node_id, node_delta);

  if let Some(key) = opts.key {
    handle.tx.pending_key_updates.insert(key, node_id);
  }

  if let Some(props) = opts.props {
    let mut map = std::collections::HashMap::new();
    for (key_id, value) in props {
      map.insert(key_id, Some(value));
    }
    handle.tx.pending_node_props.insert(node_id, map);
  }

  if let Some(mvcc) = handle.db.mvcc.as_ref() {
    let mut tx_mgr = mvcc.tx_manager.lock();
    tx_mgr.record_write(handle.tx.txid, format!("node:{node_id}"));
  }

  Ok(node_id)
}

/// Delete a node
pub fn delete_node(handle: &mut TxHandle, node_id: NodeId) -> Result<bool> {
  if handle.tx.read_only {
    return Err(RayError::ReadOnly);
  }

  // If created in this transaction, remove it entirely
  if let Some(node_delta) = handle.tx.pending_created_nodes.remove(&node_id) {
    if let Some(key) = node_delta.key {
      handle.tx.pending_key_updates.remove(&key);
    }
    handle.tx.pending_node_props.remove(&node_id);
    handle.tx.pending_out_add.remove(&node_id);
    handle.tx.pending_out_del.remove(&node_id);
    handle.tx.pending_in_add.remove(&node_id);
    handle.tx.pending_in_del.remove(&node_id);
    handle.tx.pending_node_labels_add.remove(&node_id);
    handle.tx.pending_node_labels_del.remove(&node_id);
    handle
      .tx
      .pending_vector_sets
      .retain(|(n, _), _| *n != node_id);
    handle
      .tx
      .pending_vector_deletes
      .retain(|(n, _)| *n != node_id);
    return Ok(true);
  }

  if !node_exists_internal(handle.db, node_id) {
    return Ok(false);
  }

  handle.tx.pending_deleted_nodes.insert(node_id);

  // Cascade delete vectors for this node
  {
    let stores = handle.db.vector_stores.read();
    for (prop_key_id, store) in stores.iter() {
      if store.node_to_vector.contains_key(&node_id) {
        handle
          .tx
          .pending_vector_deletes
          .insert((node_id, *prop_key_id));
      }
    }
  }

  if let Some(mvcc) = handle.db.mvcc.as_ref() {
    let mut tx_mgr = mvcc.tx_manager.lock();
    tx_mgr.record_write(handle.tx.txid, format!("node:{node_id}"));
  }

  Ok(true)
}

/// Check if a node exists
pub fn node_exists(handle: &TxHandle, node_id: NodeId) -> bool {
  if handle.tx.pending_created_nodes.contains_key(&node_id) {
    return true;
  }
  if handle.tx.pending_deleted_nodes.contains(&node_id) {
    return false;
  }

  if let Some(mvcc) = handle.db.mvcc.as_ref() {
    let tx_snapshot_ts = handle.tx.snapshot_ts;
    let txid = handle.tx.txid;
    {
      let mut tx_mgr = mvcc.tx_manager.lock();
      tx_mgr.record_read(txid, format!("node:{node_id}"));
    }
    let vc = mvcc.version_chain.lock();
    if let Some(version) = vc.get_node_version(node_id) {
      return mvcc_node_exists(Some(version), tx_snapshot_ts, txid);
    }
  }

  node_exists_db(handle.db, node_id)
}

/// Internal node existence check (on GraphDB directly)
fn node_exists_internal(db: &super::db::GraphDB, node_id: NodeId) -> bool {
  node_exists_db(db, node_id)
}

// ============================================================================
// Direct Read Functions (No Transaction Required)
// ============================================================================
// These functions read directly from snapshot + delta without transaction
// overhead, matching the TypeScript implementation pattern.

/// Check if a node exists (direct read, no transaction)
pub fn node_exists_db(db: &super::db::GraphDB, node_id: NodeId) -> bool {
  if let Some(mvcc) = db.mvcc.as_ref() {
    let tx_snapshot_ts = mvcc.tx_manager.lock().get_next_commit_ts();
    let txid = 0;
    let vc = mvcc.version_chain.lock();
    if let Some(version) = vc.get_node_version(node_id) {
      return mvcc_node_exists(Some(version), tx_snapshot_ts, txid);
    }
  }

  let delta = db.delta.read();

  if delta.is_node_deleted(node_id) {
    return false;
  }

  if delta.is_node_created(node_id) {
    return true;
  }

  // Check snapshot
  if let Some(ref snapshot) = db.snapshot {
    return snapshot.has_node(node_id);
  }

  false
}

/// Get a node by its key (direct read, no transaction)
pub fn get_node_by_key_db(db: &super::db::GraphDB, key: &str) -> Option<NodeId> {
  let delta = db.delta.read();

  // Check if key was deleted in delta
  if delta.key_index_deleted.contains(key) {
    return None;
  }

  // Check if key exists in delta
  if let Some(node_id) = delta.get_node_by_key(key) {
    // Make sure the node isn't deleted
    if !delta.is_node_deleted(node_id) {
      return Some(node_id);
    }
  }

  // Check snapshot
  if let Some(ref snapshot) = db.snapshot {
    if let Some(node_id) = snapshot.lookup_by_key(key) {
      // Make sure node wasn't deleted in delta
      if !delta.is_node_deleted(node_id) {
        return Some(node_id);
      }
    }
  }

  None
}

/// Get a node property (direct read, no transaction)
pub fn get_node_prop_db(
  db: &super::db::GraphDB,
  node_id: NodeId,
  key_id: PropKeyId,
) -> Option<PropValue> {
  if let Some(mvcc) = db.mvcc.as_ref() {
    let tx_snapshot_ts = mvcc.tx_manager.lock().get_next_commit_ts();
    let txid = 0;
    let vc = mvcc.version_chain.lock();
    if let Some(prop_version) = vc.get_node_prop_version(node_id, key_id) {
      if let Some(visible) = get_visible_version(&prop_version, tx_snapshot_ts, txid) {
        return visible.data.clone();
      }
    }
  }

  get_node_prop_committed(db, node_id, key_id)
}

/// Get a node property from committed state only (snapshot + delta)
pub fn get_node_prop_committed(
  db: &super::db::GraphDB,
  node_id: NodeId,
  key_id: PropKeyId,
) -> Option<PropValue> {
  let delta = db.delta.read();

  // Check if node is deleted
  if delta.is_node_deleted(node_id) {
    return None;
  }

  // Check delta for property (Some(Some(v)) = set, Some(None) = deleted)
  if let Some(value_opt) = delta.get_node_prop(node_id, key_id) {
    return value_opt.cloned();
  }

  // Check snapshot
  if let Some(ref snapshot) = db.snapshot {
    if let Some(phys) = snapshot.get_phys_node(node_id) {
      return snapshot.get_node_prop(phys, key_id);
    }
  }

  None
}

/// Get all node properties (direct read, no transaction)
pub fn get_node_props_db(
  db: &super::db::GraphDB,
  node_id: NodeId,
) -> Option<std::collections::HashMap<PropKeyId, PropValue>> {
  use std::collections::HashMap;

  let delta = db.delta.read();
  if delta.is_node_deleted(node_id) {
    return None;
  }

  let mut props = HashMap::new();
  let node_created_in_delta = delta.is_node_created(node_id);
  let mut node_exists_in_snapshot = false;

  if let Some(ref snapshot) = db.snapshot {
    if let Some(phys) = snapshot.get_phys_node(node_id) {
      node_exists_in_snapshot = true;
      if let Some(snapshot_props) = snapshot.get_node_props(phys) {
        props = snapshot_props;
      }
    }
  }

  if !node_created_in_delta && !node_exists_in_snapshot {
    return None;
  }

  if let Some(node_delta) = delta
    .created_nodes
    .get(&node_id)
    .or_else(|| delta.modified_nodes.get(&node_id))
  {
    if let Some(delta_props) = node_delta.props.as_ref() {
      for (&key_id, value) in delta_props {
        match value {
          Some(v) => {
            props.insert(key_id, v.clone());
          }
          None => {
            props.remove(&key_id);
          }
        }
      }
    }
  }

  Some(props)
}

// ============================================================================
// Node Label Operations
// ============================================================================

/// Add a label to a node
pub fn add_node_label(handle: &mut TxHandle, node_id: NodeId, label_id: LabelId) -> Result<()> {
  if handle.tx.read_only {
    return Err(RayError::ReadOnly);
  }

  if let Some(node_delta) = handle.tx.pending_created_nodes.get_mut(&node_id) {
    let labels = node_delta
      .labels
      .get_or_insert_with(std::collections::HashSet::new);
    labels.insert(label_id);
  } else {
    if let Some(removed) = handle.tx.pending_node_labels_del.get_mut(&node_id) {
      removed.remove(&label_id);
      if removed.is_empty() {
        handle.tx.pending_node_labels_del.remove(&node_id);
      }
    }
    handle
      .tx
      .pending_node_labels_add
      .entry(node_id)
      .or_default()
      .insert(label_id);
  }

  if let Some(mvcc) = handle.db.mvcc.as_ref() {
    let mut tx_mgr = mvcc.tx_manager.lock();
    tx_mgr.record_write(handle.tx.txid, format!("node:{node_id}"));
  }

  Ok(())
}

/// Remove a label from a node
pub fn remove_node_label(handle: &mut TxHandle, node_id: NodeId, label_id: LabelId) -> Result<()> {
  if handle.tx.read_only {
    return Err(RayError::ReadOnly);
  }

  if let Some(node_delta) = handle.tx.pending_created_nodes.get_mut(&node_id) {
    if let Some(labels) = node_delta.labels.as_mut() {
      labels.remove(&label_id);
    }
  } else {
    if let Some(added) = handle.tx.pending_node_labels_add.get_mut(&node_id) {
      added.remove(&label_id);
      if added.is_empty() {
        handle.tx.pending_node_labels_add.remove(&node_id);
      }
    }
    handle
      .tx
      .pending_node_labels_del
      .entry(node_id)
      .or_default()
      .insert(label_id);
  }

  if let Some(mvcc) = handle.db.mvcc.as_ref() {
    let mut tx_mgr = mvcc.tx_manager.lock();
    tx_mgr.record_write(handle.tx.txid, format!("node:{node_id}"));
  }

  Ok(())
}

/// Check if a node has a label (direct read)
pub fn node_has_label_db(db: &super::db::GraphDB, node_id: NodeId, label_id: LabelId) -> bool {
  let delta = db.delta.read();
  if delta.is_node_deleted(node_id) {
    return false;
  }

  if delta.is_label_removed(node_id, label_id) {
    return false;
  }

  if delta.is_label_added(node_id, label_id) {
    return true;
  }

  if let Some(ref snapshot) = db.snapshot {
    if let Some(phys) = snapshot.get_phys_node(node_id) {
      if let Some(labels) = snapshot.get_node_labels(phys) {
        return labels.contains(&label_id);
      }
    }
  }

  false
}

/// Get all labels for a node (direct read)
pub fn get_node_labels_db(db: &super::db::GraphDB, node_id: NodeId) -> Vec<LabelId> {
  let delta = db.delta.read();
  if delta.is_node_deleted(node_id) {
    return Vec::new();
  }

  let mut labels: std::collections::HashSet<LabelId> = std::collections::HashSet::new();

  if let Some(ref snapshot) = db.snapshot {
    if let Some(phys) = snapshot.get_phys_node(node_id) {
      if let Some(snapshot_labels) = snapshot.get_node_labels(phys) {
        labels.extend(snapshot_labels);
      }
    }
  }

  if let Some(added) = delta.get_added_labels(node_id) {
    labels.extend(added.iter().copied());
  }

  if let Some(removed) = delta.get_removed_labels(node_id) {
    for label_id in removed {
      labels.remove(label_id);
    }
  }

  labels.into_iter().collect()
}

/// Count total nodes in the database (direct read, no transaction)
pub fn count_nodes_db(db: &super::db::GraphDB) -> u64 {
  let delta = db.delta.read();

  // Start with snapshot count
  let snapshot_count = db
    .snapshot
    .as_ref()
    .map(|s| s.header.num_nodes)
    .unwrap_or(0);

  // Count nodes created in delta
  let created = delta.created_nodes.len() as u64;

  // Count nodes deleted in delta that existed in snapshot
  let mut deleted_from_snapshot = 0u64;
  if let Some(ref snapshot) = db.snapshot {
    for &node_id in &delta.deleted_nodes {
      if !delta.created_nodes.contains_key(&node_id) && snapshot.has_node(node_id) {
        deleted_from_snapshot += 1;
      }
    }
  }

  snapshot_count + created - deleted_from_snapshot
}

/// Set a node property
pub fn set_node_prop(
  handle: &mut TxHandle,
  node_id: NodeId,
  key_id: PropKeyId,
  value: PropValue,
) -> Result<()> {
  if handle.tx.read_only {
    return Err(RayError::ReadOnly);
  }

  let props = handle.tx.pending_node_props.entry(node_id).or_default();
  props.insert(key_id, Some(value));

  if let Some(mvcc) = handle.db.mvcc.as_ref() {
    let mut tx_mgr = mvcc.tx_manager.lock();
    tx_mgr.record_write(handle.tx.txid, format!("nodeprop:{node_id}:{key_id}"));
  }

  Ok(())
}

/// Delete a node property
pub fn del_node_prop(handle: &mut TxHandle, node_id: NodeId, key_id: PropKeyId) -> Result<()> {
  if handle.tx.read_only {
    return Err(RayError::ReadOnly);
  }

  let props = handle.tx.pending_node_props.entry(node_id).or_default();
  props.insert(key_id, None);

  if let Some(mvcc) = handle.db.mvcc.as_ref() {
    let mut tx_mgr = mvcc.tx_manager.lock();
    tx_mgr.record_write(handle.tx.txid, format!("nodeprop:{node_id}:{key_id}"));
  }

  Ok(())
}

/// Get a node property
pub fn get_node_prop(handle: &TxHandle, node_id: NodeId, key_id: PropKeyId) -> Option<PropValue> {
  if handle.tx.pending_deleted_nodes.contains(&node_id) {
    return None;
  }

  if let Some(pending_props) = handle.tx.pending_node_props.get(&node_id) {
    if let Some(value) = pending_props.get(&key_id) {
      return value.clone();
    }
  }

  if let Some(mvcc) = handle.db.mvcc.as_ref() {
    let tx_snapshot_ts = handle.tx.snapshot_ts;
    let txid = handle.tx.txid;
    {
      let mut tx_mgr = mvcc.tx_manager.lock();
      tx_mgr.record_read(txid, format!("nodeprop:{node_id}:{key_id}"));
    }
    let vc = mvcc.version_chain.lock();
    if let Some(prop_version) = vc.get_node_prop_version(node_id, key_id) {
      if let Some(visible) = get_visible_version(&prop_version, tx_snapshot_ts, txid) {
        return visible.data.clone();
      }
    }
  }

  let delta = handle.db.delta.read();

  if delta.is_node_deleted(node_id) {
    return None;
  }

  if let Some(value_opt) = delta.get_node_prop(node_id, key_id) {
    return value_opt.cloned();
  }

  if let Some(ref snapshot) = handle.db.snapshot {
    if let Some(phys) = snapshot.get_phys_node(node_id) {
      return snapshot.get_node_prop(phys, key_id);
    }
  }

  None
}

/// Get a node by its key
pub fn get_node_by_key(handle: &TxHandle, key: &str) -> Option<NodeId> {
  if let Some(node_id) = handle.tx.pending_key_updates.get(key) {
    return Some(*node_id);
  }
  if handle.tx.pending_key_deletes.contains(key) {
    return None;
  }

  if let Some(mvcc) = handle.db.mvcc.as_ref() {
    let mut tx_mgr = mvcc.tx_manager.lock();
    tx_mgr.record_read(handle.tx.txid, format!("key:{key}"));
  }

  get_node_by_key_db(handle.db, key)
}

/// Count total nodes in the database
pub fn count_nodes(handle: &TxHandle) -> u64 {
  let delta = handle.db.delta.read();

  // Start with snapshot count
  let snapshot_count = handle
    .db
    .snapshot
    .as_ref()
    .map(|s| s.header.num_nodes)
    .unwrap_or(0);

  // Count nodes created in delta
  let created = delta.created_nodes.len() as u64;

  // Count nodes deleted in delta that existed in snapshot
  // (only snapshot nodes should be subtracted, not delta-created-then-deleted)
  let mut deleted_from_snapshot = 0u64;
  if let Some(ref snapshot) = handle.db.snapshot {
    for &node_id in &delta.deleted_nodes {
      // Only count if it was actually in snapshot (not a delta-created node)
      if !delta.created_nodes.contains_key(&node_id) && snapshot.has_node(node_id) {
        deleted_from_snapshot += 1;
      }
    }
  }

  let mut count = snapshot_count + created - deleted_from_snapshot;

  // Apply pending deletions
  for &node_id in &handle.tx.pending_deleted_nodes {
    let in_snapshot = handle
      .db
      .snapshot
      .as_ref()
      .map(|s| s.has_node(node_id))
      .unwrap_or(false);
    let in_delta_created = delta.created_nodes.contains_key(&node_id);
    let deleted_in_delta = delta.deleted_nodes.contains(&node_id);
    if (in_snapshot || in_delta_created) && !deleted_in_delta {
      count = count.saturating_sub(1);
    }
  }

  // Add pending creations
  count + handle.tx.pending_created_nodes.len() as u64
}

// ============================================================================
// Tests
// ============================================================================

#[cfg(test)]
mod tests {
  use super::*;
  use crate::graph::db::{close_graph_db, open_graph_db, OpenOptions};
  use crate::graph::tx::{begin_tx, commit, rollback};
  use tempfile::tempdir;

  #[test]
  fn test_create_node() {
    let temp_dir = tempdir().unwrap();
    let db = open_graph_db(temp_dir.path(), OpenOptions::new()).unwrap();

    let mut tx = begin_tx(&db).unwrap();
    let node_id = create_node(&mut tx, NodeOpts::new()).unwrap();

    assert!(node_id >= 1);

    commit(&mut tx).unwrap();
    close_graph_db(db).unwrap();
  }

  #[test]
  fn test_create_node_with_key() {
    let temp_dir = tempdir().unwrap();
    let db = open_graph_db(temp_dir.path(), OpenOptions::new()).unwrap();

    let mut tx = begin_tx(&db).unwrap();
    let node_id = create_node(&mut tx, NodeOpts::new().with_key("alice")).unwrap();

    assert!(node_id >= 1);

    commit(&mut tx).unwrap();
    close_graph_db(db).unwrap();
  }

  #[test]
  fn test_create_multiple_nodes() {
    let temp_dir = tempdir().unwrap();
    let db = open_graph_db(temp_dir.path(), OpenOptions::new()).unwrap();

    let mut tx = begin_tx(&db).unwrap();

    let node1 = create_node(&mut tx, NodeOpts::new()).unwrap();
    let node2 = create_node(&mut tx, NodeOpts::new()).unwrap();
    let node3 = create_node(&mut tx, NodeOpts::new()).unwrap();

    // Node IDs should be sequential
    assert_eq!(node2, node1 + 1);
    assert_eq!(node3, node2 + 1);

    commit(&mut tx).unwrap();
    close_graph_db(db).unwrap();
  }

  #[test]
  fn test_rollback_node_creation() {
    let temp_dir = tempdir().unwrap();
    let db = open_graph_db(temp_dir.path(), OpenOptions::new()).unwrap();

    let initial_next_id = db.peek_next_node_id();

    {
      let mut tx = begin_tx(&db).unwrap();
      let _node = create_node(&mut tx, NodeOpts::new()).unwrap();
      rollback(&mut tx).unwrap();
    }

    // After rollback, next ID should have still been consumed
    // (we don't reclaim IDs on rollback)
    assert!(db.peek_next_node_id() > initial_next_id);

    close_graph_db(db).unwrap();
  }
}