public unsafe IDriverNode Find(string path) { // 1) Locate children TS first. ulong childrenTS; Block block = journal.ReadService.Read(BlockType.NodeHeaderBlock, commonAddress); fixed(byte *p = block.Data) { NodeCommonHeader *header = (NodeCommonHeader *)p; childrenTS = header->ChildrenBTree; } // 2) Search in B+ tree. BPlusTree tree = new BPlusTree(childrenTS); ObjectInfo info = tree.Find(journal.ReadService, (uint)path.GetHashCode()); if (info == null) { return(null); } // 3) Find the actual object address. BlockStream stream = BlockStream.FromBase(info.Address, journal.ReadService); ChildTag childTag = Common.DeserializeFromArray(stream.Read(info.Size)) as ChildTag; ulong? address = childTag.Find(path); if (!address.HasValue) { return(null); // May only match hash value. } // Return the physical node (most current version). return(new PhysicalNode(path, address.Value, journal)); }
public unsafe void DeleteChild(string name) { // 1) Find children TS. ulong childTS = 0; Block block = journal.ReadService.Read(BlockType.NodeHeaderBlock, commonAddress); fixed(byte *p = block.Data) { NodeCommonHeader *header = (NodeCommonHeader *)p; childTS = header->ChildrenBTree; } // 2) Find child. BPlusTree tree = new BPlusTree(childTS); ObjectInfo info = tree.Find(journal.ReadService, (uint)name.GetHashCode()); BlockStream stream = BlockStream.FromBase(info.Address, journal.ReadService); ChildTag tag = Common.DeserializeFromArray(stream.Read(info.Size)) as ChildTag; ulong? childAddress = tag.Find(name); // Execute operation Operations.DeleteChild deleteChild = new DeleteChild(childAddress.Value, childTS, name); journal.Execute(deleteChild); }