org.neo4j.kernel.impl.api.tracer.CountingLogCheckPointEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neo4j-kernel Show documentation
Show all versions of neo4j-kernel Show documentation
Neo4j kernel is a lightweight, embedded Java database designed to
store data structured as graphs rather than tables. For more
information, see http://neo4j.org.
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.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 .
*/
package org.neo4j.kernel.impl.api.tracer;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
import org.neo4j.kernel.impl.transaction.log.LogPosition;
import org.neo4j.kernel.impl.transaction.tracing.LogCheckPointEvent;
import org.neo4j.kernel.impl.transaction.tracing.LogForceEvent;
import org.neo4j.kernel.impl.transaction.tracing.LogForceWaitEvent;
import org.neo4j.kernel.impl.transaction.tracing.LogRotateEvent;
/**
* Log checkpoint event that counts number of checkpoint that occurred and amount of time elapsed
* for all of them and for the last one.
*/
class CountingLogCheckPointEvent implements LogCheckPointEvent
{
private final AtomicLong checkpointCounter = new AtomicLong();
private final AtomicLong accumulatedCheckpointTotalTimeMillis = new AtomicLong();
private final BiConsumer logFileAppendConsumer;
private final CountingLogRotateEvent countingLogRotateEvent;
private volatile long lastCheckpointTimeMillis;
CountingLogCheckPointEvent( BiConsumer logFileAppendConsumer, CountingLogRotateEvent countingLogRotateEvent )
{
this.logFileAppendConsumer = logFileAppendConsumer;
this.countingLogRotateEvent = countingLogRotateEvent;
}
@Override
public void checkpointCompleted( long checkpointMillis )
{
checkpointCounter.incrementAndGet();
accumulatedCheckpointTotalTimeMillis.addAndGet( checkpointMillis );
lastCheckpointTimeMillis = checkpointMillis;
}
@Override
public void close()
{
//empty
}
@Override
public void appendToLogFile( LogPosition positionBeforeCheckpoint, LogPosition positionAfterCheckpoint )
{
logFileAppendConsumer.accept( positionBeforeCheckpoint, positionAfterCheckpoint );
}
@Override
public LogForceWaitEvent beginLogForceWait()
{
return LogForceWaitEvent.NULL;
}
@Override
public LogForceEvent beginLogForce()
{
return LogForceEvent.NULL;
}
long numberOfCheckPoints()
{
return checkpointCounter.get();
}
long checkPointAccumulatedTotalTimeMillis()
{
return accumulatedCheckpointTotalTimeMillis.get();
}
long lastCheckpointTimeMillis()
{
return lastCheckpointTimeMillis;
}
@Override
public LogRotateEvent beginLogRotate()
{
return countingLogRotateEvent;
}
}