Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0a7d0264 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Automerger Merge Worker
Browse files

Merge "Delay deleting the blob after the last lease is released." into rvc-dev...

Merge "Delay deleting the blob after the last lease is released." into rvc-dev am: a019160b am: 8b8132c5 am: 52344d25 am: d2083ea1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11936459

Change-Id: I86cc082f0a87bfc6286eb09bc1ca0cc875afdc09
parents aac27595 d2083ea1
Loading
Loading
Loading
Loading
+24 −0
Original line number Original line Diff line number Diff line
@@ -131,6 +131,16 @@ class BlobStoreConfig {
        public static boolean USE_REVOCABLE_FD_FOR_READS =
        public static boolean USE_REVOCABLE_FD_FOR_READS =
                DEFAULT_USE_REVOCABLE_FD_FOR_READS;
                DEFAULT_USE_REVOCABLE_FD_FOR_READS;


        /**
         * Denotes how long before a blob is deleted, once the last lease on it is released.
         */
        public static final String KEY_DELETE_ON_LAST_LEASE_DELAY_MS =
                "delete_on_last_lease_delay_ms";
        public static final long DEFAULT_DELETE_ON_LAST_LEASE_DELAY_MS =
                TimeUnit.HOURS.toMillis(6);
        public static long DELETE_ON_LAST_LEASE_DELAY_MS =
                DEFAULT_DELETE_ON_LAST_LEASE_DELAY_MS;

        static void refresh(Properties properties) {
        static void refresh(Properties properties) {
            if (!NAMESPACE_BLOBSTORE.equals(properties.getNamespace())) {
            if (!NAMESPACE_BLOBSTORE.equals(properties.getNamespace())) {
                return;
                return;
@@ -164,6 +174,10 @@ class BlobStoreConfig {
                        USE_REVOCABLE_FD_FOR_READS = properties.getBoolean(key,
                        USE_REVOCABLE_FD_FOR_READS = properties.getBoolean(key,
                                DEFAULT_USE_REVOCABLE_FD_FOR_READS);
                                DEFAULT_USE_REVOCABLE_FD_FOR_READS);
                        break;
                        break;
                    case KEY_DELETE_ON_LAST_LEASE_DELAY_MS:
                        DELETE_ON_LAST_LEASE_DELAY_MS = properties.getLong(key,
                                DEFAULT_DELETE_ON_LAST_LEASE_DELAY_MS);
                        break;
                    default:
                    default:
                        Slog.wtf(TAG, "Unknown key in device config properties: " + key);
                        Slog.wtf(TAG, "Unknown key in device config properties: " + key);
                }
                }
@@ -193,6 +207,9 @@ class BlobStoreConfig {
                    TimeUtils.formatDuration(DEFAULT_COMMIT_COOL_OFF_DURATION_MS)));
                    TimeUtils.formatDuration(DEFAULT_COMMIT_COOL_OFF_DURATION_MS)));
            fout.println(String.format(dumpFormat, KEY_USE_REVOCABLE_FD_FOR_READS,
            fout.println(String.format(dumpFormat, KEY_USE_REVOCABLE_FD_FOR_READS,
                    USE_REVOCABLE_FD_FOR_READS, DEFAULT_USE_REVOCABLE_FD_FOR_READS));
                    USE_REVOCABLE_FD_FOR_READS, DEFAULT_USE_REVOCABLE_FD_FOR_READS));
            fout.println(String.format(dumpFormat, KEY_DELETE_ON_LAST_LEASE_DELAY_MS,
                    TimeUtils.formatDuration(DELETE_ON_LAST_LEASE_DELAY_MS),
                    TimeUtils.formatDuration(DEFAULT_DELETE_ON_LAST_LEASE_DELAY_MS)));
        }
        }
    }
    }


@@ -264,6 +281,13 @@ class BlobStoreConfig {
        return DeviceConfigProperties.USE_REVOCABLE_FD_FOR_READS;
        return DeviceConfigProperties.USE_REVOCABLE_FD_FOR_READS;
    }
    }


    /**
     * Returns the duration to wait before a blob is deleted, once the last lease on it is released.
     */
    public static long getDeletionOnLastLeaseDelayMs() {
        return DeviceConfigProperties.DELETE_ON_LAST_LEASE_DELAY_MS;
    }

    @Nullable
    @Nullable
    public static File prepareBlobFile(long sessionId) {
    public static File prepareBlobFile(long sessionId) {
        final File blobsDir = prepareBlobsDir();
        final File blobsDir = prepareBlobsDir();
+16 −3
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ import static com.android.server.blob.BlobStoreConfig.LOGV;
import static com.android.server.blob.BlobStoreConfig.TAG;
import static com.android.server.blob.BlobStoreConfig.TAG;
import static com.android.server.blob.BlobStoreConfig.XML_VERSION_CURRENT;
import static com.android.server.blob.BlobStoreConfig.XML_VERSION_CURRENT;
import static com.android.server.blob.BlobStoreConfig.getAdjustedCommitTimeMs;
import static com.android.server.blob.BlobStoreConfig.getAdjustedCommitTimeMs;
import static com.android.server.blob.BlobStoreConfig.getDeletionOnLastLeaseDelayMs;
import static com.android.server.blob.BlobStoreSession.STATE_ABANDONED;
import static com.android.server.blob.BlobStoreSession.STATE_ABANDONED;
import static com.android.server.blob.BlobStoreSession.STATE_COMMITTED;
import static com.android.server.blob.BlobStoreSession.STATE_COMMITTED;
import static com.android.server.blob.BlobStoreSession.STATE_VERIFIED_INVALID;
import static com.android.server.blob.BlobStoreSession.STATE_VERIFIED_INVALID;
@@ -488,12 +489,24 @@ public class BlobStoreManagerService extends SystemService {
                Slog.v(TAG, "Released lease on " + blobHandle
                Slog.v(TAG, "Released lease on " + blobHandle
                        + "; callingUid=" + callingUid + ", callingPackage=" + callingPackage);
                        + "; callingUid=" + callingUid + ", callingPackage=" + callingPackage);
            }
            }
            if (!blobMetadata.hasLeases()) {
                mHandler.postDelayed(() -> {
                    synchronized (mBlobsLock) {
                        // Check if blobMetadata object is still valid. If it is not, then
                        // it means that it was already deleted and nothing else to do here.
                        if (!Objects.equals(userBlobs.get(blobHandle), blobMetadata)) {
                            return;
                        }
                        if (blobMetadata.shouldBeDeleted(true /* respectLeaseWaitTime */)) {
                        if (blobMetadata.shouldBeDeleted(true /* respectLeaseWaitTime */)) {
                            deleteBlobLocked(blobMetadata);
                            deleteBlobLocked(blobMetadata);
                            userBlobs.remove(blobHandle);
                            userBlobs.remove(blobHandle);
                        }
                        }
                        writeBlobsInfoAsync();
                        writeBlobsInfoAsync();
                    }
                    }
                }, getDeletionOnLastLeaseDelayMs());
            }
            writeBlobsInfoAsync();
        }
    }
    }


    private long getRemainingLeaseQuotaBytesInternal(int callingUid, String callingPackage) {
    private long getRemainingLeaseQuotaBytesInternal(int callingUid, String callingPackage) {