Пример #1
0
        public object Read(uint index)
        {
            if ((options & StreamOptions.SingleObject) != 0)
            {
                if (index != 0)
                {
                    return(null);
                }
                if (objectAddress == 0)
                {
                    return(null);
                }

                // We read it.
                BlockStream stream = BlockStream.FromBase(objectAddress, journal.ReadService);
                return(stream.Read(objectSize));
            }
            else
            {
                // We have to find it in B+ tree first.
                BPlusTree  tree = new BPlusTree(objectAddress);
                ObjectInfo info = tree.Find(journal.ReadService, index);
                if (info == null)
                {
                    return(null);
                }

                // We read it.
                BlockStream stream = BlockStream.FromBase(info.Address, journal.ReadService);
                return(stream.Read(info.Size));
            }
        }
Пример #2
0
        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));
        }
Пример #3
0
        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);
        }
Пример #4
0
        public unsafe IDriverNode GetVersion(ulong version)
        {
            // 1) Extract version typed stream.
            ulong versionTS;
            Block block = journal.ReadService.Read(BlockType.NodeHeaderBlock, commonAddress);

            fixed(byte *p = block.Data)
            {
                NodeCommonHeader *header = (NodeCommonHeader *)p;

                versionTS = header->VersionsBTree;
            }

            // 2) Search for version
            BPlusTree  versionTree = new BPlusTree(versionTS);
            ObjectInfo info        = versionTree.Find(journal.ReadService, (uint)version.GetHashCode());

            if (info == null)
            {
                return(null);
            }

            // 3) Locate the version.
            BlockStream versionTagStream = BlockStream.FromBase(info.Address, journal.ReadService);
            VersionTag  versionTag       = Common.DeserializeFromArray(versionTagStream.Read(info.Size)) as VersionTag;

            ulong?rVersionAddress = versionTag.Find(version);

            if (!rVersionAddress.HasValue)
            {
                return(null);
            }

            // 4) Return the node.
            return(new PhysicalNode(name, commonAddress, rVersionAddress.Value, journal));
        }