示例#1
0
        �������� /// <summary>
        �������� /// Coordinates the processing necessary to get things ready for executions
        �������� /// as db calls by preparing the session caches and moving the appropriate
        �������� /// entities and collections to their respective execution queues.
        �������� /// </summary>
        �������� /// <param name="event">The flush event.</param>
        ��������protected virtual void FlushEverythingToExecutions(FlushEvent @event)
        ��������
        {
            ������������log.Debug("flushing session");
            �
            ������������IEventSource        session            = @event.Session;
            ������������IPersistenceContext persistenceContext = session.PersistenceContext;
            �
            ������������session.Interceptor.PreFlush((ICollection)persistenceContext.EntitiesByKey.Values);

            �
            ������������PrepareEntityFlushes(session);
            ������������ // we could move this inside if we wanted to
            ������������ // tolerate collection initializations during
            ������������ // collection dirty checking:
            ������������PrepareCollectionFlushes(session);

            ������������ // now, any collections that are initialized
            ������������ // inside this block do not get updated - they
            ������������ // are ignored until the next flush
            �
            ������������persistenceContext.Flushing = true;

            ������������try
            ������������ {
                ����������������FlushEntities(@event);
                ����������������FlushCollections(session);
                ������������
            }
            ������������finally
            ������������ {
                ����������������persistenceContext.Flushing = false;
                ������������
            }
            �
            ������������//some statistics
            ������������if(log.IsDebugEnabled)
            ������������
            {
                ����������������StringBuilder sb = new StringBuilder(100);
                �
                ����������������sb.Append("Flushed: ").Append(session.ActionQueue.InsertionsCount).Append(" insertions, ").Append(
                    ��������������������session.ActionQueue.UpdatesCount).Append(" updates, ").Append(session.ActionQueue.DeletionsCount).Append(
                    �������������������� " deletions to ").Append(persistenceContext.EntityEntries.Count).Append(" objects");

                ����������������log.Debug(sb.ToString());
                ����������������sb = new StringBuilder(100);
                ����������������sb.Append("Flushed: ").Append(session.ActionQueue.CollectionCreationsCount).Append(" (re)creations, ").Append(
                    ��������������������session.ActionQueue.CollectionUpdatesCount).Append(" updates, ").Append(session.ActionQueue.CollectionRemovalsCount)
                ��������������������.Append(" removals to ").Append(persistenceContext.CollectionEntries.Count).Append(" collections");
                �
                ����������������log.Debug(sb.ToString());

                ����������������new Printer(session.Factory).ToString(persistenceContext.EntitiesByKey.Values.GetEnumerator(), session.EntityMode);

                ������������
            }

            ��������
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void countFlushesAndBytesWritten()
        internal virtual void CountFlushesAndBytesWritten()
        {
            PinEvent pinEvent = _pageCursorTracer.beginPin(true, 0, _swapper);

            {
                PageFaultEvent faultEvent = pinEvent.BeginPageFault();
                {
                    EvictionEvent evictionEvent = faultEvent.BeginEviction();
                    {
                        FlushEventOpportunity flushEventOpportunity = evictionEvent.FlushEventOpportunity();
                        {
                            FlushEvent flushEvent = flushEventOpportunity.BeginFlush(0, 0, _swapper);
                            flushEvent.AddBytesWritten(27);
                            flushEvent.Done();
                            FlushEvent flushEvent1 = flushEventOpportunity.BeginFlush(0, 1, _swapper);
                            flushEvent1.AddBytesWritten(13);
                            flushEvent1.Done();
                        }
                    }
                    evictionEvent.Close();
                }
                faultEvent.Done();
            }
            pinEvent.Done();

            assertEquals(1, _pageCursorTracer.pins());
            assertEquals(1, _pageCursorTracer.unpins());
            assertEquals(1, _pageCursorTracer.faults());
            assertEquals(1, _pageCursorTracer.evictions());
            assertEquals(2, _pageCursorTracer.flushes());
            assertEquals(40, _pageCursorTracer.bytesWritten());
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustCountEvictions()
        internal virtual void MustCountEvictions()
        {
            using (EvictionRunEvent evictionRunEvent = _tracer.beginPageEvictions(2))
            {
                using (EvictionEvent evictionEvent = evictionRunEvent.BeginEviction())
                {
                    FlushEvent flushEvent = evictionEvent.FlushEventOpportunity().beginFlush(0, 0, _swapper);
                    flushEvent.AddBytesWritten(12);
                    flushEvent.Done();
                }

                using (EvictionEvent evictionEvent = evictionRunEvent.BeginEviction())
                {
                    FlushEvent flushEvent = evictionEvent.FlushEventOpportunity().beginFlush(0, 0, _swapper);
                    flushEvent.AddBytesWritten(12);
                    flushEvent.Done();
                    evictionEvent.ThrewException(new IOException());
                }

                using (EvictionEvent evictionEvent = evictionRunEvent.BeginEviction())
                {
                    FlushEvent flushEvent = evictionEvent.FlushEventOpportunity().beginFlush(0, 0, _swapper);
                    flushEvent.AddBytesWritten(12);
                    flushEvent.Done();
                    evictionEvent.ThrewException(new IOException());
                }

                evictionRunEvent.BeginEviction().close();
            }

            AssertCounts(0, 0, 0, 0, 4, 2, 3, 0, 36, 0, 0, 0d);
        }
示例#4
0
        // 1. detect any dirty entities
        // 2. schedule any entity updates
        // 3. search out any reachable collections
        private void FlushEntities(FlushEvent @event)
        {
            log.Debug("Flushing entities and processing referenced collections");

            // Among other things, updateReachables() will recursively load all
            // collections that are moving roles. This might cause entities to
            // be loaded.

            // So this needs to be safe from concurrent modification problems.
            // It is safe because of how IdentityMap implements entrySet()
            IEventSource source = @event.Session;

            ICollection list = IdentityMap.ConcurrentEntries(source.PersistenceContext.EntityEntries);

            foreach (DictionaryEntry me in list)
            {
                // Update the status of the object and if necessary, schedule an update
                EntityEntry entry  = (EntityEntry)me.Value;
                Status      status = entry.Status;

                if (status != Status.Loading && status != Status.Gone)
                {
                    FlushEntityEvent            entityEvent = new FlushEntityEvent(source, me.Key, entry);
                    IFlushEntityEventListener[] listeners   = source.Listeners.FlushEntityEventListeners;
                    foreach (IFlushEntityEventListener listener in listeners)
                    {
                        listener.OnFlushEntity(entityEvent);
                    }
                }
            }
            source.ActionQueue.SortActions();
        }
示例#5
0
 public override void OnFlush(FlushEvent @event)
 {
     try {
         base.OnFlush(@event);
     }
     catch (AssertionFailure) {
         // throw away
     }
 }
示例#6
0
 /// <summary>
 /// Handle the given flush event.
 /// </summary>
 /// <param name="event">The flush event to be handled.</param>
 public void OnFlush(FlushEvent @event)
 {
     try
     {
         _defaultFlushListener.OnFlush(@event);
     }
     catch (Exception ex)
     {
         throw new InvalidOperationException("Error trying to flush", ex);
     }
 }
示例#7
0
 /// <summary>
 /// Called when [flush].
 /// </summary>
 /// <param name="event">The @event.</param>
 public override void OnFlush(FlushEvent @event)
 {
     try
     {
         base.OnFlush(@event);
     }
     catch (AssertionFailure e)
     {
         // throw away
         Logger.WarnException("AssertionFailure occurred in " + GetType().Name, e);
     }
 }
		/// <summary> 
		/// Coordinates the processing necessary to get things ready for executions
		/// as db calls by preping the session caches and moving the appropriate
		/// entities and collections to their respective execution queues. 
		/// </summary>
		/// <param name="event">The flush event.</param>
		protected virtual void FlushEverythingToExecutions(FlushEvent @event)
		{
			log.Debug("flushing session");

			IEventSource session = @event.Session;
			IPersistenceContext persistenceContext = session.PersistenceContext;

			session.Interceptor.PreFlush((ICollection)persistenceContext.EntitiesByKey.Values);

			PrepareEntityFlushes(session);
			// we could move this inside if we wanted to
			// tolerate collection initializations during
			// collection dirty checking:
			PrepareCollectionFlushes(session);
			// now, any collections that are initialized
			// inside this block do not get updated - they
			// are ignored until the next flush

			persistenceContext.Flushing = true;
			try
			{
				FlushEntities(@event);
				FlushCollections(session);
			}
			finally
			{
				persistenceContext.Flushing = false;
			}

			//some statistics
			if (log.IsDebugEnabled)
			{
				StringBuilder sb = new StringBuilder(100);

				sb.Append("Flushed: ")
					.Append(session.ActionQueue.InsertionsCount).Append(" insertions, ")
					.Append(session.ActionQueue.UpdatesCount).Append(" updates, ")
					.Append(session.ActionQueue.DeletionsCount).Append(" deletions to ")
					.Append(persistenceContext.EntityEntries.Count).Append(" objects");
				log.Debug(sb.ToString());
				sb = new StringBuilder(100);
				sb.Append("Flushed: ")
					.Append(session.ActionQueue.CollectionCreationsCount).Append(" (re)creations, ")
					.Append(session.ActionQueue.CollectionUpdatesCount).Append(" updates, ")
					.Append(session.ActionQueue.CollectionRemovalsCount).Append(" removals to ")
					.Append(persistenceContext.CollectionEntries.Count).Append(" collections");

				log.Debug(sb.ToString());
				new Printer(session.Factory).ToString(persistenceContext.EntitiesByKey.Values.GetEnumerator(), session.EntityMode);
			}
		}
示例#9
0
        /// <summary>
        /// Coordinates the processing necessary to get things ready for executions
        /// as db calls by preparing the session caches and moving the appropriate
        /// entities and collections to their respective execution queues.
        /// </summary>
        /// <param name="event">The flush event.</param>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
        protected virtual async Task FlushEverythingToExecutionsAsync(FlushEvent @event, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            log.Debug("flushing session");

            IEventSource        session            = @event.Session;
            IPersistenceContext persistenceContext = session.PersistenceContext;

            session.Interceptor.PreFlush((ICollection)persistenceContext.EntitiesByKey.Values);

            await(PrepareEntityFlushesAsync(session, cancellationToken)).ConfigureAwait(false);
            // we could move this inside if we wanted to
            // tolerate collection initializations during
            // collection dirty checking:
            await(PrepareCollectionFlushesAsync(session, cancellationToken)).ConfigureAwait(false);
            // now, any collections that are initialized
            // inside this block do not get updated - they
            // are ignored until the next flush

            persistenceContext.Flushing = true;
            try
            {
                await(FlushEntitiesAsync(@event, cancellationToken)).ConfigureAwait(false);
                await(FlushCollectionsAsync(session, cancellationToken)).ConfigureAwait(false);
            }
            finally
            {
                persistenceContext.Flushing = false;
            }

            //some statistics
            if (log.IsDebugEnabled())
            {
                log.Debug(
                    "Flushed: {0} insertions, {1} updates, {2} deletions to {3} objects",
                    session.ActionQueue.InsertionsCount,
                    session.ActionQueue.UpdatesCount,
                    session.ActionQueue.DeletionsCount,
                    persistenceContext.EntityEntries.Count);

                log.Debug(
                    "Flushed: {0} (re)creations, {1} updates, {2} removals to {3} collections",
                    session.ActionQueue.CollectionCreationsCount,
                    session.ActionQueue.CollectionUpdatesCount,
                    session.ActionQueue.CollectionRemovalsCount,
                    persistenceContext.CollectionEntries.Count);
                new Printer(session.Factory).ToString(persistenceContext.EntitiesByKey.Values.ToArray());
            }
        }
		public virtual void OnFlush(FlushEvent @event)
		{
			IEventSource source = @event.Session;

			if ((source.PersistenceContext.EntityEntries.Count > 0) || (source.PersistenceContext.CollectionEntries.Count > 0))
			{
				FlushEverythingToExecutions(@event);
				PerformExecutions(source);
				PostFlush(source);

				if (source.Factory.Statistics.IsStatisticsEnabled)
				{
					source.Factory.StatisticsImplementor.Flush();
				}
			}
		}
示例#11
0
		public virtual void OnFlush(FlushEvent @event)
		{
			IEventSource source = @event.Session;

			if (source.PersistenceContext.HasNonReadOnlyEntities)
			{
				FlushEverythingToExecutions(@event);
				PerformExecutions(source);
				PostFlush(source);

				if (source.Factory.Statistics.IsStatisticsEnabled)
				{
					source.Factory.StatisticsImplementor.Flush();
				}
			}
		}
        public virtual void OnFlush(FlushEvent @event)
        {
            IEventSource source = @event.Session;

            if (source.PersistenceContext.HasNonReadOnlyEntities)
            {
                FlushEverythingToExecutions(@event);
                PerformExecutions(source);
                PostFlush(source);

                if (source.Factory.Statistics.IsStatisticsEnabled)
                {
                    source.Factory.StatisticsImplementor.Flush();
                }
            }
        }
        public virtual void OnFlush(FlushEvent @event)
        {
            IEventSource source = @event.Session;

            if ((source.PersistenceContext.EntityEntries.Count > 0) || (source.PersistenceContext.CollectionEntries.Count > 0))
            {
                FlushEverythingToExecutions(@event);
                PerformExecutions(source);
                PostFlush(source);

                if (source.Factory.Statistics.IsStatisticsEnabled)
                {
                    source.Factory.StatisticsImplementor.Flush();
                }
            }
        }
        /// <summary>
        /// Coordinates the processing necessary to get things ready for executions
        /// as db calls by preparing the session caches and moving the appropriate
        /// entities and collections to their respective execution queues.
        /// </summary>
        /// <param name="event">The flush event.</param>
        protected virtual void FlushEverythingToExecutions(FlushEvent @event)
        {
            log.Debug("flushing session");

            IEventSource        session            = @event.Session;
            IPersistenceContext persistenceContext = session.PersistenceContext;

            session.Interceptor.PreFlush((ICollection)persistenceContext.EntitiesByKey.Values);

            PrepareEntityFlushes(session);
            // we could move this inside if we wanted to
            // tolerate collection initializations during
            // collection dirty checking:
            PrepareCollectionFlushes(session);
            // now, any collections that are initialized
            // inside this block do not get updated - they
            // are ignored until the next flush

            persistenceContext.Flushing = true;
            try
            {
                FlushEntities(@event);
                FlushCollections(session);
            }
            finally
            {
                persistenceContext.Flushing = false;
            }

            //some statistics
            if (log.IsDebugEnabled)
            {
                StringBuilder sb = new StringBuilder(100);

                sb.Append("Flushed: ").Append(session.ActionQueue.InsertionsCount).Append(" insertions, ").Append(
                    session.ActionQueue.UpdatesCount).Append(" updates, ").Append(session.ActionQueue.DeletionsCount).Append(
                    " deletions to ").Append(persistenceContext.EntityEntries.Count).Append(" objects");
                log.Debug(sb.ToString());
                sb = new StringBuilder(100);
                sb.Append("Flushed: ").Append(session.ActionQueue.CollectionCreationsCount).Append(" (re)creations, ").Append(
                    session.ActionQueue.CollectionUpdatesCount).Append(" updates, ").Append(session.ActionQueue.CollectionRemovalsCount)
                .Append(" removals to ").Append(persistenceContext.CollectionEntries.Count).Append(" collections");

                log.Debug(sb.ToString());
                new Printer(session.Factory).ToString(persistenceContext.EntitiesByKey.Values.ToArray());
            }
        }
示例#15
0
        public virtual async Task OnFlushAsync(FlushEvent @event, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            IEventSource source = @event.Session;

            if ((source.PersistenceContext.EntityEntries.Count > 0) || (source.PersistenceContext.CollectionEntries.Count > 0))
            {
                await(FlushEverythingToExecutionsAsync(@event, cancellationToken)).ConfigureAwait(false);
                await(PerformExecutionsAsync(source, cancellationToken)).ConfigureAwait(false);
                PostFlush(source);

                if (source.Factory.Statistics.IsStatisticsEnabled)
                {
                    source.Factory.StatisticsImplementor.Flush();
                }
            }
        }
示例#16
0
 /// <summary>
 /// Handle the given flush event.
 /// </summary>
 /// <param name="event">The flush event to be handled.</param>
 public void OnFlush(FlushEvent @event)
 {
     try
     {
         try
         {
             _defaultFlushListener.OnFlush(@event);
         }
         finally
         {
             AggregateDataInterceptor.UpdateAggregatesPostFlush(EnsureVersionIdsInitialised(), @event.Session);
         }
     }
     catch (Exception ex)
     {
         throw new InvalidOperationException("Error trying to flush", ex);
     }
 }
示例#17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void flushModifiedPage(long pageRef, org.neo4j.io.pagecache.tracing.EvictionEvent evictionEvent, long filePageId, org.neo4j.io.pagecache.PageSwapper swapper) throws java.io.IOException
        private void FlushModifiedPage(long pageRef, EvictionEvent evictionEvent, long filePageId, PageSwapper swapper)
        {
            FlushEvent flushEvent = evictionEvent.FlushEventOpportunity().beginFlush(filePageId, pageRef, swapper);

            try
            {
                long address      = GetAddress(pageRef);
                long bytesWritten = swapper.Write(filePageId, address);
                ExplicitlyMarkPageUnmodifiedUnderExclusiveLock(pageRef);
                flushEvent.AddBytesWritten(bytesWritten);
                flushEvent.AddPagesFlushed(1);
                flushEvent.Done();
            }
            catch (IOException e)
            {
                UnlockExclusive(pageRef);
                flushEvent.Done(e);
                evictionEvent.ThrewException(e);
                throw e;
            }
        }
        private void GenerateEventSet()
        {
            PinEvent pinEvent = _pageCursorTracer.beginPin(false, 0, _swapper);

            {
                PageFaultEvent pageFaultEvent = pinEvent.BeginPageFault();
                pageFaultEvent.AddBytesRead(150);
                {
                    EvictionEvent evictionEvent = pageFaultEvent.BeginEviction();
                    {
                        FlushEventOpportunity flushEventOpportunity = evictionEvent.FlushEventOpportunity();
                        FlushEvent            flushEvent            = flushEventOpportunity.BeginFlush(0, 0, _swapper);
                        flushEvent.AddBytesWritten(10);
                        flushEvent.Done();
                    }
                    evictionEvent.ThrewException(new IOException("eviction exception"));
                    evictionEvent.Close();
                }
                pageFaultEvent.Done();
            }
            pinEvent.Done();
        }
示例#19
0
 public void OnFlush(FlushEvent @event)
 {
     log.Debug("OnFlush :" + @event);
 }
示例#20
0
 public override void OnFlush(FlushEvent @event)
 {
     SaveAuditLogs(@event.Session);
     base.OnFlush(@event);
 }
		// 1. detect any dirty entities
		// 2. schedule any entity updates
		// 3. search out any reachable collections
		private void FlushEntities(FlushEvent @event)
		{
			log.Debug("Flushing entities and processing referenced collections");

			// Among other things, updateReachables() will recursively load all
			// collections that are moving roles. This might cause entities to
			// be loaded.

			// So this needs to be safe from concurrent modification problems.
			// It is safe because of how IdentityMap implements entrySet()
			IEventSource source = @event.Session;

			ICollection list = IdentityMap.ConcurrentEntries(source.PersistenceContext.EntityEntries);
			foreach (DictionaryEntry me in list)
			{
				// Update the status of the object and if necessary, schedule an update
				EntityEntry entry = (EntityEntry)me.Value;
				Status status = entry.Status;

				if (status != Status.Loading && status != Status.Gone)
				{
					FlushEntityEvent entityEvent = new FlushEntityEvent(source, me.Key, entry);
					IFlushEntityEventListener[] listeners = source.Listeners.FlushEntityEventListeners;
					foreach (IFlushEntityEventListener listener in listeners)
						listener.OnFlushEntity(entityEvent);
				}
			}
			source.ActionQueue.SortActions();
		}
示例#22
0
 public void OnFlush(FlushEvent e)
 {
     OnFlushInternal(e);
 }
 public void OnFlush(FlushEvent @event)
 {
     Console.WriteLine("Flush!");
 }