Skip to content

Commit

Permalink
Change IMetaProxy API to return an ImmutableList of AbstractBackupPat…
Browse files Browse the repository at this point in the history
…hs when fetching incrementals. The iterators are always fully materialized. Also, remove the now-redundant method from BackupRestoreUtil that merely wrapped the MetaProxy call.
  • Loading branch information
mattl-netflix committed May 4, 2024
1 parent 5539ebe commit c1b751f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,6 @@ public static List<AbstractBackupPath> getMostRecentSnapshotPaths(
return snapshotPaths;
}

public static List<AbstractBackupPath> getIncrementalPaths(
AbstractBackupPath latestValidMetaFile,
DateUtil.DateRange dateRange,
IMetaProxy metaProxy) {
Instant snapshotTime;
snapshotTime = latestValidMetaFile.getLastModified();
DateUtil.DateRange incrementalDateRange =
new DateUtil.DateRange(snapshotTime, dateRange.getEndTime());
List<AbstractBackupPath> incrementalPaths = new ArrayList<>();
metaProxy.getIncrementals(incrementalDateRange).forEachRemaining(incrementalPaths::add);
return incrementalPaths;
}

public static Map<String, List<String>> getFilter(String inputFilter)
throws IllegalArgumentException {
if (StringUtils.isEmpty(inputFilter)) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.netflix.priam.backupv2;

import com.google.common.collect.ImmutableList;
import com.netflix.priam.backup.AbstractBackupPath;
import com.netflix.priam.backup.BackupRestoreException;
import com.netflix.priam.backup.BackupVerificationResult;
Expand Down Expand Up @@ -78,7 +79,7 @@ public interface IMetaProxy {
* @param dateRange the time period to scan in the remote file system for incremental files.
* @return iterator containing the list of path on the remote file system satisfying criteria.
*/
Iterator<AbstractBackupPath> getIncrementals(DateUtil.DateRange dateRange);
ImmutableList<AbstractBackupPath> getIncrementals(DateUtil.DateRange dateRange);

/**
* Validate that all the files mentioned in the meta file actually exists on remote file system.
Expand Down
24 changes: 11 additions & 13 deletions priam/src/main/java/com/netflix/priam/backupv2/MetaV2Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.netflix.priam.backupv2;

import com.google.common.collect.ImmutableList;
import com.netflix.priam.backup.AbstractBackupPath;
import com.netflix.priam.backup.BackupRestoreException;
import com.netflix.priam.backup.BackupVerificationResult;
Expand Down Expand Up @@ -85,7 +86,7 @@ private String getMatch(
}

@Override
public Iterator<AbstractBackupPath> getIncrementals(DateUtil.DateRange dateRange) {
public ImmutableList<AbstractBackupPath> getIncrementals(DateUtil.DateRange dateRange) {
String incrementalPrefix = getMatch(dateRange, AbstractBackupPath.BackupFileType.SST_V2);
String marker =
getMatch(
Expand All @@ -97,18 +98,15 @@ public Iterator<AbstractBackupPath> getIncrementals(DateUtil.DateRange dateRange
marker,
dateRange);
Iterator<String> iterator = fs.listFileSystem(incrementalPrefix, null, marker);
Iterator<AbstractBackupPath> transformIterator =
new TransformIterator<>(
iterator,
s -> {
AbstractBackupPath path = abstractBackupPathProvider.get();
path.parseRemote(s);
return path;
});

return new FilterIterator<>(
transformIterator,
abstractBackupPath -> dateRange.contains(abstractBackupPath.getLastModified()));
ImmutableList.Builder<AbstractBackupPath> results = ImmutableList.builder();
while (iterator.hasNext()) {
AbstractBackupPath path = abstractBackupPathProvider.get();
path.parseRemote(iterator.next());
if (dateRange.contains(path.getLastModified())) {
results.add(path);
}
}
return results.build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,18 @@ public Response validateV2SnapshotByDate(
@Path("/list/{daterange}")
public Response list(@PathParam("daterange") String daterange) throws Exception {
DateUtil.DateRange dateRange = new DateUtil.DateRange(daterange);
// Find latest valid meta file.
Optional<AbstractBackupPath> latestValidMetaFile =
Optional<AbstractBackupPath> metaFile =
BackupRestoreUtil.getLatestValidMetaPath(metaProxy, dateRange);
if (!latestValidMetaFile.isPresent()) {
if (!metaFile.isPresent()) {
return Response.ok("No valid meta found!").build();
}
List<AbstractBackupPath> allFiles =
BackupRestoreUtil.getMostRecentSnapshotPaths(
latestValidMetaFile.get(), metaProxy, pathProvider);
allFiles.addAll(
BackupRestoreUtil.getIncrementalPaths(
latestValidMetaFile.get(), dateRange, metaProxy));

return Response.ok(
GsonJsonSerializer.getGson()
.toJson(
allFiles.stream()
.map(AbstractBackupPath::getRemotePath)
.collect(Collectors.toList())))
.build();
List<AbstractBackupPath> files =
BackupRestoreUtil.getMostRecentSnapshotPaths(metaFile.get(), metaProxy, pathProvider);
DateUtil.DateRange incrementalDateRange =
new DateRange(metaFile.get().getLastModified(), dateRange.getEndTime());
files.addAll(metaProxy.getIncrementals(incrementalDateRange));
List<String> remotePaths =
files.stream().map(AbstractBackupPath::getRemotePath).collect(Collectors.toList());
return Response.ok(GsonJsonSerializer.getGson().toJson(remotePaths)).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ public void restore(DateUtil.DateRange dateRange) throws Exception {
BackupRestoreUtil.getMostRecentSnapshotPaths(
latestValidMetaFile.get(), metaProxy, pathProvider);
if (!config.skipIncrementalRestore()) {
allFiles.addAll(
BackupRestoreUtil.getIncrementalPaths(
latestValidMetaFile.get(), dateRange, metaProxy));
DateUtil.DateRange incrementalDateRange =
new DateUtil.DateRange(
latestValidMetaFile.get().getLastModified(), dateRange.getEndTime());
allFiles.addAll(metaProxy.getIncrementals(incrementalDateRange));
}

// Download snapshot which is listed in the meta file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package com.netflix.priam.backupv2;

import com.google.common.collect.ImmutableList;
import com.google.common.truth.Truth;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.netflix.priam.backup.AbstractBackupPath;
Expand Down Expand Up @@ -131,13 +133,7 @@ public void testGetSSTFilesFromMeta() throws Exception {
@Test
public void testGetIncrementalFiles() throws Exception {
DateUtil.DateRange dateRange = new DateUtil.DateRange("202812071820,20281229");
Iterator<AbstractBackupPath> incrementals = metaProxy.getIncrementals(dateRange);
int i = 0;
while (incrementals.hasNext()) {
System.out.println(incrementals.next());
i++;
}
Assert.assertEquals(3, i);
Truth.assertThat(metaProxy.getIncrementals(dateRange)).hasSize(3);
}

@Test
Expand Down

0 comments on commit c1b751f

Please sign in to comment.