use of org.apache.asterix.replication.functions.ReplicaFilesRequest in project asterixdb by apache.
the class ReplicationManager method requestReplicaFiles.
//Recovery Method
@Override
public void requestReplicaFiles(String selectedReplicaId, Set<Integer> partitionsToRecover, Set<String> existingFiles) throws IOException {
ReplicaFilesRequest request = new ReplicaFilesRequest(partitionsToRecover, existingFiles);
dataBuffer = ReplicationProtocol.writeGetReplicaFilesRequest(dataBuffer, request);
try (SocketChannel socketChannel = getReplicaSocket(selectedReplicaId)) {
//transfer request
NetworkingUtil.transferBufferToChannel(socketChannel, dataBuffer);
String indexPath;
String destFilePath;
ReplicationRequestType responseFunction = ReplicationProtocol.getRequestType(socketChannel, dataBuffer);
LSMIndexFileProperties fileProperties;
while (responseFunction != ReplicationRequestType.GOODBYE) {
dataBuffer = ReplicationProtocol.readRequest(socketChannel, dataBuffer);
fileProperties = ReplicationProtocol.readFileReplicationRequest(dataBuffer);
//get index path
indexPath = replicaResourcesManager.getIndexPath(fileProperties);
destFilePath = indexPath + File.separator + fileProperties.getFileName();
//create file
File destFile = new File(destFilePath);
destFile.createNewFile();
try (RandomAccessFile fileOutputStream = new RandomAccessFile(destFile, "rw");
FileChannel fileChannel = fileOutputStream.getChannel()) {
fileOutputStream.setLength(fileProperties.getFileSize());
NetworkingUtil.downloadFile(fileChannel, socketChannel);
fileChannel.force(true);
}
//we need to create LSN map for .metadata files that belong to remote replicas
if (!fileProperties.isLSMComponentFile() && !fileProperties.getNodeId().equals(nodeId)) {
//replica index
replicaResourcesManager.initializeReplicaIndexLSNMap(indexPath, logManager.getAppendLSN());
}
responseFunction = ReplicationProtocol.getRequestType(socketChannel, dataBuffer);
}
//send goodbye
ReplicationProtocol.sendGoodbye(socketChannel);
}
}
Aggregations