Esempio n. 1
0
        public unsafe void Execute(uint stage, SharpMedia.Database.Physical.Journalling.IService service)
        {
            Debug.Assert(stage == 0);

            // 1) We first write object to stream.
            BlockStream stream = service.AllocationContext.CreateBlockStream((ulong)objectData.LongLength);

            stream.Write(objectData);

            // 2) We may need to delete object from B+ stream.
            Block block = service.Read(BlockType.TypedStreamHeader, typedStreamHeader);

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

                // We may need to delete link.
                if (header->ObjectsAddress != 0)
                {
                    BlockStream objToDelete = BlockStream.FromBase(header->ObjectsAddress, service);
                    objToDelete.Deallocate();
                }

                // 3) We must relink it to out block.
                header->ObjectsAddress = stream.BaseAddress;
                header->ObjectSize     = (ulong)objectData.LongLength;
            }

            service.Write(BlockType.TypedStreamHeader, typedStreamHeader, block);
        }
Esempio n. 2
0
        public unsafe void Execute(uint stage, SharpMedia.Database.Physical.Journalling.IService service)
        {
            // 1) We first delete header node entry.
            Block versionNodeBlock = service.Read(BlockType.NodeHeaderBlock, nodeVersionAddress);
            ulong tsHeaderAddress  = NodeVersionHelper.RemoveTypedStream(tsToDeleteIndex, versionNodeBlock);

            // 2) We delete all objects.
            Block tsHeader = service.Read(BlockType.TypedStreamHeader, tsHeaderAddress);

            fixed(byte *p = tsHeader.Data)
            {
                TypedStreamHeader *header = (TypedStreamHeader *)p;

                if ((header->Options & StreamOptions.SingleObject) != 0)
                {
                    BlockStream stream = BlockStream.FromBase(header->ObjectsAddress, service);
                    stream.Deallocate();
                }
                else
                {
                    // We have to delete whole link.
                    BPlusTree         tree = new BPlusTree(header->ObjectsAddress);
                    List <ObjectInfo> all  = tree.ListAll(service);
                    foreach (ObjectInfo info in all)
                    {
                        BlockStream stream = BlockStream.FromBase(info.Address, service);
                        stream.Deallocate();
                    }

                    // Make sure we get rid of tree.
                    tree.DeallocateTree(service);
                }
            }

            // 3) We delete typed stream.
            service.DeAllocate(tsHeaderAddress);
        }