Skip to content

Commit 76ef492

Browse files
committed
review changes
1 parent de34805 commit 76ef492

4 files changed

Lines changed: 83 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ public byte[] getPartData() {
6363
public byte[] getMd5() {
6464
return md5;
6565
}
66-
}
66+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ public Void retriableCall() throws AmazonClientException, BackupRestoreException
9797
"Picked up part {} size {}", dataPart.getPartNo(), dataPart.getPartData().length);
9898
return uploadPart();
9999
}
100-
}
100+
}

priam/src/main/java/com/netflix/priam/config/IConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,6 @@ default boolean skipMetaFileValidationOnRestore() {
11471147
* @return true to use reusable ByteBuffer implementation, false for legacy implementation
11481148
*/
11491149
default boolean useReusableBufferForMultipartUploads() {
1150-
return false;
1150+
return true;
11511151
}
11521152
}

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
import com.google.common.collect.Lists;
3030
import com.google.inject.Guice;
3131
import com.google.inject.Injector;
32+
import com.netflix.priam.aws.DataPart;
3233
import com.netflix.priam.aws.RemoteBackupPath;
3334
import com.netflix.priam.aws.S3FileSystem;
35+
import com.netflix.priam.aws.S3PartUploader;
3436
import com.netflix.priam.backup.AbstractBackupPath.BackupFileType;
3537
import com.netflix.priam.compress.CompressionType;
3638
import com.netflix.priam.config.IConfiguration;
@@ -80,6 +82,7 @@ public TestS3FileSystem() {
8082

8183
@BeforeClass
8284
public static void setUp() {
85+
new MockS3PartUploader();
8386
new MockAmazonS3Client();
8487
if (!DIR.exists()) DIR.mkdirs();
8588
}
@@ -115,6 +118,41 @@ public void testFileUploadDeleteExists() throws Exception {
115118
Assert.assertFalse(fs.checkObjectExists(Paths.get(backupfile.getRemotePath())));
116119
}
117120

121+
@Test
122+
public void testFileUploadFailures() throws Exception {
123+
MockS3PartUploader.setup();
124+
MockS3PartUploader.partFailure = true;
125+
long noOfFailures = backupMetrics.getInvalidUploads().count();
126+
S3FileSystem fs = injector.getInstance(S3FileSystem.class);
127+
RemoteBackupPath backupfile = injector.getInstance(RemoteBackupPath.class);
128+
backupfile.parseLocal(localFile(), BackupFileType.META_V2);
129+
try {
130+
// temporary hack to allow tests to complete in a timely fashion
131+
// This will be removed once we stop inheriting from AbstractFileSystem
132+
fs.uploadAndDeleteInternal(backupfile, Instant.EPOCH, 0 /* retries */);
133+
} catch (BackupRestoreException e) {
134+
// ignore
135+
}
136+
Assert.assertEquals(0, MockS3PartUploader.compattempts);
137+
Assert.assertEquals(1, backupMetrics.getInvalidUploads().count() - noOfFailures);
138+
}
139+
140+
@Test
141+
public void testFileUploadCompleteFailure() throws Exception {
142+
MockS3PartUploader.setup();
143+
MockS3PartUploader.completionFailure = true;
144+
S3FileSystem fs = injector.getInstance(S3FileSystem.class);
145+
fs.setS3Client(new MockAmazonS3Client().getMockInstance());
146+
RemoteBackupPath backupfile = injector.getInstance(RemoteBackupPath.class);
147+
backupfile.parseLocal(localFile(), BackupFileType.META_V2);
148+
try {
149+
// temporary hack to allow tests to complete in a timely fashion
150+
// This will be removed once we stop inheriting from AbstractFileSystem
151+
fs.uploadAndDeleteInternal(backupfile, Instant.EPOCH, 0 /* retries */);
152+
} catch (BackupRestoreException e) {
153+
// ignore
154+
}
155+
}
118156

119157
@Test
120158
public void testCleanupAdd() throws Exception {
@@ -251,6 +289,48 @@ private File localFile() throws IOException {
251289
return file;
252290
}
253291

292+
// Mock S3PartUploader class
293+
static class MockS3PartUploader extends MockUp<S3PartUploader> {
294+
static int compattempts = 0;
295+
static int partAttempts = 0;
296+
static boolean partFailure = false;
297+
static boolean completionFailure = false;
298+
private static List<PartETag> partETags;
299+
300+
@Mock
301+
public void $init(AmazonS3 client, DataPart dp, List<PartETag> partETags) {
302+
MockS3PartUploader.partETags = partETags;
303+
}
304+
305+
@Mock
306+
private Void uploadPart() throws AmazonClientException, BackupRestoreException {
307+
++partAttempts;
308+
if (partFailure) throw new BackupRestoreException("Test exception");
309+
partETags.add(new PartETag(0, null));
310+
return null;
311+
}
312+
313+
@Mock
314+
public CompleteMultipartUploadResult completeUpload() throws BackupRestoreException {
315+
++compattempts;
316+
if (completionFailure) throw new BackupRestoreException("Test exception");
317+
318+
return null;
319+
}
320+
321+
@Mock
322+
public Void retriableCall() throws AmazonClientException, BackupRestoreException {
323+
logger.info("MOCK UPLOADING...");
324+
return uploadPart();
325+
}
326+
327+
public static void setup() {
328+
compattempts = 0;
329+
partAttempts = 0;
330+
partFailure = false;
331+
completionFailure = false;
332+
}
333+
}
254334

255335
static class MockAmazonS3Client extends MockUp<AmazonS3Client> {
256336
private boolean ruleAvailable = false;

0 commit comments

Comments
 (0)