Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/cas/storage/index/index_abc.py: 73.33%
15 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-22 21:04 +0000
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-22 21:04 +0000
1# Copyright (C) 2019 Bloomberg LP
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# <http://www.apache.org/licenses/LICENSE-2.0>
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
16"""
17IndexABC
18==================
20The abstract base class for storage indices. An index is a special type of
21Storage that facilitates storing blob metadata. It must wrap another Storage.
23Derived classes must implement all methods of both this interface and the
24StorageABC interface.
25"""
27import abc
29from ..storage_abc import StorageABC
32class IndexABC(StorageABC):
34 @abc.abstractmethod
35 def __init__(self, *, fallback_on_get=False):
37 # If fallback is enabled, the index is required to fetch blobs from
38 # storage on each get_blob and bulk_read_blobs request and update
39 # itself accordingly.
40 self._fallback_on_get = fallback_on_get
42 @abc.abstractmethod
43 def delete_blob(self, digest):
44 """ Delete a blob from the index. Return True if the blob was deleted,
45 or False otherwise.
47 TODO: This method will be promoted to StorageABC in a future commit. """
48 raise NotImplementedError()
50 @abc.abstractmethod
51 def least_recent_digests(self):
52 """ Generator to iterate through the digests in LRU order """
53 raise NotImplementedError()
55 @abc.abstractmethod
56 def get_total_size(self):
57 """ Return the sum of the size of all blobs within the index """
58 raise NotImplementedError()
60 @abc.abstractmethod
61 def mark_n_bytes_as_deleted(self, n_bytes):
62 """Mark a given number of bytes' worth of index entries as deleted.
64 The entries are marked as deleted in LRU order until the total size
65 marked as deleted is at least the requested number of bytes. If any
66 entries are already marked as deleted, they are used first when
67 attempting to reach the required number of bytes.
69 Args:
70 n_bytes (int): The number of bytes of index entries to mark as
71 deleted. When the sum of the ``size_bytes`` of index entries
72 meets or exceeds this value, the affected digests will be
73 returned.
74 Returns:
75 list: The list of digests that were marked as deleted.
77 """
78 raise NotImplementedError()