Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/cas/storage/index/index_abc.py: 73.33%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

15 statements  

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. 

14 

15 

16""" 

17IndexABC 

18================== 

19 

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. 

22 

23Derived classes must implement all methods of both this interface and the 

24StorageABC interface. 

25""" 

26 

27import abc 

28 

29from ..storage_abc import StorageABC 

30 

31 

32class IndexABC(StorageABC): 

33 

34 @abc.abstractmethod 

35 def __init__(self, *, fallback_on_get=False): 

36 

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 

41 

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. 

46 

47 TODO: This method will be promoted to StorageABC in a future commit. """ 

48 raise NotImplementedError() 

49 

50 @abc.abstractmethod 

51 def least_recent_digests(self): 

52 """ Generator to iterate through the digests in LRU order """ 

53 raise NotImplementedError() 

54 

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() 

59 

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. 

63 

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. 

68 

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. 

76 

77 """ 

78 raise NotImplementedError()