Skip to content

Commit

Permalink
Ensure DumpClusterState does not create files
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Aug 10, 2016
1 parent 226e533 commit d1f2d07
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Expand Up @@ -86,8 +86,11 @@ void dump() throws IOException
{
MemberIdStorage memberIdStorage = new MemberIdStorage( fs, clusterStateDirectory, CORE_MEMBER_ID_NAME,
new MemberIdMarshal(), NullLogProvider.getInstance() );
MemberId memberId = memberIdStorage.readState();
out.println( CORE_MEMBER_ID_NAME + ": " + memberId );
if ( memberIdStorage.exists() )
{
MemberId memberId = memberIdStorage.readState();
out.println( CORE_MEMBER_ID_NAME + ": " + memberId );
}

dumpState( LAST_FLUSHED_NAME, new LongIndexMarshal() );
dumpState( LOCK_TOKEN_NAME, new ReplicatedLockTokenState.Marshal( new MemberIdMarshal() ) );
Expand All @@ -105,9 +108,12 @@ private void dumpState( String name, StateMarshal<?> marshal ) throws IOExceptio
DurableStateStorage<?> storage = new DurableStateStorage<>(
fs, clusterStateDirectory, name, marshal, 1024, NullLogProvider.getInstance() );

try ( Lifespan ignored = new Lifespan( storage ) )
if ( storage.exists() )
{
out.println( name + ": " + storage.getInitialState() );
try ( Lifespan ignored = new Lifespan( storage ) )
{
out.println( name + ": " + storage.getInitialState() );
}
}
}
}
Expand Up @@ -63,6 +63,11 @@ public DurableStateStorage( FileSystemAbstraction fsa, File baseDir, String name
this.fileB = new File( parent, name + ".b" );
}

public boolean exists()
{
return fsa.fileExists( fileA ) && fsa.fileExists( fileB );
}

private void create() throws IOException
{
ensureExists( fileA );
Expand Down
Expand Up @@ -40,17 +40,23 @@ public class MemberIdStorage
private final File file;
private Log log;

public MemberIdStorage( FileSystemAbstraction fileSystem, File directory, String name, MemberId.MemberIdMarshal marshal, LogProvider logProvider )
public MemberIdStorage( FileSystemAbstraction fileSystem, File directory, String name,
MemberId.MemberIdMarshal marshal, LogProvider logProvider )
{
this.fileSystem = fileSystem;
this.log = logProvider.getLog( getClass() );
this.file = new File( DurableStateStorage.stateDir( directory, name ), name );
this.marshal = marshal;
}

public boolean exists()
{
return fileSystem.fileExists( file );
}

public MemberId readState() throws IOException
{
if ( fileSystem.fileExists( file ) )
if ( exists() )
{
try ( ReadableClosableChannel channel = new ReadAheadChannel<>( fileSystem.open( file, "r" ) ) )
{
Expand Down

0 comments on commit d1f2d07

Please sign in to comment.