private ObjectServerImpl(LocalObjectContainer container, ServerConfigurationImpl serverConfig, int port, bool isEmbeddedServer) { _isEmbeddedServer = isEmbeddedServer; _container = container; _serverConfig = serverConfig; _socketFactory = serverConfig.Networking.SocketFactory; _transactionPool = new ClientTransactionPool(container); _port = port; _name = "db4o ServerSocket FILE: " + container.ToString() + " PORT:" + _port; _container.SetServer(true); ConfigureObjectServer(); _classInfoHelper = new Db4objects.Db4o.CS.Internal.ClassInfoHelper(Db4oClientServerLegacyConfigurationBridge .AsLegacy(serverConfig)); _container.ClassCollection().CheckAllClassChanges(); bool ok = false; try { EnsureLoadStaticClass(); StartCommittedCallbackThread(_committedInfosQueue); StartServer(); if (_serverConfig != null) { _serverConfig.ApplyConfigurationItems(this); } ok = true; } finally { if (!ok) { Close(); } } }
public static Db4objects.Db4o.Internal.Freespace.AbstractFreespaceManager CreateNew (LocalObjectContainer file, byte systemType) { systemType = CheckType(systemType); int unblockedDiscardLimit = file.ConfigImpl.DiscardFreeSpace(); int blockedDiscardLimit = unblockedDiscardLimit == int.MaxValue ? unblockedDiscardLimit : file.BlockConverter().BytesToBlocks(unblockedDiscardLimit); int remainderSizeLimit = file.BlockConverter().BytesToBlocks(RemainderSizeLimit); IProcedure4 slotFreedCallback = new _IProcedure4_52(file); switch (systemType) { case FmIx: { return new FreespaceManagerIx(blockedDiscardLimit, remainderSizeLimit); } case FmBtree: { return new BTreeFreespaceManager(file, slotFreedCallback, blockedDiscardLimit, remainderSizeLimit ); } default: { return new InMemoryFreespaceManager(slotFreedCallback, blockedDiscardLimit, remainderSizeLimit ); break; } } }
private void Open() { IConfiguration config = ((IConfiguration)_currentConfig.Run()); Db4oLegacyConfigurationBridge.AsIdSystemConfiguration(config).UsePointerBasedSystem (); _container = (LocalObjectContainer)Db4oFactory.OpenFile(config, TempFile()); }
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 virtual void AssertSingleEntry(LocalObjectContainer container, long id) { var called = new BooleanByRef(); Index(container).TraverseKeys(container.SystemTransaction(), new _IVisitor4_24(id , called)); Assert.IsTrue(called.value); }
public BTreeFreespaceManager(LocalObjectContainer file, IProcedure4 slotFreedCallback , int discardLimit) : base(slotFreedCallback, discardLimit) { _file = file; _delegate = new InMemoryFreespaceManager(slotFreedCallback, discardLimit); _idSystem = file.SystemData().FreespaceIdSystem(); }
/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public sealed override void InitNew(LocalObjectContainer file) { NewTimerFileLock(file); OldEncryptionOff(file); _variablePart = CreateVariablePart(file); WriteVariablePart(file); }
public virtual long CollectFor(LocalObjectContainer db, int id, ISlotMap slotMap) { var bigSet = db.GetByID(id); db.Activate(bigSet, 1); var btree = (BTree) Reflection4.GetFieldValue(bigSet, "_bTree"); return FileUsageStatsCollector.BTreeUsage(db, btree, slotMap); }
/// <exception cref="System.IO.IOException"></exception> public DefragmentServicesImpl(DefragmentConfig defragConfig, IDefragmentListener listener) { _listener = listener; var originalConfig = (Config4Impl) defragConfig.Db4oConfig(); var storage = defragConfig.BackupStorage(); if (defragConfig.ReadOnly()) { storage = new NonFlushingStorage(storage); } var sourceConfig = PrepareConfig(originalConfig, storage, defragConfig.ReadOnly ()); _sourceDb = (LocalObjectContainer) Db4oFactory.OpenFile(sourceConfig, defragConfig .TempPath()).Ext(); _sourceDb.ShowInternalClasses(true); defragConfig.Db4oConfig().BlockSize(_sourceDb.BlockSize()); if (!originalConfig.GenerateCommitTimestamps().DefiniteNo()) { defragConfig.Db4oConfig().GenerateCommitTimestamps(_sourceDb.Config().GenerateCommitTimestamps ().DefiniteYes()); } _targetDb = FreshTargetFile(defragConfig); _mapping = defragConfig.Mapping(); _mapping.Open(); _defragConfig = defragConfig; }
public LocalTransaction(ObjectContainerBase container, Transaction parentTransaction , ITransactionalIdSystem idSystem, IReferenceSystem referenceSystem) : base(container , parentTransaction, referenceSystem) { _file = (LocalObjectContainer) container; _committedCallbackDispatcher = new _ICommittedCallbackDispatcher_39(this); _idSystem = idSystem; }
private void Store(LocalObjectContainer origDb) { for (int itemId = 0; itemId < NumItems; itemId++) { origDb.Store(new MemoryBackupTestCaseBase.Item(itemId)); } origDb.Commit(); }
protected override FileHeader NewOnSignatureMatch(LocalObjectContainer file, ByteArrayBuffer reader) { if (SignatureMatches(reader, Signature, Version())) { return CreateNew(); } return null; }
public static IIdSystem NewInstance(LocalObjectContainer localContainer) { SystemData systemData = localContainer.SystemData(); byte idSystemType = systemData.IdSystemType(); switch (idSystemType) { case Legacy: { return new PointerBasedIdSystem(localContainer); } case PointerBased: { return new PointerBasedIdSystem(localContainer); } case StackedBtree: { InMemoryIdSystem inMemoryIdSystem = new InMemoryIdSystem(localContainer); BTreeIdSystem bTreeIdSystem = new BTreeIdSystem(localContainer, inMemoryIdSystem); systemData.FreespaceIdSystem(bTreeIdSystem.FreespaceIdSystem()); return new BTreeIdSystem(localContainer, bTreeIdSystem); } case SingleBtree: { InMemoryIdSystem smallInMemoryIdSystem = new InMemoryIdSystem(localContainer); BTreeIdSystem smallBTreeIdSystem = new BTreeIdSystem(localContainer, smallInMemoryIdSystem ); systemData.FreespaceIdSystem(smallBTreeIdSystem.FreespaceIdSystem()); return smallBTreeIdSystem; } case InMemory: { return new InMemoryIdSystem(localContainer); } case Custom: { IIdSystemFactory customIdSystemFactory = localContainer.ConfigImpl.CustomIdSystemFactory (); if (customIdSystemFactory == null) { throw new Db4oFatalException("Custom IdSystem configured but no factory was found. See IdSystemConfiguration#useCustomSystem()" ); } return customIdSystemFactory.NewInstance(localContainer); } default: { return new PointerBasedIdSystem(localContainer); break; } } }
public virtual bool RebuildIndexForClass(LocalObjectContainer container, ClassMetadata classMetadata) { long[] ids = classMetadata.GetIDs(); for (int i = 0; i < ids.Length; i++) { RebuildIndexForObject(container, (int)ids[i]); } return ids.Length > 0; }
/// <exception cref="Db4objects.Db4o.Internal.FieldIndexException"></exception> protected virtual void RebuildIndexForObject(LocalObjectContainer container, int objectId) { StatefulBuffer writer = container.ReadStatefulBufferById(container.SystemTransaction (), objectId); if (writer != null) { RebuildIndexForWriter(container, writer, objectId); } }
public ClientTransactionPool(LocalObjectContainer mainContainer) { // Transaction -> ContainerCount // String -> ContainerCount ClientTransactionPool.ContainerCount mainEntry = new ClientTransactionPool.ContainerCount (mainContainer, 1); _transaction2Container = new Hashtable4(); _fileName2Container = new Hashtable4(); _fileName2Container.Put(mainContainer.FileName(), mainEntry); _mainContainer = mainContainer; }
public FileUsageStatsCollector(IObjectContainer db, bool collectSlots) { MiscCollectors = new Hashtable(); RegisterBigSetCollector(); _db = (LocalObjectContainer)db; byte blockSize = _db.BlockSize(); _blockConverter = blockSize > 1 ? (IBlockConverter)new BlockSizeBlockConverter(blockSize ) : (IBlockConverter)new DisabledBlockConverter(); _slots = collectSlots ? (ISlotMap)new SlotMapImpl(_db.FileLength()) : (ISlotMap)new NullSlotMap(); }
public FileHeaderVariablePart1(LocalObjectContainer container, int id) : base(container ) { // The variable part format is: // (int) converter version // (byte) freespace system used // (int) freespace address // (int) identity ID // (long) versionGenerator // (int) uuid index ID _id = id; }
public sealed override void WriteVariablePart(LocalObjectContainer file, bool shuttingDown ) { if (!IsInitalized()) { return; } IRunnable commitHook = Commit(shuttingDown); file.SyncFiles(); commitHook.Run(); file.SyncFiles(); }
private void RebuildUUIDIndex(LocalObjectContainer file) { UUIDFieldMetadata uuid = file.UUIDIndex(); ClassMetadataIterator i = file.ClassCollection().Iterator(); while (i.MoveNext()) { ClassMetadata clazz = i.CurrentClass(); if (clazz.GenerateUUIDs()) { uuid.RebuildIndexForClass(file, clazz); } } }
private void BuildCommitTimestampIndex(LocalObjectContainer container) { versionFieldMetadata = container.Handlers.Indexes()._version; ClassMetadataIterator i = container.ClassCollection().Iterator(); while (i.MoveNext()) { ClassMetadata clazz = i.CurrentClass(); if (clazz.HasVersionField() && !clazz.IsStruct()) { RebuildIndexForClass(container, clazz); } } }
public virtual Tree Free(LocalObjectContainer file, Tree treeRoot, Db4objects.Db4o.Internal.Slots.Slot slot) { file.Free(_slot.Address(), _slot.Length()); if (RemoveReferenceIsLast()) { if (treeRoot != null) { return treeRoot.RemoveNode(this); } } PointTo(slot); return treeRoot; }
private static FileHeader DetectFileHeader(LocalObjectContainer file, ByteArrayBuffer reader) { for (int i = 0; i < AvailableFileHeaders.Length; i++) { reader.Seek(0); FileHeader result = AvailableFileHeaders[i].NewOnSignatureMatch(file, reader); if (result != null) { return result; } } return null; }
public static IDictionary TypesFor(LocalObjectContainer db, Sharpen.Util.ISet ids ) { IDictionary id2clazzes = new Hashtable(); ClassMetadataIterator iter = db.ClassCollection().Iterator(); while (iter.MoveNext()) { for (IEnumerator idIter = ids.GetEnumerator(); idIter.MoveNext(); ) { int id = ((int)idIter.Current); ClassMetadata clazz = iter.CurrentClass(); BTree btree = BTreeClassIndexStrategy.Btree(clazz); if (btree.Search(db.SystemTransaction(), id) != null) { Sharpen.Util.ISet clazzes = ((Sharpen.Util.ISet)id2clazzes[id]); if (clazzes == null) { clazzes = new HashSet(); id2clazzes[id] = clazzes; } clazzes.Add(clazz); } } } IDictionary id2clazz = new Hashtable(); for (IEnumerator idIter = id2clazzes.Keys.GetEnumerator(); idIter.MoveNext(); ) { int id = ((int)idIter.Current); Sharpen.Util.ISet clazzes = ((Sharpen.Util.ISet)id2clazzes[id]); ClassMetadata mostSpecific = null; for (IEnumerator curClazzIter = clazzes.GetEnumerator(); curClazzIter.MoveNext(); ) { ClassMetadata curClazz = ((ClassMetadata)curClazzIter.Current); for (IEnumerator cmpClazzIter = clazzes.GetEnumerator(); cmpClazzIter.MoveNext(); ) { ClassMetadata cmpClazz = ((ClassMetadata)cmpClazzIter.Current); if (curClazz.Equals(cmpClazz._ancestor)) { goto OUTER_continue; } } mostSpecific = curClazz; break; OUTER_continue: ; } OUTER_break: ; id2clazz[id] = mostSpecific; } return id2clazz; }
/// <exception cref="Db4objects.Db4o.Ext.OldFormatException"></exception> public static FileHeader Read(LocalObjectContainer file) { ByteArrayBuffer reader = PrepareFileHeaderReader(file); FileHeader header = DetectFileHeader(file, reader); if (header == null) { Exceptions4.ThrowRuntimeException(Db4objects.Db4o.Internal.Messages.IncompatibleFormat , file.ToString()); } else { header.Read(file, reader); } return header; }
public virtual void Convert(LocalObjectContainer container, int classIndexId, BTree bTree) { Transaction trans = container.SystemTransaction(); ByteArrayBuffer reader = container.ReadBufferById(trans, classIndexId); if (reader == null) { return; } int entries = reader.ReadInt(); for (int i = 0; i < entries; i++) { bTree.Add(trans, reader.ReadInt()); } }
public FileHeaderVariablePart2(LocalObjectContainer container, int address, int length ) : base(container) { // The variable part format is: // (long) checksum // (int) address of InMemoryIdSystem slot // (int) length of InMemoryIdSystem slot // (int) address of InMemoryFreespace // (int) length of InMemoryFreespace // (int) BTreeFreespace id // (int) converter version // (int) uuid index ID // (int) identity ID // (long) versionGenerator // (byte) freespace system used _address = address; _length = length; }
protected override void Read(LocalObjectContainer file, ByteArrayBuffer reader) { NewTimerFileLock(file); OldEncryptionOff(file); CheckThreadFileLock(file, reader); reader.Seek(TransactionPointerOffset); file.SystemData().TransactionPointer1(reader.ReadInt()); file.SystemData().TransactionPointer2(reader.ReadInt()); reader.Seek(BlocksizeOffset); file.BlockSizeReadFromFile(reader.ReadInt()); SystemData systemData = file.SystemData(); systemData.ClassCollectionID(reader.ReadInt()); reader.ReadInt(); // was freespace ID, can no longer be read _variablePart = CreateVariablePart(file); int variablePartId = reader.ReadInt(); _variablePart.Read(variablePartId, 0); }
public BTreeIdSystem(LocalObjectContainer container, IStackableIdSystem parentIdSystem , int maxValidId) { _container = container; _parentIdSystem = parentIdSystem; _transactionalIdSystem = container.NewTransactionalIdSystem(null, new _IClosure4_40 (parentIdSystem)); int persistentArrayId = parentIdSystem.ChildId(); if (persistentArrayId == 0) { InitializeNew(); } else { InitializeExisting(persistentArrayId); } _idGenerator = new SequentialIdGenerator(new _IFunction4_52(this), IdGeneratorValue (), _container.Handlers.LowestValidId(), maxValidId); }
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); } } }
public SystemInfoFileImpl(LocalObjectContainer file) { _file = file; }
public CommitTimestampSupport(LocalObjectContainer container) { _container = container; }
public void Write(LocalObjectContainer file, int address) { file.WriteBytes(_target, address, 0); }
public _IClosure4_58(LocalObjectContainer _enclosing) { this._enclosing = _enclosing; }