Skip to content

Commit aac2dbc

Browse files
[JIRA-ODS-1624] Preliminary commits in advance of switching to a supported S3 SDK (#1120)
* Prelim commit - Removing all references to backup file system cleanup and lifecycle config * Addressing comments * Minor change, adding another clear test call
1 parent cebfeff commit aac2dbc

7 files changed

Lines changed: 5 additions & 167 deletions

File tree

priam/src/main/java/com/netflix/priam/aws/S3FileSystemBase.java

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -99,119 +99,6 @@ public void setS3Client(AmazonS3 client) {
9999
s3Client = client;
100100
}
101101

102-
@Override
103-
public void cleanup() {
104-
105-
AmazonS3 s3Client = getS3Client();
106-
String clusterPath = pathProvider.get().clusterPrefix("");
107-
logger.debug("Bucket: {}", config.getBackupPrefix());
108-
BucketLifecycleConfiguration lifeConfig =
109-
s3Client.getBucketLifecycleConfiguration(config.getBackupPrefix());
110-
logger.debug("Got bucket:{} lifecycle.{}", config.getBackupPrefix(), lifeConfig);
111-
if (lifeConfig == null) {
112-
lifeConfig = new BucketLifecycleConfiguration();
113-
List<Rule> rules = Lists.newArrayList();
114-
lifeConfig.setRules(rules);
115-
}
116-
117-
List<Rule> rules = lifeConfig.getRules();
118-
119-
if (updateLifecycleRule(config, rules, clusterPath)) {
120-
if (rules.size() > 0) {
121-
lifeConfig.setRules(rules);
122-
s3Client.setBucketLifecycleConfiguration(config.getBackupPrefix(), lifeConfig);
123-
} else s3Client.deleteBucketLifecycleConfiguration(config.getBackupPrefix());
124-
}
125-
}
126-
127-
// Dummy class to get Prefix. - Why oh why AWS you can't give the details!!
128-
private class PrefixVisitor implements LifecyclePredicateVisitor {
129-
String prefix;
130-
131-
@Override
132-
public void visit(LifecyclePrefixPredicate lifecyclePrefixPredicate) {
133-
prefix = lifecyclePrefixPredicate.getPrefix();
134-
}
135-
136-
@Override
137-
public void visit(LifecycleTagPredicate lifecycleTagPredicate) {}
138-
139-
@Override
140-
public void visit(
141-
LifecycleObjectSizeGreaterThanPredicate lifecycleObjectSizeGreaterThanPredicate) {}
142-
143-
@Override
144-
public void visit(LifecycleAndOperator lifecycleAndOperator) {}
145-
146-
@Override
147-
public void visit(
148-
LifecycleObjectSizeLessThanPredicate lifecycleObjectSizeLessThanPredicate) {}
149-
}
150-
151-
private Optional<Rule> getBucketLifecycleRule(List<Rule> rules, String prefix) {
152-
if (rules == null || rules.isEmpty()) return Optional.empty();
153-
154-
for (Rule rule : rules) {
155-
String rulePrefix = "";
156-
if (rule.getFilter() != null) {
157-
PrefixVisitor prefixVisitor = new PrefixVisitor();
158-
rule.getFilter().getPredicate().accept(prefixVisitor);
159-
rulePrefix = prefixVisitor.prefix;
160-
} else if (rule.getPrefix() != null) {
161-
// Being backwards compatible, here.
162-
rulePrefix = rule.getPrefix();
163-
}
164-
if (prefix.equalsIgnoreCase(rulePrefix)) {
165-
return Optional.of(rule);
166-
}
167-
}
168-
169-
return Optional.empty();
170-
}
171-
172-
private boolean updateLifecycleRule(IConfiguration config, List<Rule> rules, String prefix) {
173-
Optional<Rule> rule = getBucketLifecycleRule(rules, prefix);
174-
// No need to update the rule as it never existed and retention is not set.
175-
if (!rule.isPresent() && config.getBackupRetentionDays() <= 0) return false;
176-
177-
// Rule not required as retention days is zero or negative.
178-
if (rule.isPresent() && config.getBackupRetentionDays() <= 0) {
179-
logger.warn(
180-
"Removing the rule for backup retention on prefix: {} as retention is set to [{}] days. Only positive values are supported by S3!!",
181-
prefix,
182-
config.getBackupRetentionDays());
183-
rules.remove(rule.get());
184-
return true;
185-
}
186-
187-
// Rule present and is current.
188-
if (rule.isPresent()
189-
&& rule.get().getExpirationInDays() == config.getBackupRetentionDays()
190-
&& rule.get().getStatus().equalsIgnoreCase(BucketLifecycleConfiguration.ENABLED)) {
191-
logger.info(
192-
"Cleanup rule already set on prefix: {} with retention period: [{}] days",
193-
prefix,
194-
config.getBackupRetentionDays());
195-
return false;
196-
}
197-
198-
if (!rule.isPresent()) {
199-
// Create a new rule
200-
rule = Optional.of(new BucketLifecycleConfiguration.Rule());
201-
rules.add(rule.get());
202-
}
203-
204-
rule.get().setStatus(BucketLifecycleConfiguration.ENABLED);
205-
rule.get().setExpirationInDays(config.getBackupRetentionDays());
206-
rule.get().setFilter(new LifecycleFilter(new LifecyclePrefixPredicate(prefix)));
207-
rule.get().setId(prefix);
208-
logger.info(
209-
"Setting cleanup rule for prefix: {} with retention period: [{}] days",
210-
prefix,
211-
config.getBackupRetentionDays());
212-
return true;
213-
}
214-
215102
void checkSuccessfulUpload(
216103
CompleteMultipartUploadResult resultS3MultiPartUploadComplete, Path localPath)
217104
throws BackupRestoreException {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ default String getShard() {
120120
*/
121121
Iterator<String> listFileSystem(String prefix, String delimiter, String marker);
122122

123-
/** Runs cleanup or set retention */
124-
void cleanup();
125-
126123
/** Give the file system a chance to terminate any thread pools, etc. */
127124
void shutdown();
128125

priam/src/test/java/com/netflix/priam/backup/FakeBackupFileSystem.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void setupTest(List<String> files) {
5757
}
5858
}
5959

60-
private void clearTest() {
60+
public void clearTest() {
6161
flist.clear();
6262
downloadedFiles.clear();
6363
uploadedFiles.clear();
@@ -111,11 +111,6 @@ public void deleteFiles(List<Path> remotePaths) throws BackupRestoreException {
111111
});
112112
}
113113

114-
@Override
115-
public void cleanup() {
116-
clearTest();
117-
}
118-
119114
@Override
120115
protected void downloadFileImpl(AbstractBackupPath path, String suffix)
121116
throws BackupRestoreException {

priam/src/test/java/com/netflix/priam/backup/NullBackupFileSystem.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ public Iterator<String> listFileSystem(String prefix, String delimiter, String m
5858
return Collections.emptyIterator();
5959
}
6060

61-
@Override
62-
public void cleanup() {
63-
// TODO Auto-generated method stub
64-
}
65-
6661
@Override
6762
protected void downloadFileImpl(AbstractBackupPath path, String suffix)
6863
throws BackupRestoreException {}

priam/src/test/java/com/netflix/priam/backup/TestBackup.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static void cleanup() throws IOException {
7070

7171
@Test
7272
public void testIncrementalBackup() throws Exception {
73-
filesystem.cleanup();
73+
filesystem.clearTest();
7474
generateIncrementalFiles();
7575
IncrementalBackup backup = injector.getInstance(IncrementalBackup.class);
7676
backup.execute();
@@ -85,7 +85,7 @@ public void testIncrementalBackup() throws Exception {
8585

8686
@Test
8787
public void testIncrementalBackupOfSecondaryIndexes() throws Exception {
88-
filesystem.cleanup();
88+
filesystem.clearTest();
8989
generateIncrementalFiles();
9090
IncrementalBackup backup = injector.getInstance(IncrementalBackup.class);
9191
File secondaryIndexBackupDir =
@@ -121,7 +121,7 @@ public void testClusterSpecificColumnFamiliesSkippedFrom21() throws Exception {
121121

122122
private void testClusterSpecificColumnFamiliesSkipped(String[] columnFamilyDirs)
123123
throws Exception {
124-
filesystem.cleanup();
124+
filesystem.clearTest();
125125
File tmp = new File("target/data/");
126126
if (tmp.exists()) cleanup(tmp);
127127
// Generate "data"

priam/src/test/java/com/netflix/priam/backup/TestS3FileSystem.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -154,42 +154,6 @@ public void testFileUploadCompleteFailure() throws Exception {
154154
}
155155
}
156156

157-
@Test
158-
public void testCleanupAdd() throws Exception {
159-
MockAmazonS3Client.setRuleAvailable(false);
160-
S3FileSystem fs = injector.getInstance(S3FileSystem.class);
161-
fs.cleanup();
162-
Assert.assertEquals(1, MockAmazonS3Client.bconf.getRules().size());
163-
BucketLifecycleConfiguration.Rule rule = MockAmazonS3Client.bconf.getRules().get(0);
164-
Assert.assertEquals("casstestbackup/" + region + "/fake-app/", rule.getId());
165-
Assert.assertEquals(configuration.getBackupRetentionDays(), rule.getExpirationInDays());
166-
}
167-
168-
@Test
169-
public void testCleanupIgnore() throws Exception {
170-
MockAmazonS3Client.setRuleAvailable(true);
171-
S3FileSystem fs = injector.getInstance(S3FileSystem.class);
172-
fs.cleanup();
173-
Assert.assertEquals(1, MockAmazonS3Client.bconf.getRules().size());
174-
BucketLifecycleConfiguration.Rule rule = MockAmazonS3Client.bconf.getRules().get(0);
175-
Assert.assertEquals("casstestbackup/" + region + "/fake-app/", rule.getId());
176-
Assert.assertEquals(configuration.getBackupRetentionDays(), rule.getExpirationInDays());
177-
}
178-
179-
@Test
180-
public void testCleanupUpdate() throws Exception {
181-
MockAmazonS3Client.setRuleAvailable(true);
182-
S3FileSystem fs = injector.getInstance(S3FileSystem.class);
183-
String clusterPrefix = "casstestbackup/" + region + "/fake-app/";
184-
MockAmazonS3Client.updateRule(
185-
MockAmazonS3Client.getBucketLifecycleConfig(clusterPrefix, 2));
186-
fs.cleanup();
187-
Assert.assertEquals(1, MockAmazonS3Client.bconf.getRules().size());
188-
BucketLifecycleConfiguration.Rule rule = MockAmazonS3Client.bconf.getRules().get(0);
189-
Assert.assertEquals("casstestbackup/" + region + "/fake-app/", rule.getId());
190-
Assert.assertEquals(configuration.getBackupRetentionDays(), rule.getExpirationInDays());
191-
}
192-
193157
@Test
194158
public void testDeleteObjects() throws Exception {
195159
S3FileSystem fs = injector.getInstance(S3FileSystem.class);

priam/src/test/java/com/netflix/priam/backupv2/TestBackupTTLTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private String getRemoteFromLocal(String localPath) throws ParseException {
139139
@After
140140
public void cleanup() {
141141
BackupFileUtils.cleanupDir(Paths.get(configuration.getDataFileLocation()));
142-
backupFileSystem.cleanup();
142+
backupFileSystem.clearTest();
143143
}
144144

145145
private List<String> getAllFiles() {

0 commit comments

Comments
 (0)