Skip to content

Commit 4c25e6d

Browse files
Warmup objectCache with the latest validated snapshot files to reduce HEAD requests to AWS (#1118)
* add interface for enableSynchronizingDroppedColumns * Revert "add interface for enableSynchronizingDroppedColumns" This reverts commit 6d54ae4. * Warmup objectCache with the latest validated snapshot files to reduce HEAD requests to AWS * PR comments
1 parent c230216 commit 4c25e6d

File tree

7 files changed

+50
-8
lines changed

7 files changed

+50
-8
lines changed

priam/src/main/java/com/netflix/priam/backup/AbstractFileSystem.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.common.util.concurrent.ListeningExecutorService;
2727
import com.google.common.util.concurrent.MoreExecutors;
2828
import com.netflix.priam.backup.AbstractBackupPath.BackupFileType;
29+
import com.netflix.priam.backupv2.IMetaProxy;
2930
import com.netflix.priam.config.IConfiguration;
3031
import com.netflix.priam.merics.BackupMetrics;
3132
import com.netflix.priam.notification.BackupNotificationMgr;
@@ -37,10 +38,7 @@
3738
import java.nio.file.Path;
3839
import java.nio.file.Paths;
3940
import java.time.Instant;
40-
import java.util.Date;
41-
import java.util.Iterator;
42-
import java.util.List;
43-
import java.util.Set;
41+
import java.util.*;
4442
import java.util.concurrent.*;
4543
import javax.inject.Inject;
4644
import javax.inject.Provider;
@@ -236,10 +234,12 @@ public Long retriableCall() throws Exception {
236234
return path;
237235
}
238236

239-
private void addObjectCache(Path remotePath) {
237+
@Override
238+
public void addObjectCache(Path remotePath) {
240239
objectCache.put(remotePath, Boolean.TRUE);
241240
}
242241

242+
243243
@Override
244244
public boolean checkObjectExists(Path remotePath) {
245245
// Check in cache, if remote file exists.

priam/src/main/java/com/netflix/priam/backup/BackupHelper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.google.common.collect.ImmutableSet;
55
import com.google.common.util.concurrent.ListenableFuture;
66
import com.google.inject.ImplementedBy;
7+
import com.netflix.priam.backupv2.IMetaProxy;
8+
import com.netflix.priam.backup.IBackupStatusMgr;
9+
710
import java.io.File;
811
import java.io.IOException;
912
import java.time.Instant;
@@ -26,4 +29,6 @@ ImmutableList<ListenableFuture<AbstractBackupPath>> uploadAndDeleteAllFiles(
2629

2730
ImmutableSet<AbstractBackupPath> getBackupPaths(
2831
File dir, AbstractBackupPath.BackupFileType type) throws IOException;
29-
}
32+
33+
void warmupCache(IMetaProxy metaProxy, IBackupStatusMgr snapshotStatusMgr) throws Exception;
34+
}

priam/src/main/java/com/netflix/priam/backup/BackupHelperImpl.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55
import com.google.common.collect.ImmutableList;
66
import com.google.common.collect.ImmutableSet;
77
import com.google.common.util.concurrent.ListenableFuture;
8+
import com.netflix.priam.backupv2.IMetaProxy;
89
import com.netflix.priam.compress.CompressionType;
910
import com.netflix.priam.config.BackupsToCompress;
1011
import com.netflix.priam.config.IConfiguration;
12+
import com.netflix.priam.utils.DateUtil;
13+
1114
import java.io.File;
1215
import java.io.IOException;
1316
import java.nio.file.Files;
1417
import java.nio.file.Path;
18+
import java.nio.file.Paths;
1519
import java.time.Instant;
20+
import java.time.temporal.ChronoUnit;
21+
import java.util.Comparator;
22+
import java.util.Optional;
1623
import java.util.Set;
1724
import java.util.stream.Stream;
1825
import javax.inject.Inject;
@@ -84,6 +91,25 @@ public ImmutableSet<AbstractBackupPath> getBackupPaths(
8491
return bps.build();
8592
}
8693

94+
@Override
95+
public void warmupCache(IMetaProxy metaProxy, IBackupStatusMgr snapshotStatusMgr) throws Exception {
96+
Instant now = Instant.now();
97+
DateUtil.DateRange dateRange = new DateUtil.DateRange(now.minus(1, ChronoUnit.DAYS), now);
98+
Optional<String> snapshotLocation = snapshotStatusMgr.getLatestBackupMetadata(dateRange)
99+
.stream()
100+
.filter(backupMetadata -> backupMetadata.getLastValidated() != null)
101+
.max(Comparator.comparing(BackupMetadata::getStart))
102+
.map(BackupMetadata::getSnapshotLocation);
103+
if (snapshotLocation.isPresent()) {
104+
AbstractBackupPath backupPath = pathFactory.get();
105+
backupPath.parseRemote(snapshotLocation.get());
106+
BackupRestoreUtil.getMostRecentSnapshotPaths(backupPath, metaProxy, pathFactory)
107+
.stream()
108+
.map(abp -> Paths.get(abp.getRemotePath()))
109+
.forEach(fs::addObjectCache);
110+
}
111+
}
112+
87113
private CompressionType getCorrectCompressionAlgorithm(
88114
AbstractBackupPath path, Set<String> compressedFiles) {
89115
if (path.getLastModified().toEpochMilli() < config.getCompressionTransitionEpochMillis()) {

priam/src/main/java/com/netflix/priam/backup/IBackupFileSystem.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,7 @@ default boolean checkObjectExists(Path remotePath) {
172172

173173
/** Clear the cache for the backup file system, if any. */
174174
void clearCache();
175+
176+
/** Add remote backup path to the object cache*/
177+
void addObjectCache(Path remotePath);
175178
}

priam/src/main/java/com/netflix/priam/backupv2/BackupV2Service.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public void scheduleService() throws Exception {
6464
if (snapshotMetaTimer == null) {
6565
SnapshotMetaTask.cleanOldBackups(configuration);
6666
}
67+
68+
// Warm up object cache
69+
snapshotMetaTask.warmCache();
70+
6771
scheduleTask(scheduler, SnapshotMetaTask.class, snapshotMetaTimer);
6872

6973
if (snapshotMetaTimer != null) {

priam/src/main/java/com/netflix/priam/backupv2/SnapshotMetaTask.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ public String getName() {
255255
return JOBNAME;
256256
}
257257

258+
public void warmCache() throws Exception {
259+
backupHelper.warmupCache(metaProxy, snapshotStatusMgr);
260+
}
261+
258262
private void uploadAllFiles(final File backupDir) throws Exception {
259263
// Process all the snapshots with SNAPSHOT_PREFIX. This will ensure that we "resume" the
260264
// uploads of previous snapshot leftover as Priam restarted or any failure for any reason

priam/src/test/groovy/com.netflix.priam/backup/TestBackupRestoreUtil.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class TestBackupRestoreUtil extends Specification {
5959
}
6060

6161

62-
def "Expected exception KS #keyspace and CF #columnfamily with configuration include #configIncludeFilter and exclude #configExcludeFilter"() {
62+
def "Expected exception for shouldOmitFromBackup KS #keyspace and CF #columnfamily with configuration include #configIncludeFilter and exclude #configExcludeFilter"() {
6363
when:
6464
new BackupRestoreUtil(configIncludeFilter, configExcludeFilter).shouldOmitFromBackup(keyspace, columnfamily)
6565

@@ -106,7 +106,7 @@ class TestBackupRestoreUtil extends Specification {
106106
null | null | "system" | "peers_v2" || true
107107
}
108108

109-
def "Expected exception KS #keyspace and CF #columnfamily with configuration include #configIncludeFilter and exclude #configExcludeFilter"() {
109+
def "Expected exception for shouldOmitFromRestore KS #keyspace and CF #columnfamily with configuration include #configIncludeFilter and exclude #configExcludeFilter"() {
110110
when:
111111
new BackupRestoreUtil(configIncludeFilter, configExcludeFilter).shouldOmitFromRestore(keyspace, columnfamily)
112112

0 commit comments

Comments
 (0)