Merge "Use backstop timeouts on asynchronous countdown during preflight" into nyc-dev

This commit is contained in:
Chris Tate
2016-05-26 22:32:44 +00:00
committed by Android (Google) Code Review

View File

@@ -146,6 +146,7 @@ import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
@@ -4664,7 +4665,7 @@ public class BackupManagerService {
// a standalone thread. The runner owns this half of the pipe, and closes // a standalone thread. The runner owns this half of the pipe, and closes
// it to indicate EOD to the other end. // it to indicate EOD to the other end.
class SinglePackageBackupPreflight implements BackupRestoreTask, FullBackupPreflight { class SinglePackageBackupPreflight implements BackupRestoreTask, FullBackupPreflight {
final AtomicLong mResult = new AtomicLong(); final AtomicLong mResult = new AtomicLong(BackupTransport.AGENT_ERROR);
final CountDownLatch mLatch = new CountDownLatch(1); final CountDownLatch mLatch = new CountDownLatch(1);
final IBackupTransport mTransport; final IBackupTransport mTransport;
@@ -4684,8 +4685,13 @@ public class BackupManagerService {
} }
agent.doMeasureFullBackup(token, mBackupManagerBinder); agent.doMeasureFullBackup(token, mBackupManagerBinder);
// now wait to get our result back // Now wait to get our result back. If this backstop timeout is reached without
mLatch.await(); // the latch being thrown, flow will continue as though a result or "normal"
// timeout had been produced. In case of a real backstop timeout, mResult
// will still contain the value it was constructed with, AGENT_ERROR, which
// intentionaly falls into the "just report failure" code.
mLatch.await(TIMEOUT_FULL_BACKUP_INTERVAL, TimeUnit.MILLISECONDS);
long totalSize = mResult.get(); long totalSize = mResult.get();
// If preflight timed out, mResult will contain error code as int. // If preflight timed out, mResult will contain error code as int.
if (totalSize < 0) { if (totalSize < 0) {
@@ -4738,7 +4744,7 @@ public class BackupManagerService {
@Override @Override
public long getExpectedSizeOrErrorCode() { public long getExpectedSizeOrErrorCode() {
try { try {
mLatch.await(); mLatch.await(TIMEOUT_FULL_BACKUP_INTERVAL, TimeUnit.MILLISECONDS);
return mResult.get(); return mResult.get();
} catch (InterruptedException e) { } catch (InterruptedException e) {
return BackupTransport.NO_MORE_DATA; return BackupTransport.NO_MORE_DATA;
@@ -4763,8 +4769,8 @@ public class BackupManagerService {
mPreflight = new SinglePackageBackupPreflight(transport); mPreflight = new SinglePackageBackupPreflight(transport);
mPreflightLatch = new CountDownLatch(1); mPreflightLatch = new CountDownLatch(1);
mBackupLatch = new CountDownLatch(1); mBackupLatch = new CountDownLatch(1);
mPreflightResult = BackupTransport.TRANSPORT_OK; mPreflightResult = BackupTransport.AGENT_ERROR;
mBackupResult = BackupTransport.TRANSPORT_OK; mBackupResult = BackupTransport.AGENT_ERROR;
} }
@Override @Override
@@ -4801,7 +4807,7 @@ public class BackupManagerService {
// otherwise return negative error code. // otherwise return negative error code.
long getPreflightResultBlocking() { long getPreflightResultBlocking() {
try { try {
mPreflightLatch.await(); mPreflightLatch.await(TIMEOUT_FULL_BACKUP_INTERVAL, TimeUnit.MILLISECONDS);
if (mPreflightResult == BackupTransport.TRANSPORT_OK) { if (mPreflightResult == BackupTransport.TRANSPORT_OK) {
return mPreflight.getExpectedSizeOrErrorCode(); return mPreflight.getExpectedSizeOrErrorCode();
} else { } else {
@@ -4814,7 +4820,7 @@ public class BackupManagerService {
int getBackupResultBlocking() { int getBackupResultBlocking() {
try { try {
mBackupLatch.await(); mBackupLatch.await(TIMEOUT_FULL_BACKUP_INTERVAL, TimeUnit.MILLISECONDS);
return mBackupResult; return mBackupResult;
} catch (InterruptedException e) { } catch (InterruptedException e) {
return BackupTransport.AGENT_ERROR; return BackupTransport.AGENT_ERROR;