public virtual void Run() { _transaction.CheckSynchronization(); if (DTrace.enabled) { DTrace.WriteUpdateAdjustIndexes.Log(_id); } if (AlreadyHandled()) { return; } // TODO: Try to get rid of getting the slot here because it // will invoke reading a pointer from the file system. // It may be possible to figure out the readd case // by asking the IdSystem in a smarter way. Slot slot = _transaction.IdSystem().CurrentSlot(_id); if (HandledAsReAdd(slot)) { return; } if (_clazz.CanUpdateFast()) { return; } StatefulBuffer objectBytes = Container().ReadStatefulBufferBySlot(_transaction, _id , slot); DeleteMembers(objectBytes); }
public DeleteContextImpl(Db4objects.Db4o.Internal.StatefulBuffer buffer, ObjectHeader objectHeader, IReflectClass fieldClass, Config4Field fieldConfig) : base(buffer .Transaction(), buffer, objectHeader) { _fieldClass = fieldClass; _fieldConfig = fieldConfig; }
/// <exception cref="Db4objects.Db4o.Internal.FieldIndexException"></exception> public override void Delete(DeleteContextImpl context, bool isUpdate) { if (!CheckAlive(context)) { return; } try { RemoveIndexEntry(context); if (isUpdate) { IncrementOffset(context); return; } StatefulBuffer buffer = (StatefulBuffer)context.Buffer(); DeleteContextImpl childContext = new DeleteContextImpl(context, GetStoredType(), _config); context.SlotFormat().DoWithSlotIndirection(buffer, GetHandler(), new _IClosure4_445 (this, childContext)); } catch (CorruptionException exc) { throw new FieldIndexException(exc, this); } }
public override void WriteFixedPart(LocalObjectContainer file, bool startFileLockingThread , bool shuttingDown, StatefulBuffer writer, int blockSize) { SystemData systemData = file.SystemData(); writer.Append(Signature); writer.WriteByte(Version()); writer.WriteInt((int)TimeToWrite(_timerFileLock.OpenTime(), shuttingDown)); writer.WriteLong(TimeToWrite(_timerFileLock.OpenTime(), shuttingDown)); writer.WriteLong(TimeToWrite(Runtime.CurrentTimeMillis(), shuttingDown)); writer.WriteInt(blockSize); writer.WriteInt(systemData.ClassCollectionID()); writer.WriteByte(systemData.IdSystemType()); writer.WriteInt(((FileHeaderVariablePart2)_variablePart).Address()); writer.WriteInt(((FileHeaderVariablePart2)_variablePart).Length()); writer.WriteInt(_transactionPointerAddress); writer.Write(); if (shuttingDown) { WriteVariablePart(file, true); } else { file.SyncFiles(); } if (startFileLockingThread) { file.ThreadPool().Start("db4o lock thread", _timerFileLock); } }
public override void ApplySlotChanges(IVisitable slotChangeTree, int slotChangeCount , Slot reservedSlot) { if (slotChangeCount > 0) { Slot transactionLogSlot = SlotLongEnoughForLog(slotChangeCount, reservedSlot) ? reservedSlot : AllocateSlot(true, slotChangeCount); StatefulBuffer buffer = new StatefulBuffer(_container.SystemTransaction(), transactionLogSlot ); buffer.WriteInt(transactionLogSlot.Length()); buffer.WriteInt(slotChangeCount); AppendSlotChanges(buffer, slotChangeTree); buffer.Write(); IRunnable commitHook = _container.CommitHook(); FlushDatabaseFile(); _container.WriteTransactionPointer(transactionLogSlot.Address()); FlushDatabaseFile(); if (WriteSlots(slotChangeTree)) { FlushDatabaseFile(); } _container.WriteTransactionPointer(0); commitHook.Run(); FlushDatabaseFile(); if (transactionLogSlot != reservedSlot) { FreeSlot(transactionLogSlot); } } FreeSlot(reservedSlot); }
/// <summary>generates a new Db4oDatabase object with a unique signature.</summary> /// <remarks>generates a new Db4oDatabase object with a unique signature.</remarks> public static Db4objects.Db4o.Ext.Db4oDatabase Generate() { StatefulBuffer writer = new StatefulBuffer(null, 300); new LatinStringIO().Write(writer, SignatureGenerator.GenerateSignature()); return new Db4objects.Db4o.Ext.Db4oDatabase(writer.GetWrittenBytes(), Runtime.CurrentTimeMillis ()); }
public static StatefulBuffer Marshall(Transaction ta, object obj) { SerializedGraph serialized = Marshall(ta.Container(), obj); StatefulBuffer buffer = new StatefulBuffer(ta, serialized.Length()); buffer.Append(serialized._bytes); buffer.UseSlot(serialized._id, 0, serialized.Length()); return buffer; }
public sealed override MsgD GetWriter(StatefulBuffer bytes) { MsgD message = GetWriterForLength(bytes.Transaction(), bytes.Length() + Const4.IntLength ); message._payLoad.WriteInt(bytes.GetAddress()); message._payLoad.Append(bytes._buffer); return message; }
protected virtual void RebuildIndexForWriter(LocalObjectContainer stream, StatefulBuffer writer, int objectId) { ObjectHeader oh = new ObjectHeader(stream, writer); object obj = ReadIndexEntryForRebuild(writer, oh); AddIndexEntry(stream.SystemTransaction(), objectId, obj); }
public virtual void Test() { StatefulBuffer writer = new StatefulBuffer(null, 300); string stringRepresentation = SignatureGenerator.GenerateSignature(); new LatinStringIO().Write(writer, stringRepresentation); Signature signature = new Signature(writer.GetWrittenBytes()); Assert.AreEqual(stringRepresentation, signature.ToString()); }
public ByteArrayBuffer ReadPayloadWriter(int offset, int length) { Db4objects.Db4o.Internal.StatefulBuffer payLoad = new Db4objects.Db4o.Internal.StatefulBuffer (_trans, 0, length); System.Array.Copy(_buffer, offset, payLoad._buffer, 0, length); TransferPayLoadAddress(payLoad, offset); return(payLoad); }
private void AppendPayLoad(StatefulBuffer target, Pointer4 pointer, ByteArrayBuffer payLoad) { target.WriteInt(payLoad.Length()); target.WriteInt(pointer.Id()); target.WriteInt(pointer.Address()); target.Append(payLoad._buffer); }
public ByteArrayBuffer ReadPayloadWriter(int offset, int length) { var payLoad = new StatefulBuffer (_trans, 0, length); Array.Copy(_buffer, offset, payLoad._buffer, 0, length); TransferPayLoadAddress(payLoad, offset); return(payLoad); }
public static StatefulBuffer Marshall(Transaction ta, object obj) { SerializedGraph serialized = Marshall(ta.Container(), obj); StatefulBuffer buffer = new StatefulBuffer(ta, serialized.Length()); buffer.Append(serialized._bytes); buffer.UseSlot(serialized._id, 0, serialized.Length()); return(buffer); }
private void TransferPayLoadAddress(StatefulBuffer toWriter , int offset) { var blockedOffset = offset / Container().BlockSize(); toWriter._address = _address + blockedOffset; toWriter._id = toWriter._address; toWriter._addressOffset = _addressOffset; }
// When a file gets opened, it uses the file size to determine where // new slots can be appended. If this method would not be called, the // freespace system could already contain a slot that points beyond // the end of the file and this space could be allocated and used twice, // for instance if a slot was allocated and freed without ever being // written to file. internal virtual void EnsureLastSlotWritten() { if (_blockEndAddress > _blockConverter.BytesToBlocks(FileLength())) { StatefulBuffer writer = CreateStatefulBuffer(SystemTransaction(), _blockEndAddress - 1, BlockSize()); writer.Write(); } }
private void TransferPayLoadAddress(Db4objects.Db4o.Internal.StatefulBuffer toWriter , int offset) { int blockedOffset = offset / Container().BlockSize(); toWriter._address = _address + blockedOffset; toWriter._id = toWriter._address; toWriter._addressOffset = _addressOffset; }
/// <exception cref="Db4objects.Db4o.Internal.FieldIndexException"></exception> protected virtual void RebuildIndexForObject(LocalObjectContainer stream, ClassMetadata classMetadata, int objectId) { StatefulBuffer writer = stream.ReadStatefulBufferById(stream.SystemTransaction(), objectId); if (writer != null) { RebuildIndexForWriter(stream, writer, objectId); } }
/// <summary>This readIndexEntry method reads from the parent slot.</summary> /// <remarks>This readIndexEntry method reads from the parent slot.</remarks> /// <exception cref="Db4objects.Db4o.CorruptionException"></exception> /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public virtual object ReadIndexEntryFromObjectSlot(MarshallerFamily mf, StatefulBuffer buffer) { int payLoadOffSet = buffer.ReadInt(); int length = buffer.ReadInt(); if (payLoadOffSet == 0) { return null; } return buffer.ReadPayloadWriter(payLoadOffSet, length); }
public Db4objects.Db4o.Internal.StatefulBuffer ReadStatefulBuffer() { int length = ReadInt(); if (length == 0) { return(null); } Db4objects.Db4o.Internal.StatefulBuffer yb = new Db4objects.Db4o.Internal.StatefulBuffer (_trans, length); System.Array.Copy(_buffer, _offset, yb._buffer, 0, length); _offset += length; return(yb); }
public StatefulBuffer ReadStatefulBuffer() { var length = ReadInt(); if (length == 0) { return(null); } var yb = new StatefulBuffer (_trans, length); Array.Copy(_buffer, _offset, yb._buffer, 0, length); _offset += length; return(yb); }
private void DeleteMembers(StatefulBuffer objectBytes) { ObjectHeader oh = new ObjectHeader(_clazz, objectBytes); DeleteInfo info = (DeleteInfo)TreeInt.Find(_transaction._delete, _id); if (info != null) { if (info._cascade > _cascade) { _cascade = info._cascade; } } objectBytes.SetCascadeDeletes(_cascade); DeleteContextImpl context = new DeleteContextImpl(objectBytes, oh, _clazz.ClassReflector (), null); _clazz.DeleteMembers(context, _typeInfo, true); }
public Msg ReplyFromServer() { StatefulBuffer bytes = null; // readWriterByID may fail in certain cases, for instance if // and object was deleted by another client int id = _payLoad.ReadInt(); int lastCommitted = _payLoad.ReadInt(); lock (ContainerLock()) { bytes = Container().ReadStatefulBufferById(Transaction(), id, lastCommitted == 1); } if (bytes == null) { bytes = new StatefulBuffer(Transaction(), 0, 0); } return Msg.ObjectToClient.GetWriter(bytes); }
private void WriteIndex(MarshallingContext context, int masterAddress, int position ) { if (_indexedField != null) { // for now this is a String index only, it takes the entire slot. StatefulBuffer buffer = new StatefulBuffer(context.Transaction(), UnblockedLength ()); int blockedPosition = context.Container().BlockConverter().BytesToBlocks(position ); int indexID = masterAddress + blockedPosition; buffer.SetID(indexID); buffer.Address(indexID); TransferContentTo(buffer, UnblockedLength()); _indexedField.AddIndexEntry(context.Transaction(), context.ObjectID(), buffer); } }
public virtual void WriteHeader(bool startFileLockingThread, bool shuttingDown) { if (shuttingDown) { _freespaceManager.Write(this); _freespaceManager = null; } StatefulBuffer writer = CreateStatefulBuffer(SystemTransaction(), 0, _fileHeader. Length()); _fileHeader.WriteFixedPart(this, startFileLockingThread, shuttingDown, writer, BlockSize ()); if (shuttingDown) { EnsureLastSlotWritten(); } SyncFiles(); }
public virtual StatefulBuffer ReadStatefulBufferBySlot(Transaction trans, int id, Slot slot) { if (Slot.IsNull(slot)) { return(null); } if (DTrace.enabled) { DTrace.ReadSlot.LogLength(slot.Address(), slot.Length()); } StatefulBuffer buffer = CreateStatefulBuffer(trans, slot.Address(), slot.Length() ); buffer.SetID(id); buffer.ReadEncrypt(this, slot.Address()); return(buffer); }
public Msg ReplyFromServer() { int address = ReadInt(); int length = ReadInt(); lock (ContainerLock()) { StatefulBuffer bytes = new StatefulBuffer(this.Transaction(), address, length); try { Container().ReadBytes(bytes._buffer, address, length); return GetWriter(bytes); } catch (Exception) { // TODO: not nicely handled on the client side yet return Msg.Null; } } }
public override void CompleteInterruptedTransaction(int transactionId1, int transactionId2 ) { if (transactionId1 <= 0 || transactionId1 != transactionId2) { return; } StatefulBuffer bytes = new StatefulBuffer(_container.SystemTransaction(), transactionId1 , Const4.IntLength); bytes.Read(); int length = bytes.ReadInt(); if (length > 0) { bytes = new StatefulBuffer(_container.SystemTransaction(), transactionId1, length ); bytes.Read(); bytes.IncrementOffset(Const4.IntLength); ReadWriteSlotChanges(bytes); } _container.WriteTransactionPointer(0); FlushDatabaseFile(); }
protected virtual void RebuildIndexForWriter(LocalObjectContainer container, StatefulBuffer buffer, int objectId) { ObjectHeader objectHeader = new ObjectHeader(container, buffer); ObjectIdContextImpl context = new ObjectIdContextImpl(container.SystemTransaction (), buffer, objectHeader, objectId); ClassMetadata classMetadata = context.ClassMetadata(); if (classMetadata.IsStruct()) { // We don't keep version information for structs. return; } if (classMetadata.SeekToField(container.SystemTransaction(), buffer, versionFieldMetadata ) != HandlerVersion.Invalid) { long version = ((long)versionFieldMetadata.Read(context)); if (version != 0) { LocalTransaction t = (LocalTransaction)container.SystemTransaction(); t.CommitTimestampSupport().Put(container.SystemTransaction(), objectId, version); } } }
/// <exception cref="Db4objects.Db4o.Internal.FieldIndexException"></exception> public override void AddFieldIndex(ObjectIdContextImpl context) { LocalTransaction transaction = (LocalTransaction)context.Transaction(); LocalObjectContainer localContainer = (LocalObjectContainer)transaction.Container (); Slot oldSlot = transaction.IdSystem().CommittedSlot(context.ObjectId()); int savedOffset = context.Offset(); int db4oDatabaseIdentityID = context.ReadInt(); long uuid = context.ReadLong(); context.Seek(savedOffset); bool isnew = (oldSlot.IsNull()); if ((uuid == 0 || db4oDatabaseIdentityID == 0) && context.ObjectId() > 0 && !isnew) { UUIDFieldMetadata.DatabaseIdentityIDAndUUID identityAndUUID = ReadDatabaseIdentityIDAndUUID (localContainer, context.ClassMetadata(), oldSlot, false); db4oDatabaseIdentityID = identityAndUUID.databaseIdentityID; uuid = identityAndUUID.uuid; } if (db4oDatabaseIdentityID == 0) { db4oDatabaseIdentityID = localContainer.Identity().GetID(transaction); } if (uuid == 0) { uuid = localContainer.GenerateTimeStampId(); } StatefulBuffer writer = (StatefulBuffer)context.Buffer(); writer.WriteInt(db4oDatabaseIdentityID); writer.WriteLong(uuid); if (isnew) { AddIndexEntry(writer, uuid); } }
public sealed override bool Delete4(Transaction transaction, ObjectReference @ref , object obj, int cascade, bool userCall) { int id = @ref.GetID(); StatefulBuffer reader = ReadStatefulBufferById(transaction, id); if (reader != null) { if (obj != null) { if ((!ShowInternalClasses()) && Const4.ClassInternal.IsAssignableFrom(obj.GetType ())) { return(false); } } reader.SetCascadeDeletes(cascade); transaction.IdSystem().NotifySlotDeleted(id, SlotChangeFactory.UserObjects); ClassMetadata classMetadata = @ref.ClassMetadata(); classMetadata.Delete(reader, obj); return(true); } return(false); }
private object ReadIndexEntryForRebuild(StatefulBuffer writer, ObjectHeader oh) { ClassMetadata classMetadata = oh.ClassMetadata(); if (classMetadata == null) { return(DefaultValueForFieldType()); } ObjectIdContextImpl context = new ObjectIdContextImpl(writer.Transaction(), writer , oh, writer.GetID()); if (!classMetadata.SeekToField(context, this)) { return(DefaultValueForFieldType()); } try { return(ReadIndexEntry(context)); } catch (CorruptionException exc) { throw new FieldIndexException(exc, this); } }
public void AddFieldIndices(StatefulBuffer buffer) { if (!StandardReferenceTypeHandlerIsUsed()) { return; } if (HasClassIndex() || HasVirtualAttributes()) { var oh = new ObjectHeader(this, buffer); var context = new ObjectIdContextImpl(buffer.Transaction(), buffer , oh, buffer.GetID()); Handlers4.FieldAwareTypeHandler(CorrectHandlerVersion(context)).AddFieldIndices(context ); } }
// FIXME: This code has not been called in any test case when the // new ArrayMarshaller was written. // Apparently it only frees slots. // For now the code simply returns without freeing. /// <param name="classPrimitive"></param> public void DeletePrimitiveEmbedded(StatefulBuffer buffer, PrimitiveTypeMetadata classPrimitive) { buffer.ReadInt(); //int address = a_bytes.readInt(); buffer.ReadInt(); }
internal void Delete(StatefulBuffer buffer, object obj) { RemoveFromIndex(buffer.Transaction(), buffer.GetID()); CascadeDeletion(buffer, obj); }
private void CascadeDeletion(StatefulBuffer buffer, object obj) { var oh = new ObjectHeader(this, buffer); var context = new DeleteContextImpl(buffer, oh, ClassReflector(), null ); DeleteMembers(context, ArrayTypeFor(buffer, obj), false); }
/// <exception cref="Db4objects.Db4o.CorruptionException"></exception> /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public override object ReadIndexEntryFromObjectSlot(MarshallerFamily mf, StatefulBuffer buffer) { return buffer.Container().ReadWriterByAddress(buffer.Transaction(), buffer.ReadInt (), buffer.ReadInt()); }
// TODO: freespaceID should not be passed here, it should be taken from SystemData public abstract void WriteFixedPart(LocalObjectContainer file, bool startFileLockingThread , bool shuttingDown, StatefulBuffer writer, int blockSize);
object IIndexableTypeHandler.ReadIndexEntryFromObjectSlot(MarshallerFamily mf, StatefulBuffer buffer) { return ReadFrom(buffer); }
/// <exception cref="Db4objects.Db4o.Internal.FieldIndexException"></exception> public override void AddFieldIndex(ObjectIdContextImpl context) { StatefulBuffer buffer = (StatefulBuffer)context.Buffer(); buffer.WriteLong(context.Transaction().Container().GenerateTimeStampId()); }
public virtual Db4objects.Db4o.CS.Internal.Messages.MsgD GetWriter(StatefulBuffer bytes) { Db4objects.Db4o.CS.Internal.Messages.MsgD message = GetWriterForLength(bytes.Transaction (), bytes.Length()); message._payLoad.Append(bytes._buffer); return message; }
protected void AddIndexEntry(StatefulBuffer a_bytes, object indexEntry) { AddIndexEntry(a_bytes.Transaction(), a_bytes.GetID(), indexEntry); }
public static object Unmarshall(ObjectContainerBase serviceProvider, StatefulBuffer buffer) { return(Unmarshall(serviceProvider, buffer._buffer, buffer.GetID())); }
public override void WriteFixedPart(LocalObjectContainer file, bool startFileLockingThread , bool shuttingDown, StatefulBuffer writer, int blockSize) { throw new InvalidOperationException(); }
public object ReadIndexEntryFromObjectSlot(MarshallerFamily mf, StatefulBuffer buffer) { return ReadFrom(buffer); }
protected virtual void WriteTransactionPointer(Transaction systemTransaction, int transactionPointer, int address, int offset) { StatefulBuffer bytes = new StatefulBuffer(systemTransaction, address, TransactionPointerLength ); bytes.MoveForward(offset); bytes.WriteInt(transactionPointer); bytes.WriteInt(transactionPointer); // Dangerous write. // On corruption transaction pointers will not be the same and nothing will happen. bytes.Write(); }
public virtual void PayLoad(StatefulBuffer writer) { _payLoad = writer; }
/// <exception cref="Db4objects.Db4o.CorruptionException"></exception> public override object Read(MarshallerFamily mf, StatefulBuffer buffer, bool redirect ) { return mf._primitive.ReadDouble(buffer); }
/// <exception cref="Db4objects.Db4o.CorruptionException"></exception> public override object Read(MarshallerFamily mf, StatefulBuffer writer, bool redirect ) { return mf._primitive.ReadInteger(writer); }
private ArrayType ArrayTypeFor(StatefulBuffer buffer, object obj) { return buffer.Transaction().Container()._handlers.ArrayType(obj); }
public static object Unmarshall(ObjectContainerBase serviceProvider, StatefulBuffer buffer) { return Unmarshall(serviceProvider, buffer._buffer, buffer.GetID()); }