Skip to content

Commit

Permalink
Add total size of all log log files and total size of all index files…
Browse files Browse the repository at this point in the history
… to jmx
  • Loading branch information
klaren committed Jul 3, 2017
1 parent 2ec5aea commit 40570fb
Show file tree
Hide file tree
Showing 19 changed files with 312 additions and 166 deletions.
5 changes: 5 additions & 0 deletions community/jmx/pom.xml
Expand Up @@ -79,6 +79,11 @@ the relevant Commercial Agreement.
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>commons-codec</groupId> <groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId> <artifactId>commons-codec</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions community/jmx/src/main/java/org/neo4j/jmx/StoreFile.java
Expand Up @@ -46,4 +46,10 @@ public interface StoreFile


@Description( "The amount of disk space used to store array properties, in bytes." ) @Description( "The amount of disk space used to store array properties, in bytes." )
long getArrayStoreSize(); long getArrayStoreSize();

@Description( "The amount of disk space used by all logical logs, in bytes." )
long getAllLogicalLogsSize();

@Description( "The amount of disk space used by all indices, in bytes" )
long getIndexStoreSize();
} }
140 changes: 99 additions & 41 deletions community/jmx/src/main/java/org/neo4j/jmx/impl/StoreFileBean.java
Expand Up @@ -24,15 +24,28 @@
import javax.management.NotCompliantMBeanException; import javax.management.NotCompliantMBeanException;


import org.neo4j.helpers.Service; import org.neo4j.helpers.Service;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.jmx.StoreFile; import org.neo4j.jmx.StoreFile;
import org.neo4j.kernel.NeoStoreDataSource; import org.neo4j.kernel.NeoStoreDataSource;
import org.neo4j.kernel.api.index.SchemaIndexProvider;
import org.neo4j.kernel.api.labelscan.LabelScanStore;
import org.neo4j.kernel.impl.api.LegacyIndexProviderLookup;
import org.neo4j.kernel.impl.store.MetaDataStore;
import org.neo4j.kernel.impl.transaction.log.LogFile; import org.neo4j.kernel.impl.transaction.log.LogFile;
import org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles;
import org.neo4j.kernel.impl.transaction.state.DataSourceManager; import org.neo4j.kernel.impl.transaction.state.DataSourceManager;
import org.neo4j.kernel.spi.legacyindex.IndexImplementation;

import static org.neo4j.kernel.impl.store.StoreFactory.NODE_STORE_NAME;
import static org.neo4j.kernel.impl.store.StoreFactory.PROPERTY_ARRAYS_STORE_NAME;
import static org.neo4j.kernel.impl.store.StoreFactory.PROPERTY_STORE_NAME;
import static org.neo4j.kernel.impl.store.StoreFactory.PROPERTY_STRINGS_STORE_NAME;
import static org.neo4j.kernel.impl.store.StoreFactory.RELATIONSHIP_STORE_NAME;


@Service.Implementation( ManagementBeanProvider.class ) @Service.Implementation( ManagementBeanProvider.class )
public final class StoreFileBean extends ManagementBeanProvider public final class StoreFileBean extends ManagementBeanProvider
{ {
public StoreFileBean() StoreFileBean()
{ {
super( StoreFile.class ); super( StoreFile.class );
} }
Expand All @@ -43,34 +56,53 @@ protected Neo4jMBean createMBean( ManagementData management ) throws NotComplian
return new StoreFileImpl( management ); return new StoreFileImpl( management );
} }


private static class StoreFileImpl extends Neo4jMBean implements StoreFile static class StoreFileImpl extends Neo4jMBean implements StoreFile
{ {
private static final String NODE_STORE = "neostore.nodestore.db"; private static final String NODE_STORE = MetaDataStore.DEFAULT_NAME + NODE_STORE_NAME;
private static final String RELATIONSHIP_STORE = "neostore.relationshipstore.db"; private static final String RELATIONSHIP_STORE = MetaDataStore.DEFAULT_NAME + RELATIONSHIP_STORE_NAME;
private static final String PROPERTY_STORE = "neostore.propertystore.db"; private static final String PROPERTY_STORE = MetaDataStore.DEFAULT_NAME + PROPERTY_STORE_NAME;
private static final String ARRAY_STORE = "neostore.propertystore.db.arrays"; private static final String ARRAY_STORE = MetaDataStore.DEFAULT_NAME + PROPERTY_ARRAYS_STORE_NAME;
private static final String STRING_STORE = "neostore.propertystore.db.strings"; private static final String STRING_STORE = MetaDataStore.DEFAULT_NAME + PROPERTY_STRINGS_STORE_NAME;

private File storePath; private File storePath;
private LogFile logFile; private LogFile logFile;
private PhysicalLogFiles physicalLogFiles;
private FileSystemAbstraction fs;
private LegacyIndexProviderLookup legacyIndexProviderLookup;
private SchemaIndexProvider schemaIndexProvider;
private LabelScanStore labelScanStore;


StoreFileImpl( ManagementData management ) throws NotCompliantMBeanException StoreFileImpl( ManagementData management ) throws NotCompliantMBeanException
{ {
super( management ); super( management );


fs = management.getKernelData().getFilesystemAbstraction();

DataSourceManager dataSourceManager = management.resolveDependency( DataSourceManager.class ); DataSourceManager dataSourceManager = management.resolveDependency( DataSourceManager.class );
dataSourceManager.addListener( new DataSourceManager.Listener() dataSourceManager.addListener( new DataSourceManager.Listener()
{ {
@Override @Override
public void registered( NeoStoreDataSource ds ) public void registered( NeoStoreDataSource ds )
{ {
logFile = ds.getDependencyResolver().resolveDependency( LogFile.class ); logFile = resolveDependency( ds, LogFile.class );
physicalLogFiles = resolveDependency( ds, PhysicalLogFiles.class );
legacyIndexProviderLookup = resolveDependency( ds, LegacyIndexProviderLookup.class );
schemaIndexProvider = resolveDependency( ds, SchemaIndexProvider.class );
labelScanStore = resolveDependency( ds, LabelScanStore.class );

storePath = resolvePath( ds ); storePath = resolvePath( ds );
} }


private <T> T resolveDependency( NeoStoreDataSource ds, Class<T> clazz )
{
return ds.getDependencyResolver().resolveDependency( clazz );
}

@Override @Override
public void unregistered( NeoStoreDataSource ds ) public void unregistered( NeoStoreDataSource ds )
{ {
logFile = null; logFile = null;
physicalLogFiles = null;
storePath = null; storePath = null;
} }


Expand All @@ -91,96 +123,122 @@ private File resolvePath( NeoStoreDataSource ds )
@Override @Override
public long getTotalStoreSize() public long getTotalStoreSize()
{ {
return storePath == null ? 0 : sizeOf( storePath ); return storePath == null ? 0 : sizeOf( fs, storePath );
} }


@Override @Override
public long getLogicalLogSize() public long getLogicalLogSize()
{ {
return logFile == null ? 0 : sizeOf( logFile.currentLogFile() ); return logFile == null ? 0 : sizeOf( fs, logFile.currentLogFile() );
} }


private static long sizeOf( File file ) private static long sizeOf( FileSystemAbstraction fs, File file )
{ {
if ( file.isFile() ) if ( fs.isDirectory( file ) )
{
return file.length();
}
else if ( file.isDirectory() )
{ {
long size = 0; long size = 0;
File[] files = file.listFiles(); File[] files = fs.listFiles( file );
if ( files == null ) if ( files == null )
{ {
return 0; return 0;
} }
for ( File child : files ) for ( File child : files )
{ {
size += sizeOf( child ); size += sizeOf( fs, child );
} }
return size; return size;
} }
return 0; else
{
return fs.getFileSize( file );
}
} }


private long sizeOf( String name ) private long sizeOf( String name )
{ {
return sizeOf( new File( storePath, name ) ); return storePath == null ? 0 : sizeOf( fs, new File( storePath, name ) );
} }


@Override @Override
public long getArrayStoreSize() public long getArrayStoreSize()
{ {
if ( storePath == null )
{
return 0;
}

return sizeOf( ARRAY_STORE ); return sizeOf( ARRAY_STORE );
} }


@Override @Override
public long getNodeStoreSize() public long getAllLogicalLogsSize()
{ {
if ( storePath == null ) TotalSizeVersionVisitor logVersionVisitor = new TotalSizeVersionVisitor( fs );

physicalLogFiles.accept( logVersionVisitor );

return logVersionVisitor.getTotalSize();
}

@Override
public long getIndexStoreSize()
{
long size = 0;

// Add legacy indices
for ( IndexImplementation index : legacyIndexProviderLookup.all() )
{ {
return 0; size += sizeOf( fs, index.getIndexImplementationDirectory( storePath ) );
} }


// Add schema index
size += sizeOf( fs, schemaIndexProvider.getSchemaIndexStoreDirectory( storePath ) );

// Add label index
size += sizeOf( fs, labelScanStore.getLabelScanStoreFile() );

return size;
}

@Override
public long getNodeStoreSize()
{
return sizeOf( NODE_STORE ); return sizeOf( NODE_STORE );
} }


@Override @Override
public long getPropertyStoreSize() public long getPropertyStoreSize()
{ {
if ( storePath == null )
{
return 0;
}

return sizeOf( PROPERTY_STORE ); return sizeOf( PROPERTY_STORE );
} }


@Override @Override
public long getRelationshipStoreSize() public long getRelationshipStoreSize()
{ {
if ( storePath == null )
{
return 0;
}

return sizeOf( RELATIONSHIP_STORE ); return sizeOf( RELATIONSHIP_STORE );
} }


@Override @Override
public long getStringStoreSize() public long getStringStoreSize()
{ {
if ( storePath == null ) return sizeOf( STRING_STORE );
}

private static class TotalSizeVersionVisitor implements PhysicalLogFiles.LogVersionVisitor
{
private final FileSystemAbstraction fs;
private long totalSize;

TotalSizeVersionVisitor( FileSystemAbstraction fs )
{ {
return 0; this.fs = fs;
} }


return sizeOf( STRING_STORE ); long getTotalSize()
{
return totalSize;
}

@Override
public void visit( File file, long logVersion )
{
totalSize += sizeOf( fs, file );
}
} }
} }
} }

0 comments on commit 40570fb

Please sign in to comment.