Skip to content

Commit

Permalink
Progress reporting on all migration participants
Browse files Browse the repository at this point in the history
also makes sure that the migration progress is visible to the user by
using the user log.
  • Loading branch information
tinwelint committed Dec 14, 2015
1 parent 4403517 commit 1c4f20c
Show file tree
Hide file tree
Showing 25 changed files with 528 additions and 157 deletions.
Expand Up @@ -551,7 +551,7 @@ private void upgradeStore()
HighestSelectionStrategy.getInstance() ); HighestSelectionStrategy.getInstance() );


VisibleMigrationProgressMonitor progressMonitor = VisibleMigrationProgressMonitor progressMonitor =
new VisibleMigrationProgressMonitor( logService.getInternalLog( StoreMigrator.class ) ); new VisibleMigrationProgressMonitor( logService.getUserLog( StoreMigrator.class ) );
new DatabaseMigrator( new DatabaseMigrator(
progressMonitor, progressMonitor,
fs, fs,
Expand Down
Expand Up @@ -23,15 +23,15 @@
import java.io.IOException; import java.io.IOException;


import org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor; import org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor;
import org.neo4j.kernel.impl.storemigration.participant.BaseStoreMigrationParticipant; import org.neo4j.kernel.impl.storemigration.participant.AbstractStoreMigrationParticipant;
import org.neo4j.kernel.impl.util.UnsatisfiedDependencyException; import org.neo4j.kernel.impl.util.UnsatisfiedDependencyException;


public interface StoreMigrationParticipant public interface StoreMigrationParticipant
{ {
/** /**
* Default empty implementation of StoreMigrationParticipant * Default empty implementation of StoreMigrationParticipant
*/ */
StoreMigrationParticipant NOT_PARTICIPATING = new BaseStoreMigrationParticipant(); StoreMigrationParticipant NOT_PARTICIPATING = new AbstractStoreMigrationParticipant( "Nothing" );


/** /**
* Performs migration of data this participant is responsible for if necessary. * Performs migration of data this participant is responsible for if necessary.
Expand All @@ -42,19 +42,19 @@ public interface StoreMigrationParticipant
* *
* @param storeDir data to migrate. * @param storeDir data to migrate.
* @param migrationDir place to migrate to. * @param migrationDir place to migrate to.
* @param progressMonitor migration progress monitor * @param progress migration progress monitor
* @param versionToMigrateFrom the version to migrate from * @param versionToMigrateFrom the version to migrate from
* @throws IOException if there was an error migrating. * @throws IOException if there was an error migrating.
* @throws UnsatisfiedDependencyException if one or more dependencies were unsatisfied. * @throws UnsatisfiedDependencyException if one or more dependencies were unsatisfied.
*/ */
void migrate( File storeDir, File migrationDir, MigrationProgressMonitor progressMonitor, void migrate( File storeDir, File migrationDir, MigrationProgressMonitor.Section progress,
String versionToMigrateFrom ) throws IOException; String versionToMigrateFrom ) throws IOException;


/** /**
* After a successful migration, move all affected files from {@code upgradeDirectory} over to * After a successful migration, move all affected files from {@code upgradeDirectory} over to
* the {@code workingDirectory}, effectively activating the migration changes. * the {@code workingDirectory}, effectively activating the migration changes.
* @param migrationDir directory where the * @param migrationDir directory where the
* {@link #migrate(File, File, MigrationProgressMonitor, String) migration} put its files. * {@link #migrate(File, File, MigrationProgressMonitor.Section, String) migration} put its files.
* @param storeDir directory the store directory of the to move the migrated files to. * @param storeDir directory the store directory of the to move the migrated files to.
* @param versionToMigrateFrom the version we have migrated from * @param versionToMigrateFrom the version we have migrated from
* @throws IOException if unable to move one or more files. * @throws IOException if unable to move one or more files.
Expand All @@ -78,4 +78,8 @@ void migrate( File storeDir, File migrationDir, MigrationProgressMonitor progres
*/ */
void cleanup( File migrationDir ) throws IOException; void cleanup( File migrationDir ) throws IOException;


/**
* @return descriptive name of this migration participant.
*/
String getName();
} }
Expand Up @@ -31,9 +31,12 @@
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor; import org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor;
import org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor.Section;
import org.neo4j.logging.Log; import org.neo4j.logging.Log;
import org.neo4j.logging.LogProvider; import org.neo4j.logging.LogProvider;


import static java.lang.String.format;

/** /**
* A migration process to migrate {@link StoreMigrationParticipant migration participants}, if there's * A migration process to migrate {@link StoreMigrationParticipant migration participants}, if there's
* need for it, before the database fully starts. Participants can * need for it, before the database fully starts. Participants can
Expand Down Expand Up @@ -144,7 +147,7 @@ public void migrateIfNeeded( File storeDirectory)


cleanup( participants, migrationDirectory ); cleanup( participants, migrationDirectory );


progressMonitor.finished(); progressMonitor.completed();
} }


private boolean isUpgradeAllowed() private boolean isUpgradeAllowed()
Expand Down Expand Up @@ -223,9 +226,14 @@ private void migrateToIsolatedDirectory( File storeDir, File migrationDirectory,
{ {
try try
{ {
int index = 1;
for ( StoreMigrationParticipant participant : participants ) for ( StoreMigrationParticipant participant : participants )
{ {
participant.migrate( storeDir, migrationDirectory, progressMonitor, versionToMigrateFrom ); Section section = progressMonitor.startSection(
format( "%s (%d/%d)", participant.getName(), index, participants.size() ) );
participant.migrate( storeDir, migrationDirectory, section, versionToMigrateFrom );
section.completed();
index++;
} }
} }
catch ( IOException e ) catch ( IOException e )
Expand Down
Expand Up @@ -21,10 +21,41 @@


public interface MigrationProgressMonitor public interface MigrationProgressMonitor
{ {
/**
* Signals that the migration process has started.
*/
void started(); void started();

/** /**
* @param percent 0..100 * Signals that migration goes into section with given {@code name}.
*
* @param name descriptive name of the section to migration.
* @return {@link Section} which should be notified about progress in the given section.
*/ */
void percentComplete(int percent); Section startSection( String name );
void finished();
/**
* The migration process has completed successfully.
*/
void completed();

interface Section
{
/**
* @param max max progress, which {@link #progress(long)} moves towards.
*/
void start( long max );

/**
* Percentage completeness for the current section.
*
* @param add progress to add towards a maximum.
*/
void progress( long add );

/**
* Called if this section was completed successfully.
*/
void completed();
}
} }
Expand Up @@ -21,15 +21,37 @@


public class SilentMigrationProgressMonitor implements MigrationProgressMonitor public class SilentMigrationProgressMonitor implements MigrationProgressMonitor
{ {
private static final Section SECTION = new Section()
{
@Override
public void progress( long add )
{
}

@Override
public void start( long max )
{
}

@Override
public void completed()
{
}
};

@Override
public void started() public void started()
{ {
} }


public void percentComplete( int percent ) @Override
public Section startSection( String name )
{ {
return SECTION;
} }


public void finished() @Override
public void completed()
{ {
} }
} }
Expand Up @@ -25,6 +25,9 @@


public class VisibleMigrationProgressMonitor implements MigrationProgressMonitor public class VisibleMigrationProgressMonitor implements MigrationProgressMonitor
{ {
static final String MESSAGE_STARTED = "Starting upgrade of database";
static final String MESSAGE_COMPLETED = "Successfully finished upgrade of database";

private final Log log; private final Log log;


public VisibleMigrationProgressMonitor( Log log ) public VisibleMigrationProgressMonitor( Log log )
Expand All @@ -35,21 +38,65 @@ public VisibleMigrationProgressMonitor( Log log )
@Override @Override
public void started() public void started()
{ {
log.info( "Starting upgrade of database store files" ); log.info( MESSAGE_STARTED );
} }


@Override @Override
public void percentComplete( int percent ) public Section startSection( String name )
{ {
if (percent % 10 == 0) log.info( "Migrating " + name + ":" );
{
log.info( format( "Store upgrade %d%% complete", percent ) ); return new ProgressSection();
}
} }


@Override @Override
public void finished() public void completed()
{
log.info( MESSAGE_COMPLETED );
}

private class ProgressSection implements Section
{ {
log.info( "Finished upgrade of database store files" ); private static final int STRIDE = 10;

private long current;
private int currentPercent;
private long max;

@Override
public void progress( long add )
{
current += add;
int percent = max == 0 ? 100 : (int) (current*100/max);
ensurePercentReported( percent );
}

private void ensurePercentReported( int percent )
{
while ( currentPercent < percent )
{
reportPercent( ++currentPercent );
}
}

private void reportPercent( int percent )
{
if ( percent % STRIDE == 0 )
{
log.info( format( " %d%% completed", percent ) );
}
}

@Override
public void start( long max )
{
this.max = max;
}

@Override
public void completed()
{
ensurePercentReported( 100 );
}
} }
} }
Expand Up @@ -31,30 +31,39 @@
* *
* @see org.neo4j.kernel.impl.storemigration.StoreUpgrader * @see org.neo4j.kernel.impl.storemigration.StoreUpgrader
*/ */
public class BaseStoreMigrationParticipant implements StoreMigrationParticipant public class AbstractStoreMigrationParticipant implements StoreMigrationParticipant
{ {
protected final String name;

public AbstractStoreMigrationParticipant( String name )
{
this.name = name;
}

@Override @Override
public void migrate( File storeDir, File migrationDir, MigrationProgressMonitor progressMonitor, public void migrate( File storeDir, File migrationDir, MigrationProgressMonitor.Section progressMonitor,
String versionToMigrateFrom ) throws IOException String versionToMigrateFrom ) throws IOException
{ {

} }


@Override @Override
public void moveMigratedFiles( File migrationDir, File storeDir, String versionToMigrateFrom ) throws IOException public void moveMigratedFiles( File migrationDir, File storeDir, String versionToMigrateFrom ) throws IOException
{ {

} }


@Override @Override
public void rebuildCounts( File storeDir, String versionToMigrateFrom ) throws IOException public void rebuildCounts( File storeDir, String versionToMigrateFrom ) throws IOException
{ {

} }


@Override @Override
public void cleanup( File migrationDir ) throws IOException public void cleanup( File migrationDir ) throws IOException
{ {
}


@Override
public String getName()
{
return name;
} }
} }

0 comments on commit 1c4f20c

Please sign in to comment.