public void Execute(uint stage, SharpMedia.Database.Physical.Journalling.IService service) { Debug.Assert(stage == 0); // 1) We first write to allocated block stream. BlockStream stream = service.AllocationContext.CreateBlockStream((ulong)objectData.LongLength); stream.Write(objectData); // 2) We may need to delete object at index. ObjectInfo data = tree.Find(service, index); if (data != null) { // Deallocate link. BlockStream stream2 = BlockStream.FromBase(data.Address, service); stream2.Deallocate(); // We replace the entry (cheaper than delete and rewrite). tree.Replace(service, new ObjectInfo(index, (ulong)objectData.LongLength, stream.BaseAddress)); } else { // 3) We execute insert operation. tree.Add(service, new ObjectInfo(index, (ulong)objectData.LongLength, stream.BaseAddress)); } }
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); }
public void Execute(uint stage, SharpMedia.Database.Physical.Journalling.IService service) { // 1) We read previous object placement and change it. ObjectInfo info = childrenTree.Find(service, (uint)prevName.GetHashCode()); BlockStream stream = BlockStream.FromBase(info.Address, service); ChildTag childTag = Common.DeserializeFromArray(stream.Read(info.Size)) as ChildTag; childTag.Remove(prevName); // Remove it if empty. if (childTag.IsEmpty) { childrenTree.Remove(service, (uint)prevName.GetHashCode(), 1, false); } else { // Update the entry (now without this child). byte[] childTagData = Common.SerializeToArray(childTag); stream = service.AllocationContext.CreateBlockStream((ulong)childTagData.LongLength); stream.Write(childTagData); childrenTree.Replace(service, new ObjectInfo((uint)prevName.GetHashCode(), (ulong)childTagData.LongLength, stream.BaseAddress)); } // 3) We create new and insert it into tree. ObjectInfo info2 = childrenTree.Find(service, (uint)newName.GetHashCode()); if (info2 == null) { // We create new tag. childTag = new ChildTag(); childTag.Add(newName, info.Address); byte[] childTagData = Common.SerializeToArray(childTag); stream = service.AllocationContext.CreateBlockStream((ulong)childTagData.LongLength); stream.Write(childTagData); // And we add child. childrenTree.Add(service, new ObjectInfo((uint)newName.GetHashCode(), (ulong)childTagData.LongLength, stream.BaseAddress)); } else { // We append it and release previous tag. stream = BlockStream.FromBase(info2.Address, service); childTag = Common.DeserializeFromArray(stream.Read(info2.Size)) as ChildTag; stream.Deallocate(); // We modify and rewrite it. childTag.Add(newName, info.Address); byte[] childTagData = Common.SerializeToArray(childTag); stream = service.AllocationContext.CreateBlockStream((ulong)childTagData.LongLength); stream.Write(childTagData); // We insert into children tree. childrenTree.Replace(service, new ObjectInfo((uint)newName.GetHashCode(), (ulong)childTagData.LongLength, info.Address)); } }
public void Execute(uint stage, SharpMedia.Database.Physical.Journalling.IService service) { Debug.Assert(stage == 0); foreach (AddObject op in subOperations) { op.Execute(stage, service); } }
public void Execute(uint stage, SharpMedia.Database.Physical.Journalling.IService service) { // 1) We create the object. BlockStream stream = service.AllocationContext.CreateBlockStream((ulong)objectData.LongLength); stream.Write(objectData); // 2) We insert to B+ tree. tree.Insert(service, before, new ObjectInfo(index, (ulong)objectData.LongLength, stream.BaseAddress)); }
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); }
public void Execute(uint stage, SharpMedia.Database.Physical.Journalling.IService service) { subOperationsToExecute[(int)stage].ExecuteInternal(service); }