Example #1
0
 public _IVisitor4_336(DefragmentServicesImpl _enclosing, CommitTimestampSupport target
                       , LocalTransaction targetTransaction)
 {
     this._enclosing        = _enclosing;
     this.target            = target;
     this.targetTransaction = targetTransaction;
 }
Example #2
0
 public _IVisitor4_284(IPassCommand command, DefragmentServicesImpl context, ClassMetadata
                       curClass)
 {
     this.command  = command;
     this.context  = context;
     this.curClass = curClass;
 }
Example #3
0
		/// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public void ProcessObjectSlot(DefragmentServicesImpl services, ClassMetadata classMetadata
			, int id)
		{
			ByteArrayBuffer sourceBuffer = services.SourceBufferByID(id);
			DefragmentContextImpl.ProcessCopy(services, id, new _ISlotCopyHandler_43(this, services
				), sourceBuffer);
		}
Example #4
0
        /// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private static void Pass(DefragmentServicesImpl context, DefragmentConfig config,
                                 IPassCommand command)
        {
            command.ProcessClassCollection(context);
            IStoredClass[] classes = context.StoredClasses(DefragmentServicesImpl.Sourcedb);
            for (int classIdx = 0; classIdx < classes.Length; classIdx++)
            {
                ClassMetadata classMetadata = (ClassMetadata)classes[classIdx];
                if (!config.StoredClassFilter().Accept(classMetadata))
                {
                    continue;
                }
                ProcessClass(context, classMetadata, command);
                command.Flush(context);
                if (config.ObjectCommitFrequency() > 0)
                {
                    context.TargetCommit();
                }
            }
            BTree uuidIndex = context.SourceUuidIndex();

            if (uuidIndex != null)
            {
                command.ProcessBTree(context, uuidIndex);
            }
            command.Flush(context);
            context.TargetCommit();
        }
Example #5
0
        /// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public void ProcessObjectSlot(DefragmentServicesImpl services, ClassMetadata classMetadata
                                      , int id)
        {
            ByteArrayBuffer sourceBuffer = services.SourceBufferByID(id);

            DefragmentContextImpl.ProcessCopy(services, id, new _ISlotCopyHandler_43(this, services
                                                                                     ), sourceBuffer);
        }
Example #6
0
 internal virtual void CreateIDMapping(DefragmentServicesImpl context, int objectID
     , bool isClassID)
 {
     if (BatchFull())
     {
         Flush(context);
     }
     _ids = TreeInt.Add(_ids, (isClassID ? -objectID : objectID));
 }
Example #7
0
 /// <exception cref="System.IO.IOException"></exception>
 public override void Open()
 {
     _mappingDb = DefragmentServicesImpl.FreshTempFile(_fileName, 1);
     _idTree    = (_treeSpec == null ? new BTree(Trans(), 0, new MappedIDPairHandler()) :
                   new BTree(Trans(), 0, new MappedIDPairHandler(), _treeSpec.NodeSize()));
     _slotTree = (_treeSpec == null ? new BTree(Trans(), 0, new BTreeIdSystem.IdSlotMappingHandler
                                                    ()) : new BTree(Trans(), 0, new BTreeIdSystem.IdSlotMappingHandler(), _treeSpec.
                                                                    NodeSize()));
 }
Example #8
0
 internal virtual void CreateIDMapping(DefragmentServicesImpl context, int objectID
                                       , bool isClassID)
 {
     if (BatchFull())
     {
         Flush(context);
     }
     _ids = TreeInt.Add(_ids, (isClassID ? -objectID : objectID));
 }
Example #9
0
 /// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 public void ProcessClass(DefragmentServicesImpl services, ClassMetadata classMetadata
                          , int id, int classIndexID)
 {
     if (services.MappedID(id, -1) == -1)
     {
         Sharpen.Runtime.Err.WriteLine("MAPPING NOT FOUND: " + id);
     }
     DefragmentContextImpl.ProcessCopy(services, id, new _ISlotCopyHandler_34(classMetadata
                                                                              , classIndexID));
 }
Example #10
0
        private static void DefragUnindexed(DefragmentServicesImpl services)
        {
            IdSource unindexedIDs = services.UnindexedIDs();

            while (unindexedIDs.HasMoreIds())
            {
                int origID = unindexedIDs.NextId();
                DefragmentContextImpl.ProcessCopy(services, origID, new _ISlotCopyHandler_208());
            }
        }
Example #11
0
 // TODO order of class index/object slot processing is crucial:
 // - object slots before field indices (object slots register addresses for
 // use by string indices)
 // - class index before object slots, otherwise phantom btree entries from
 // deletions appear in the source class index?!?
 // reproducable with SelectiveCascadingDeleteTestCase and ObjectSetTestCase
 // - investigate.
 /// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 private static void ProcessClass(DefragmentServicesImpl context, ClassMetadata curClass
                                  , IPassCommand command)
 {
     ProcessClassIndex(context, curClass, command);
     if (!ParentHasIndex(curClass))
     {
         ProcessObjectsForClass(context, curClass, command);
     }
     ProcessClassAndFieldIndices(context, curClass, command);
 }
Example #12
0
		/// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public void ProcessClass(DefragmentServicesImpl services, ClassMetadata classMetadata
			, int id, int classIndexID)
		{
			if (services.MappedID(id, -1) == -1)
			{
				Sharpen.Runtime.Err.WriteLine("MAPPING NOT FOUND: " + id);
			}
			DefragmentContextImpl.ProcessCopy(services, id, new _ISlotCopyHandler_34(classMetadata
				, classIndexID));
		}
Example #13
0
 /// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 private static void ProcessClassIndex(DefragmentServicesImpl context, ClassMetadata
                                       curClass, IPassCommand command)
 {
     if (curClass.HasClassIndex())
     {
         BTreeClassIndexStrategy indexStrategy = (BTreeClassIndexStrategy)curClass.Index();
         BTree btree = indexStrategy.Btree();
         command.ProcessBTree(context, btree);
     }
 }
Example #14
0
        /// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private static void ProcessClassAndFieldIndices(DefragmentServicesImpl context, ClassMetadata
                                                        curClass, IPassCommand command)
        {
            int sourceClassIndexID = 0;
            int targetClassIndexID = 0;

            if (curClass.HasClassIndex())
            {
                sourceClassIndexID = curClass.Index().Id();
                targetClassIndexID = context.MappedID(sourceClassIndexID, -1);
            }
            command.ProcessClass(context, curClass, curClass.GetID(), targetClassIndexID);
        }
Example #15
0
        /// <summary>
        /// Renames the file at the configured original path to the configured backup
        /// path and then builds a defragmented version of the file in the original
        /// place.
        /// </summary>
        /// <remarks>
        /// Renames the file at the configured original path to the configured backup
        /// path and then builds a defragmented version of the file in the original
        /// place.
        /// </remarks>
        /// <param name="config">The configuration for this defragmentation run.</param>
        /// <param name="listener">
        /// A listener for status notifications during the defragmentation
        /// process.
        /// </param>
        /// <exception cref="System.IO.IOException">if the original file cannot be moved to the backup location
        ///     </exception>
        public static void Defrag(DefragmentConfig config, IDefragmentListener listener)
        {
            IStorage storage = config.Db4oConfig().Storage;

            EnsureFileExists(storage, config.OrigPath());
            IStorage backupStorage = config.BackupStorage();

            if (backupStorage.Exists(config.BackupPath()))
            {
                if (!config.ForceBackupDelete())
                {
                    throw new IOException("Could not use '" + config.BackupPath() + "' as backup path - file exists."
                                          );
                }
            }
            // Always delete, because !exists can indicate length == 0
            backupStorage.Delete(config.BackupPath());
            MoveToBackup(config);
            if (config.FileNeedsUpgrade())
            {
                UpgradeFile(config);
            }
            DefragmentServicesImpl services = new DefragmentServicesImpl(config, listener);

            try
            {
                FirstPass(services, config);
                services.CommitIds();
                SecondPass(services, config);
                services.CommitIds();
                DefragUnindexed(services);
                services.CommitIds();
                services.DefragIdToTimestampBtree();
                services.ReplaceClassMetadataRepository();
            }
            catch (CorruptionException exc)
            {
                Sharpen.Runtime.PrintStackTrace(exc);
            }
            finally
            {
                services.Close();
            }
        }
Example #16
0
 public virtual void Flush(DefragmentServicesImpl context)
 {
     if (_ids == null)
     {
         return;
     }
     IEnumerator idIter = new TreeKeyIterator(_ids);
     while (idIter.MoveNext())
     {
         var objectID = ((int) idIter.Current);
         var isClassID = false;
         if (objectID < 0)
         {
             objectID = -objectID;
             isClassID = true;
         }
         // seen object ids don't come by here anymore - any other candidates?
         context.MapIDs(objectID, context.TargetNewId(), isClassID);
     }
     context.Mapping().Commit();
     _ids = null;
 }
Example #17
0
        public virtual void Flush(DefragmentServicesImpl context)
        {
            if (_ids == null)
            {
                return;
            }
            IEnumerator idIter = new TreeKeyIterator(_ids);

            while (idIter.MoveNext())
            {
                int  objectID  = ((int)idIter.Current);
                bool isClassID = false;
                if (objectID < 0)
                {
                    objectID  = -objectID;
                    isClassID = true;
                }
                // seen object ids don't come by here anymore - any other candidates?
                context.MapIDs(objectID, context.TargetNewId(), isClassID);
            }
            context.Mapping().Commit();
            _ids = null;
        }
Example #18
0
 public _ISlotCopyHandler_59(DefragmentServicesImpl services)
 {
     this.services = services;
 }
			public _IVisitor4_284(IPassCommand command, DefragmentServicesImpl context, ClassMetadata
				 curClass)
			{
				this.command = command;
				this.context = context;
				this.curClass = curClass;
			}
Example #20
0
			public _IVisitor4_336(DefragmentServicesImpl _enclosing, CommitTimestampSupport target
				, LocalTransaction targetTransaction)
			{
				this._enclosing = _enclosing;
				this.target = target;
				this.targetTransaction = targetTransaction;
			}
Example #21
0
			public _ISlotCopyHandler_43(SecondPassCommand _enclosing, DefragmentServicesImpl 
				services)
			{
				this._enclosing = _enclosing;
				this.services = services;
			}
		public void ProcessObjectSlot(DefragmentServicesImpl context, ClassMetadata classMetadata
			, int sourceID)
		{
			_collector.CreateIDMapping(context, sourceID, false);
		}
		public void ProcessClass(DefragmentServicesImpl context, ClassMetadata classMetadata
			, int id, int classIndexID)
		{
			_collector.CreateIDMapping(context, id, true);
			classMetadata.TraverseAllAspects(new _TraverseFieldCommand_24(this, context));
		}
Example #24
0
		public void Flush(DefragmentServicesImpl context)
		{
		}
Example #25
0
 internal abstract LocalObjectContainer Db(DefragmentServicesImpl context);
Example #26
0
 public void Flush(DefragmentServicesImpl context)
 {
     _collector.Flush(context);
 }
Example #27
0
 public void ProcessBTree(DefragmentServicesImpl context, BTree btree)
 {
     context.RegisterBTreeIDs(btree, _collector);
 }
Example #28
0
 /// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
 public void ProcessClassCollection(DefragmentServicesImpl context)
 {
     _collector.CreateIDMapping(context, context.SourceClassCollectionID(), false);
 }
Example #29
0
 public void ProcessObjectSlot(DefragmentServicesImpl context, ClassMetadata classMetadata
                               , int sourceID)
 {
     _collector.CreateIDMapping(context, sourceID, false);
 }
Example #30
0
 public _TraverseFieldCommand_24(FirstPassCommand _enclosing, DefragmentServicesImpl
                                 context)
 {
     this._enclosing = _enclosing;
     this.context    = context;
 }
Example #31
0
 public void ProcessClass(DefragmentServicesImpl context, ClassMetadata classMetadata
                          , int id, int classIndexID)
 {
     _collector.CreateIDMapping(context, id, true);
     classMetadata.TraverseAllAspects(new _TraverseFieldCommand_24(this, context));
 }
Example #32
0
 public void Flush(DefragmentServicesImpl context)
 {
 }
		public void ProcessBTree(DefragmentServicesImpl context, BTree btree)
		{
			context.RegisterBTreeIDs(btree, _collector);
		}
Example #34
0
		public virtual ByteArrayBuffer BufferByID(DefragmentServicesImpl.DbSelector selector
			, int id)
		{
			Slot slot = CommittedSlot(selector, id);
			return BufferByAddress(selector, slot.Address(), slot.Length());
		}
Example #35
0
		/// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public void ProcessBTree(DefragmentServicesImpl context, BTree btree)
		{
			btree.DefragBTree(context);
		}
Example #36
0
		public virtual ByteArrayBuffer BufferByAddress(DefragmentServicesImpl.DbSelector 
			selector, int address, int length)
		{
			return selector.Db(this).DecryptedBufferByAddress(address, length);
		}
			public _TraverseFieldCommand_24(FirstPassCommand _enclosing, DefragmentServicesImpl
				 context)
			{
				this._enclosing = _enclosing;
				this.context = context;
			}
Example #38
0
			public _ISlotCopyHandler_59(DefragmentServicesImpl services)
			{
				this.services = services;
			}
		/// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
		public void ProcessClassCollection(DefragmentServicesImpl context)
		{
			_collector.CreateIDMapping(context, context.SourceClassCollectionID(), false);
		}
Example #40
0
 internal virtual Db4objects.Db4o.Internal.Transaction Transaction(DefragmentServicesImpl
                                                                   context)
 {
     return(Db(context).SystemTransaction());
 }
		public void Flush(DefragmentServicesImpl context)
		{
			_collector.Flush(context);
		}
Example #42
0
			public _IVisitor4_244(DefragmentServicesImpl _enclosing, IDMappingCollector collector
				)
			{
				this._enclosing = _enclosing;
				this.collector = collector;
			}
Example #43
0
		private Slot CommittedSlot(DefragmentServicesImpl.DbSelector selector, int id)
		{
			return selector.Db(this).IdSystem().CommittedSlot(id);
		}
Example #44
0
			internal abstract LocalObjectContainer Db(DefragmentServicesImpl context);
Example #45
0
		public virtual IStoredClass[] StoredClasses(DefragmentServicesImpl.DbSelector selector
			)
		{
			LocalObjectContainer db = selector.Db(this);
			db.ShowInternalClasses(true);
			try
			{
				return db.ClassCollection().StoredClasses();
			}
			finally
			{
				db.ShowInternalClasses(false);
			}
		}
Example #46
0
		/// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public void ProcessClassCollection(DefragmentServicesImpl services)
		{
			DefragmentContextImpl.ProcessCopy(services, services.SourceClassCollectionID(), new 
				_ISlotCopyHandler_59(services));
		}
Example #47
0
		public virtual int DatabaseIdentityID(DefragmentServicesImpl.DbSelector selector)
		{
			LocalObjectContainer db = selector.Db(this);
			Db4oDatabase identity = db.Identity();
			if (identity == null)
			{
				return 0;
			}
			return identity.GetID(selector.Transaction(this));
		}
Example #48
0
 /// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 private static void FirstPass(DefragmentServicesImpl context, DefragmentConfig config
                               )
 {
     // System.out.println("FIRST");
     Pass(context, config, new FirstPassCommand());
 }
Example #49
0
			internal virtual Db4objects.Db4o.Internal.Transaction Transaction(DefragmentServicesImpl
				 context)
			{
				return Db(context).SystemTransaction();
			}
		/// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private static void ProcessClassIndex(DefragmentServicesImpl context, ClassMetadata
			 curClass, IPassCommand command)
		{
			if (curClass.HasClassIndex())
			{
				BTreeClassIndexStrategy indexStrategy = (BTreeClassIndexStrategy)curClass.Index();
				BTree btree = indexStrategy.Btree();
				command.ProcessBTree(context, btree);
			}
		}
Example #51
0
			internal override LocalObjectContainer Db(DefragmentServicesImpl context)
			{
				return context._targetDb;
			}
		private static void ProcessObjectsForClass(DefragmentServicesImpl context, ClassMetadata
			 curClass, IPassCommand command)
		{
			context.TraverseAll(curClass, new _IVisitor4_284(command, context, curClass));
		}
Example #53
0
 /// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 public void ProcessClassCollection(DefragmentServicesImpl services)
 {
     DefragmentContextImpl.ProcessCopy(services, services.SourceClassCollectionID(), new
                                       _ISlotCopyHandler_59(services));
 }
Example #54
0
 private static void ProcessObjectsForClass(DefragmentServicesImpl context, ClassMetadata
                                            curClass, IPassCommand command)
 {
     context.TraverseAll(curClass, new _IVisitor4_284(command, context, curClass));
 }
Example #55
0
 /// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 public void ProcessBTree(DefragmentServicesImpl context, BTree btree)
 {
     btree.DefragBTree(context);
 }
		/// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private static void ProcessClassAndFieldIndices(DefragmentServicesImpl context, ClassMetadata
			 curClass, IPassCommand command)
		{
			int sourceClassIndexID = 0;
			int targetClassIndexID = 0;
			if (curClass.HasClassIndex())
			{
				sourceClassIndexID = curClass.Index().Id();
				targetClassIndexID = context.MappedID(sourceClassIndexID, -1);
			}
			command.ProcessClass(context, curClass, curClass.GetID(), targetClassIndexID);
		}
Example #57
0
 /// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 private static void SecondPass(DefragmentServicesImpl context, DefragmentConfig config
                                )
 {
     // System.out.println("SECOND");
     Pass(context, config, new SecondPassCommand(config.ObjectCommitFrequency()));
 }
Example #58
0
 internal override LocalObjectContainer Db(DefragmentServicesImpl context)
 {
     return(context._targetDb);
 }
Example #59
0
 public _ISlotCopyHandler_43(SecondPassCommand _enclosing, DefragmentServicesImpl
                             services)
 {
     this._enclosing = _enclosing;
     this.services   = services;
 }
		// TODO order of class index/object slot processing is crucial:
		// - object slots before field indices (object slots register addresses for
		// use by string indices)
		// - class index before object slots, otherwise phantom btree entries from
		// deletions appear in the source class index?!?
		// reproducable with SelectiveCascadingDeleteTestCase and ObjectSetTestCase
		// - investigate.
		/// <exception cref="Db4objects.Db4o.CorruptionException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private static void ProcessClass(DefragmentServicesImpl context, ClassMetadata curClass
			, IPassCommand command)
		{
			ProcessClassIndex(context, curClass, command);
			if (!ParentHasIndex(curClass))
			{
				ProcessObjectsForClass(context, curClass, command);
			}
			ProcessClassAndFieldIndices(context, curClass, command);
		}