Skip to content

Commit

Permalink
Remove dependency on IdGeneratorFactory from EntityCountMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Jan 18, 2016
1 parent 5f5ce38 commit 27efdf4
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 23 deletions.
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2002-2015 "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.kernel.impl.store.stats;

import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;

import static org.neo4j.kernel.impl.store.id.IdType.NODE;
import static org.neo4j.kernel.impl.store.id.IdType.PROPERTY;
import static org.neo4j.kernel.impl.store.id.IdType.RELATIONSHIP;
import static org.neo4j.kernel.impl.store.id.IdType.RELATIONSHIP_TYPE_TOKEN;

public class IdBasedStoreEntityCounters implements StoreEntityCounters
{
private final IdGeneratorFactory idGeneratorFactory;

public IdBasedStoreEntityCounters( IdGeneratorFactory idGeneratorFactory )
{
this.idGeneratorFactory = idGeneratorFactory;
}

@Override
public long nodes()
{
return idGeneratorFactory.get( NODE ).getNumberOfIdsInUse();
}

@Override
public long relationships()
{
return idGeneratorFactory.get( RELATIONSHIP ).getNumberOfIdsInUse();
}

@Override
public long properties()
{
return idGeneratorFactory.get( PROPERTY ).getNumberOfIdsInUse();
}

@Override
public long relationshipTypes()
{
return idGeneratorFactory.get( RELATIONSHIP_TYPE_TOKEN ).getNumberOfIdsInUse();
}
}
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2002-2015 "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.kernel.impl.store.stats;

public interface StoreEntityCounters
{
long nodes();

long relationships();

long properties();

long relationshipTypes();
}
Expand Up @@ -111,6 +111,7 @@
import org.neo4j.kernel.impl.factory.PlatformModule;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.store.stats.IdBasedStoreEntityCounters;
import org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory;
import org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore;
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore;
Expand Down Expand Up @@ -276,6 +277,7 @@ public EnterpriseCoreEditionModule( final PlatformModule platformModule,
createIdGeneratorFactory( fileSystem, idRangeAcquirer, logProvider );

this.idGeneratorFactory = dependencies.satisfyDependency( replicatedIdGeneratorFactory );
dependencies.satisfyDependency( new IdBasedStoreEntityCounters( this.idGeneratorFactory ) );

Long tokenCreationTimeout = config.get( CoreEdgeClusterSettings.token_creation_timeout );
ReplicatedRelationshipTypeTokenHolder relationshipTypeTokenHolder = new ReplicatedRelationshipTypeTokenHolder(
Expand Down
Expand Up @@ -43,7 +43,6 @@
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.DatabaseAvailability;
import org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory;
import org.neo4j.kernel.GraphDatabaseAPI;
import org.neo4j.kernel.KernelData;
import org.neo4j.kernel.NeoStoreDataSource;
Expand All @@ -65,6 +64,8 @@
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;
import org.neo4j.kernel.impl.factory.PlatformModule;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory;
import org.neo4j.kernel.impl.store.stats.IdBasedStoreEntityCounters;
import org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory;
import org.neo4j.kernel.impl.transaction.log.TransactionAppender;
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore;
Expand Down Expand Up @@ -102,6 +103,7 @@ public EnterpriseEdgeEditionModule( final PlatformModule platformModule,
lockManager = dependencies.satisfyDependency( createLockManager( config, logging ) );

idGeneratorFactory = dependencies.satisfyDependency( new DefaultIdGeneratorFactory( fileSystem ) );
dependencies.satisfyDependency( new IdBasedStoreEntityCounters( this.idGeneratorFactory ) );

propertyKeyTokenHolder = life.add( dependencies.satisfyDependency(
new DelegatingPropertyKeyTokenHolder( new ReadOnlyTokenCreator() ) ) );
Expand Down
Expand Up @@ -58,7 +58,6 @@
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.AvailabilityGuard;
import org.neo4j.kernel.GraphDatabaseAPI;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.KernelData;
import org.neo4j.kernel.NeoStoreDataSource;
import org.neo4j.kernel.api.KernelAPI;
Expand Down Expand Up @@ -136,6 +135,8 @@
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.store.StoreId;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.impl.store.stats.IdBasedStoreEntityCounters;
import org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory;
import org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore;
import org.neo4j.kernel.impl.transaction.log.ReadableLogChannel;
Expand Down Expand Up @@ -325,6 +326,7 @@ public void elected( String role, InstanceId instanceId, URI electedMember )

idGeneratorFactory = dependencies.satisfyDependency( createIdGeneratorFactory(
masterDelegateInvocationHandler, logging.getInternalLogProvider(), requestContextFactory, fs ) );
dependencies.satisfyDependency( new IdBasedStoreEntityCounters( this.idGeneratorFactory ) );

// TODO There's a cyclical dependency here that should be fixed
final AtomicReference<HighAvailabilityModeSwitcher> exceptionHandlerRef = new AtomicReference<>();
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.neo4j.kernel.impl.factory.CommunityEditionModule;
import org.neo4j.kernel.impl.factory.EditionModule;
import org.neo4j.kernel.impl.factory.PlatformModule;
import org.neo4j.kernel.impl.store.stats.IdBasedStoreEntityCounters;

/**
* This implementation of {@link EditionModule} creates the implementations of services
Expand All @@ -33,11 +34,12 @@ public class EnterpriseEditionModule extends CommunityEditionModule
public EnterpriseEditionModule( PlatformModule platformModule )
{
super( platformModule );
platformModule.dependencies.satisfyDependency( new IdBasedStoreEntityCounters( this.idGeneratorFactory ) );
}

@Override
protected ConstraintSemantics createSchemaRuleVerifier()
{
return new EnterpriseConstraintSemantics();
}
}
}
Expand Up @@ -43,7 +43,7 @@ public MetricsKernelExtensionFactory()
}

@Override
public Lifecycle newKernelExtension( Dependencies dependencies ) throws Throwable
public Lifecycle newInstance( KernelContext context, Dependencies dependencies ) throws Throwable
{
return new MetricsExtension( dependencies );
}
Expand Down
Expand Up @@ -23,11 +23,11 @@

import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.io.pagecache.monitoring.PageCacheMonitor;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.ha.cluster.member.ClusterMembers;
import org.neo4j.kernel.impl.api.LogRotationMonitor;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.store.stats.StoreEntityCounters;
import org.neo4j.kernel.impl.transaction.TransactionCounters;
import org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointerMonitor;
import org.neo4j.kernel.impl.transaction.state.DataSourceManager;
Expand Down Expand Up @@ -71,8 +71,7 @@ public interface Dependencies

LogRotationMonitor logRotationMonitor();

@SuppressWarnings( "deprecation" )
IdGeneratorFactory idGeneratorFactory();
StoreEntityCounters entityCountStats();

DependencyResolver getDependencyResolver();
}
Expand Down Expand Up @@ -120,7 +119,7 @@ public boolean build()

if ( config.get( MetricsSettings.neoCountsEnabled ) )
{
life.add( new EntityCountMetrics( registry, deps.idGeneratorFactory() ) );
life.add( new EntityCountMetrics( registry, deps.entityCountStats() ) );
result = true;
}

Expand Down
Expand Up @@ -22,15 +22,11 @@
import com.codahale.metrics.Gauge;
import com.codahale.metrics.MetricRegistry;

import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.impl.annotations.Documented;
import org.neo4j.kernel.impl.store.stats.StoreEntityCounters;
import org.neo4j.kernel.lifecycle.LifecycleAdapter;

import static com.codahale.metrics.MetricRegistry.name;
import static org.neo4j.kernel.impl.store.id.IdType.NODE;
import static org.neo4j.kernel.impl.store.id.IdType.PROPERTY;
import static org.neo4j.kernel.impl.store.id.IdType.RELATIONSHIP;
import static org.neo4j.kernel.impl.store.id.IdType.RELATIONSHIP_TYPE_TOKEN;

@Documented( ".Database Data Metrics" )
public class EntityCountMetrics extends LifecycleAdapter
Expand All @@ -47,24 +43,21 @@ public class EntityCountMetrics extends LifecycleAdapter
public static final String COUNTS_NODE = name( COUNTS_PREFIX, "node" );

private final MetricRegistry registry;
private final IdGeneratorFactory idGeneratorFactory;
private final StoreEntityCounters storeEntityCounters;

public EntityCountMetrics( MetricRegistry registry, IdGeneratorFactory idGeneratorFactory )
public EntityCountMetrics( MetricRegistry registry, StoreEntityCounters storeEntityCounters )
{
this.registry = registry;
this.idGeneratorFactory = idGeneratorFactory;
this.storeEntityCounters = storeEntityCounters;
}

@Override
public void start()
{
registry.register( COUNTS_NODE, (Gauge<Long>) () -> idGeneratorFactory.get( NODE ).getNumberOfIdsInUse() );
registry.register( COUNTS_RELATIONSHIP,
(Gauge<Long>) () -> idGeneratorFactory.get( RELATIONSHIP ).getNumberOfIdsInUse() );
registry.register( COUNTS_PROPERTY,
(Gauge<Long>) () -> idGeneratorFactory.get( PROPERTY ).getNumberOfIdsInUse() );
registry.register( COUNTS_RELATIONSHIP_TYPE,
(Gauge<Long>) () -> idGeneratorFactory.get( RELATIONSHIP_TYPE_TOKEN ).getNumberOfIdsInUse() );
registry.register( COUNTS_NODE, (Gauge<Long>) storeEntityCounters::nodes );
registry.register( COUNTS_RELATIONSHIP, (Gauge<Long>) storeEntityCounters::relationships );
registry.register( COUNTS_PROPERTY, (Gauge<Long>) storeEntityCounters::properties );
registry.register( COUNTS_RELATIONSHIP_TYPE, (Gauge<Long>) storeEntityCounters::relationshipTypes );
}

@Override
Expand Down

0 comments on commit 27efdf4

Please sign in to comment.