"pkg/apis/git@git.gitsec.cn:baidan/Kube-OVN.git" did not exist on "e8877f1d7e9c7bc1009ebfe10748c0b70ba568e1"
Commit ed1561ee authored by Chris Gioran's avatar Chris Gioran
Browse files

Merge pull request #4293 from martinfurmanski/1.9-dump-store-ids

DumpStore with list of ids.
parents 417a591b 1cfc00f6
Showing with 101 additions and 48 deletions
+101 -48
......@@ -34,7 +34,7 @@ public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAb
{
if ( args == null || args.length == 0 )
{
System.err.println( "WARNING: no files specified..." );
System.err.println( "SYNTAX: [file[:id[,id]*]]+" );
return;
}
StoreFactory storeFactory = new StoreFactory(
......@@ -43,29 +43,53 @@ public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAb
for ( String arg : args )
{
File file = new File( arg );
if ( !file.isFile() )
long[] ids = null; // null means all possible ids
if( file.isFile() )
{
/* If file exists, even with : in its path, then accept it straight off. */
}
else if ( !file.isDirectory() && file.getName().indexOf( ':' ) != -1 )
{
throw new IllegalArgumentException( "No such file: " + arg );
/* Now we know that it is not a directory either, and that the last component
of the path contains a colon, thus it is very likely an attempt to use the
id-specifying syntax. */
int idStart = arg.lastIndexOf( ':' );
String[] idStrings = arg.substring( idStart + 1 ).split( "," );
ids = new long[idStrings.length];
for ( int i = 0; i < ids.length; i++ )
{
ids[i] = Long.parseLong( idStrings[i] );
}
file = new File( arg.substring( 0, idStart ) );
if ( !file.isFile() )
{
throw new IllegalArgumentException( "No such file: " + arg );
}
}
if ( "neostore.nodestore.db".equals( file.getName() ) )
{
dumpNodeStore( file, storeFactory );
dumpNodeStore( file, storeFactory, ids );
}
else if ( "neostore.relationshipstore.db".equals( file.getName() ) )
{
dumpRelationshipStore( file, storeFactory );
dumpRelationshipStore( file, storeFactory, ids );
}
else if ( "neostore.propertystore.db".equals( file.getName() ) )
{
dumpPropertyStore( file, storeFactory );
dumpPropertyStore( file, storeFactory, ids );
}
else if ( "neostore.propertystore.db.index".equals( file.getName() ) )
{
dumpPropertyKeys( file, storeFactory );
dumpPropertyKeys( file, storeFactory, ids );
}
else if ( "neostore.relationshiptypestore.db".equals( file.getName() ) )
{
dumpRelationshipTypes( file, storeFactory );
dumpRelationshipTypes( file, storeFactory, ids );
}
else
{
......@@ -79,17 +103,17 @@ public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAb
return Boolean.getBoolean( "logger" ) ? StringLogger.SYSTEM : StringLogger.DEV_NULL;
}
private static void dumpPropertyKeys( File file, StoreFactory storeFactory ) throws Exception
private static void dumpPropertyKeys( File file, StoreFactory storeFactory, long[] ids ) throws Exception
{
dumpTokens( storeFactory.newPropertyIndexStore( file ) );
dumpTokens( storeFactory.newPropertyIndexStore( file ), ids );
}
private static void dumpRelationshipTypes( File file, StoreFactory storeFactory ) throws Exception
private static void dumpRelationshipTypes( File file, StoreFactory storeFactory, long[] ids ) throws Exception
{
dumpTokens( storeFactory.newRelationshipTypeStore( file ) );
dumpTokens( storeFactory.newRelationshipTypeStore( file ), ids );
}
private static <T extends AbstractNameRecord> void dumpTokens( final AbstractNameStore<T> store ) throws Exception
private static <T extends AbstractNameRecord> void dumpTokens( final AbstractNameStore<T> store, long[] ids ) throws Exception
{
try
{
......@@ -105,7 +129,7 @@ public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAb
}
return null;
}
}.dump( store );
}.dump( store, ids );
}
finally
{
......@@ -113,12 +137,12 @@ public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAb
}
}
private static void dumpRelationshipStore( File file, StoreFactory storeFactory ) throws Exception
private static void dumpRelationshipStore( File file, StoreFactory storeFactory, long[] ids ) throws Exception
{
RelationshipStore store = storeFactory.newRelationshipStore( file );
try
{
new DumpStore<RelationshipRecord, RelationshipStore>( System.out ).dump( store );
new DumpStore<RelationshipRecord, RelationshipStore>( System.out ).dump( store, ids );
}
finally
{
......@@ -126,12 +150,12 @@ public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAb
}
}
private static void dumpPropertyStore( File file, StoreFactory storeFactory ) throws Exception
private static void dumpPropertyStore( File file, StoreFactory storeFactory, long[] ids ) throws Exception
{
PropertyStore store = storeFactory.newPropertyStore( file );
try
{
new DumpStore<PropertyRecord, PropertyStore>( System.out ).dump( store );
new DumpStore<PropertyRecord, PropertyStore>( System.out ).dump( store, ids );
}
finally
{
......@@ -139,7 +163,7 @@ public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAb
}
}
private static void dumpNodeStore( File file, StoreFactory storeFactory ) throws Exception
private static void dumpNodeStore( File file, StoreFactory storeFactory, long[] ids ) throws Exception
{
NodeStore store = storeFactory.newNodeStore( file );
try
......@@ -151,7 +175,7 @@ public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAb
{
return record.inUse() ? record : "";
}
}.dump( store );
}.dump( store, ids );
}
finally
{
......@@ -166,7 +190,7 @@ public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAb
this.out = out;
}
public final void dump( STORE store ) throws Exception
public final void dump( STORE store, long[] ids ) throws Exception
{
store.makeStoreOk();
int size = store.getRecordSize();
......@@ -175,43 +199,72 @@ public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAb
out.println( "store.getRecordSize() = " + size );
out.println( "<dump>" );
long used = 0;
for ( long i = 1, high = store.getHighestPossibleIdInUse(); i <= high; i++ )
if ( ids == null )
{
RECORD record = store.forceGetRecord( i );
long high = store.getHighestPossibleIdInUse();
for ( long id = 1; id <= high; id++ )
{
boolean inUse = dumpRecord( store, size, fileChannel, buffer, id );
if ( inUse )
{
used++;
}
}
}
else
{
for( long id : ids )
{
dumpRecord( store, size, fileChannel, buffer, id );
}
}
out.println( "</dump>" );
if ( ids == null )
{
out.printf( "used = %s / highId = %s (%.2f%%)%n", used, store.getHighId(), used * 100.0 / store.getHighId
() );
}
}
private boolean dumpRecord( STORE store, int size, StoreChannel fileChannel, ByteBuffer buffer, long id ) throws
Exception
{
RECORD record = store.forceGetRecord( id );
Object transform = transform( record );
if ( transform != null )
{
if ( !"".equals( transform ) )
{
out.println( transform );
}
}
else
{
out.print( record );
buffer.clear();
fileChannel.read( buffer, id * size );
buffer.flip();
if ( record.inUse() )
{
used++;
dumpHex( buffer, id * size );
}
Object transform = transform( record );
if ( transform != null )
else if ( allZero( buffer ) )
{
if ( !"".equals( transform ) )
{
out.println( transform );
}
out.printf( ": all zeros @ 0x%x - 0x%x%n", id * size, (id + 1) * size );
}
else
{
out.print( record );
buffer.clear();
fileChannel.read( buffer, i * size );
buffer.flip();
if ( record.inUse() )
{
dumpHex( buffer, i * size );
}
else if ( allZero( buffer ) )
{
out.printf( ": all zeros @ 0x%x - 0x%x%n", i * size, (i + 1) * size );
}
else
{
dumpHex( buffer, i * size );
}
dumpHex( buffer, id * size );
}
}
out.println( "</dump>" );
out.printf( "used = %s / highId = %s (%.2f%%)%n", used, store.getHighId(), used * 100.0 / store.getHighId() );
return record.inUse();
}
private boolean allZero( ByteBuffer buffer )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment