Skip to content

Commit

Permalink
Restore from a dump does not restore some blobs #10761
Browse files Browse the repository at this point in the history
  • Loading branch information
rymsha committed Dec 16, 2024
1 parent 21c2a09 commit aa8db5d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ public class DumpServiceImpl
private static final List<RepositoryId> SYSTEM_REPO_IDS =
List.of( RepositoryId.from( "system.auditlog" ), RepositoryId.from( "system.scheduler" ) );

private BlobStore blobStore;
private final BlobStore blobStore;

private NodeService nodeService;
private final NodeService nodeService;

private RepositoryEntryService repositoryEntryService;
private final RepositoryEntryService repositoryEntryService;

private NodeRepositoryService nodeRepositoryService;
private final NodeRepositoryService nodeRepositoryService;

private NodeStorageService nodeStorageService;
private final NodeStorageService nodeStorageService;

private final EventPublisher eventPublisher;

Expand All @@ -100,9 +100,16 @@ public class DumpServiceImpl
private Path basePath = HomeDir.get().toPath().resolve( "data" ).resolve( "dump" );

@Activate
public DumpServiceImpl( @Reference EventPublisher eventPublisher )
public DumpServiceImpl( @Reference EventPublisher eventPublisher, @Reference BlobStore blobStore, @Reference NodeService nodeService,
@Reference RepositoryEntryService repositoryEntryService, @Reference NodeRepositoryService nodeRepositoryService,
@Reference NodeStorageService nodeStorageService )
{
this.xpVersion = VersionInfo.get().getVersion();
this.blobStore = blobStore;
this.nodeService = nodeService;
this.repositoryEntryService = repositoryEntryService;
this.nodeRepositoryService = nodeRepositoryService;
this.nodeStorageService = nodeStorageService;
this.eventPublisher = eventPublisher;
}

Expand Down Expand Up @@ -488,36 +495,6 @@ private void ensureBasePath()
}
}

@Reference
public void setNodeService( final NodeService nodeService )
{
this.nodeService = nodeService;
}

@Reference
public void setBlobStore( final BlobStore blobStore )
{
this.blobStore = blobStore;
}

@Reference
public void setRepositoryEntryService( final RepositoryEntryService repositoryEntryService )
{
this.repositoryEntryService = repositoryEntryService;
}

@Reference
public void setNodeRepositoryService( final NodeRepositoryService nodeRepositoryService )
{
this.nodeRepositoryService = nodeRepositoryService;
}

@Reference
public void setNodeStorageService( final NodeStorageService nodeStorageService )
{
this.nodeStorageService = nodeStorageService;
}

public void setBasePath( final Path basePath )
{
this.basePath = basePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import com.google.common.io.ByteSource;

import com.enonic.xp.blob.BlobKey;
import com.enonic.xp.blob.BlobRecord;
import com.enonic.xp.blob.BlobStore;
import com.enonic.xp.blob.Segment;
import com.enonic.xp.node.AttachedBinary;
Expand Down Expand Up @@ -43,24 +41,18 @@ class AbstractEntryProcessor
repositoryId = builder.repositoryId;
}

void validateOrAddBinary( final NodeVersion nodeVersion, final EntryLoadResult.Builder result )
void addBinary( final NodeVersion nodeVersion, final EntryLoadResult.Builder result )
{
final Segment segment = RepositorySegmentUtils.toSegment( repositoryId, NodeConstants.BINARY_SEGMENT_LEVEL );
nodeVersion.getAttachedBinaries().forEach( binary -> {

final Segment segment = RepositorySegmentUtils.toSegment( repositoryId, NodeConstants.BINARY_SEGMENT_LEVEL );
final BlobRecord existingRecord = this.blobStore.getRecord( segment, BlobKey.from( binary.getBlobKey() ) );

if ( existingRecord == null )
try
{
final ByteSource dumpBinary = this.dumpReader.getBinary( repositoryId, binary.getBlobKey() );
this.blobStore.addRecord( segment, dumpBinary );
}
catch ( RepoLoadException e )
{
try
{
final ByteSource dumpBinary = this.dumpReader.getBinary( repositoryId, binary.getBlobKey() );
this.blobStore.addRecord( segment, dumpBinary );
}
catch ( RepoLoadException e )
{
reportBinaryError( nodeVersion, result, binary, e );
}
reportBinaryError( nodeVersion, result, binary, e );
}
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void addNode( final EntryLoadResult.Builder result, final BranchDumpEntr
nodeCommitId( meta.getNodeCommitId() ).
build() );

validateOrAddBinary( nodeVersion, result );
addBinary( nodeVersion, result );

result.successful();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void addVersions( final EntryLoadResult.Builder result, final VersionsDu
nodeCommitId( version.getNodeCommitId() ).
build() );

validateOrAddBinary( nodeVersion, result );
addBinary( nodeVersion, result );
result.successful();
}
catch ( Exception e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,7 @@ public DumpServiceImplTest()
public void setUp()
throws Exception
{
this.dumpService = new DumpServiceImpl( eventPublisher );
this.dumpService.setBlobStore( BLOB_STORE );
this.dumpService.setNodeService( this.nodeService );
this.dumpService.setNodeRepositoryService( this.nodeRepositoryService );
this.dumpService.setNodeStorageService( this.storageService );
this.dumpService.setRepositoryEntryService( this.repositoryEntryService );
this.dumpService = new DumpServiceImpl( eventPublisher, BLOB_STORE, this.nodeService , this.repositoryEntryService, this.nodeRepositoryService, this.storageService );
this.dumpService.setBasePath( temporaryFolder );
}

Expand Down

0 comments on commit aa8db5d

Please sign in to comment.