Skip to content

cachehitrate implies a rate but is used as a boolean flag #3

Open
@HerrHorizontal

Description

@HerrHorizontal

The cachehitrate parameter in RequestedFiles_HitrateBased is currently used as a boolean despite being an integer.

class RequestedFile_HitrateBased(RequestedFile):
"""
Represents a requested file in hitrate based caching.
The cachehitrate flag is somewhat messed up currently.
**Its use should be reworked when remodeling the connection module.**
"""
__slots__ = "cachehitrate"
def __init__(self, filename: str, filesize: int, cachehitrate: int):
super().__init__(filename, filesize)
"""flag whether the file is cached, 1 if it is cached, 0 if it is not cached"""
self.cachehitrate = cachehitrate

Since the meaning of a rate implies a percentage, this either needs a renaming or checking if the application of cachehitrate in terms of a rate does not change expectation, e.g. in the HitrateStorage and FileBasedHitrateStorage implementation.
Here the cachehitrate is used in two different ways,

  • as a boolean in the transfer method for FileBasedHitrateStorage

if file.cachehitrate:
await self.connection.transfer(total=file.filesize)
await sampling_required.put(self.connection)
else:
print("wants to read from remote")
print("file is not cached but cache is file source, this should not occur")
raise ValueError

  • as a multiplicative factor in the find method for FileBasedHitrateStorage

return LookUpInformation(file.filesize * file.cachehitrate, self)

  • as a multiplicative factor in transfer for HitrateStorage (however, this class is out of date already)

hitrate_size = self._hitrate * file.filesize

As the current implementation already ensures correct functioning also with rates, I would propose to actually interpret it as it is named already. This means the following should be done:

  • adaptation of docstrings to remove mentioning of interpretation as a flag
  • adaptation of typehints
  • unit tests to ensure that everything works as expected

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactoringRestructuring for better intelligibility

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions