Skip to content

Commit

Permalink
Introduce Page Cursor Counters interface to split
Browse files Browse the repository at this point in the history
cursor counters and tracers to isolate code that can only access counters
and actually do cursor events tracing.
  • Loading branch information
MishaDemianenko committed Feb 27, 2017
1 parent af01c42 commit d4b0cbf
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 31 deletions.
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.io.pagecache.tracing.cursor;

/**
* Expose information from page cache about particular page cursor events.
*
* Exposed counters are relevant only for particular cursor and do not represent global page cache wide picture.
*
* @see PageCursorCounters
* @see PageCursorTracer
*/
public interface PageCursorCounters
{
/**
* @return The number of page faults observed thus far.
*/
long faults();

/**
* @return The number of page pins observed thus far.
*/
long pins();

/**
* @return The number of page unpins observed thus far.
*/
long unpins();

/**
* @return The sum total of bytes read in through page faults thus far.
*/
long bytesRead();

}
Expand Up @@ -23,8 +23,16 @@
import org.neo4j.io.pagecache.tracing.PageCacheTracer; import org.neo4j.io.pagecache.tracing.PageCacheTracer;
import org.neo4j.io.pagecache.tracing.PinEvent; import org.neo4j.io.pagecache.tracing.PinEvent;


//:TODO javadoc /**
public interface PageCursorTracer * Event tracer for page cursors.
*
* Performs event tracing related to particular page cursors and expose simple counters around them.
* Since events of each particular page cursor are part of whole page cache events, each particular page cursor
* tracer will eventually report them to global page cache counters/tracers.
*
* @see PageCursorTracer
*/
public interface PageCursorTracer extends PageCursorCounters
{ {


PageCursorTracer NULL = new PageCursorTracer() PageCursorTracer NULL = new PageCursorTracer()
Expand Down Expand Up @@ -72,29 +80,8 @@ public void reportEvents()
} }
}; };


/**
* @return The number of page faults observed thus far.
*/
long faults();

/**
* @return The number of page pins observed thus far.
*/
long pins();

/**
* @return The number of page unpins observed thus far.
*/
long unpins();

/**
* @return The sum total of bytes read in through page faults thus far.
*/
long bytesRead();

PinEvent beginPin( boolean writeLock, long filePageId, PageSwapper swapper ); PinEvent beginPin( boolean writeLock, long filePageId, PageSwapper swapper );


// TODO:: methods that glue current tracer to page cache tracer can be avoided?
void init( PageCacheTracer tracer ); void init( PageCacheTracer tracer );


void reportEvents(); void reportEvents();
Expand Down
Expand Up @@ -24,7 +24,7 @@


import org.neo4j.graphdb.NotInTransactionException; import org.neo4j.graphdb.NotInTransactionException;
import org.neo4j.graphdb.TransactionTerminatedException; import org.neo4j.graphdb.TransactionTerminatedException;
import org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer; import org.neo4j.io.pagecache.tracing.cursor.PageCursorCounters;
import org.neo4j.kernel.api.DataWriteOperations; import org.neo4j.kernel.api.DataWriteOperations;
import org.neo4j.kernel.api.query.ExecutingQuery; import org.neo4j.kernel.api.query.ExecutingQuery;
import org.neo4j.kernel.api.ProcedureCallOperations; import org.neo4j.kernel.api.ProcedureCallOperations;
Expand Down Expand Up @@ -53,14 +53,14 @@
* <ol> * <ol>
* <li>Construct {@link KernelStatement} when {@link KernelTransactionImplementation} is constructed</li> * <li>Construct {@link KernelStatement} when {@link KernelTransactionImplementation} is constructed</li>
* <li>For every transaction...</li> * <li>For every transaction...</li>
* <li>Call {@link #initialize(StatementLocks, StatementOperationParts, PageCursorTracer)} which makes this instance * <li>Call {@link #initialize(StatementLocks, StatementOperationParts, PageCursorCounters)} which makes this instance
* full available and ready to use. Call when the {@link KernelTransactionImplementation} is initialized.</li> * full available and ready to use. Call when the {@link KernelTransactionImplementation} is initialized.</li>
* <li>Alternate {@link #acquire()} / {@link #close()} when acquiring / closing a statement for the transaction... * <li>Alternate {@link #acquire()} / {@link #close()} when acquiring / closing a statement for the transaction...
* Temporarily asymmetric number of calls to {@link #acquire()} / {@link #close()} is supported, although in * Temporarily asymmetric number of calls to {@link #acquire()} / {@link #close()} is supported, although in
* the end an equal number of calls must have been issued.</li> * the end an equal number of calls must have been issued.</li>
* <li>To be safe call {@link #forceClose()} at the end of a transaction to force a close of the statement, * <li>To be safe call {@link #forceClose()} at the end of a transaction to force a close of the statement,
* even if there are more than one current call to {@link #acquire()}. This instance is now again ready * even if there are more than one current call to {@link #acquire()}. This instance is now again ready
* to be {@link #initialize(StatementLocks, StatementOperationParts, PageCursorTracer) initialized} and used for the transaction * to be {@link #initialize(StatementLocks, StatementOperationParts, PageCursorCounters)} initialized} and used for the transaction
* instance again, when it's initialized.</li> * instance again, when it's initialized.</li>
* </ol> * </ol>
*/ */
Expand All @@ -72,7 +72,7 @@ public class KernelStatement implements TxStateHolder, Statement
private final KernelTransactionImplementation transaction; private final KernelTransactionImplementation transaction;
private final OperationsFacade facade; private final OperationsFacade facade;
private StatementLocks statementLocks; private StatementLocks statementLocks;
private PageCursorTracer pageCursorTracer; private PageCursorCounters pageCursorCounters;
private int referenceCount; private int referenceCount;
private volatile ExecutingQueryList executingQueryList; private volatile ExecutingQueryList executingQueryList;
private final LockTracer systemLockTracer; private final LockTracer systemLockTracer;
Expand Down Expand Up @@ -186,10 +186,10 @@ void assertOpen()
} }


public void initialize( StatementLocks statementLocks, StatementOperationParts operationParts, public void initialize( StatementLocks statementLocks, StatementOperationParts operationParts,
PageCursorTracer pageCursorTracer ) PageCursorCounters pageCursorCounters )
{ {
this.statementLocks = statementLocks; this.statementLocks = statementLocks;
this.pageCursorTracer = pageCursorTracer; this.pageCursorCounters = pageCursorCounters;
facade.initialize( operationParts ); facade.initialize( operationParts );
} }


Expand All @@ -204,9 +204,9 @@ public LockTracer lockTracer()
return tracer == null ? systemLockTracer : systemLockTracer.combine( tracer ); return tracer == null ? systemLockTracer : systemLockTracer.combine( tracer );
} }


public PageCursorTracer getPageCursorTracer() public PageCursorCounters getPageCursorCounters()
{ {
return pageCursorTracer; return pageCursorCounters;
} }


public final void acquire() public final void acquire()
Expand Down

0 comments on commit d4b0cbf

Please sign in to comment.