-
Notifications
You must be signed in to change notification settings - Fork 920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store creator hash prefixes in a separate lookup file #27731
base: master
Are you sure you want to change the base?
Conversation
11de286
to
a327bb5
Compare
9f6e4ff
to
f730894
Compare
|
||
// A random-access iterator over prefixes stored in an uncompressed prefix list, | ||
// suitable for binary search. | ||
class HashPrefixIterator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, do we really need this thing?
If it's only to support std::binary_search, we can just compare [0.. count-1] indexes + a custom compare function instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a rename (and cleanup) of an existing class currently used by PrefixListReader
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O, thanks, I missed that part.
I see it uses to make sanity check that the first few prefixes are in order. That code can be moved to UpdatePrefixes
.
If we can rid off it completely, it will be great.
if (!reader.ReadU32LittleEndian(parts.prefix_size)) { | ||
return std::nullopt; | ||
} | ||
parts.prefixes = reader.remaining_span(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we need to verify size here. Otherwise we can get an overflow in case the file is broken (i.e. with a sudden shutdown)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See IsValidFile
for span-length validation.
static scoped_refptr<base::SequencedTaskRunner> CreateTaskRunner() { | ||
return base::ThreadPool::CreateSequencedTaskRunner( | ||
{base::MayBlock(), base::TaskPriority::USER_VISIBLE, | ||
base::TaskShutdownBehavior::BLOCK_SHUTDOWN}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe SKIP_SHUTDOWN
?
Also does it make sense to reuse one of the current task runner to simplify things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use SKIP_ON_SHUTDOWN
. I will look into the possibility of reusing a task runner.
HashPrefixStore& operator=(const HashPrefixStore&) = delete; | ||
|
||
// Opens the hash prefix file, if not already open. | ||
bool Open(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move internal methods to the private section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is intentionally public. It's used by the unit tests for instance, but in principle could be used by a client to manually control opening/closing.
uint32 prefix_size; | ||
}; | ||
|
||
interface HashPrefixStore { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we use actually use this interface for IPC? If not why just not use sequenceBound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered passing this interface to the Rewards engine, but decided to leave that for a future improvement. In the meantime, it is used to run the interface on a different thread (via RemoteWorker
). However, if you aren't comfortable with that approach, I can use SequenceBound
instead.
f730894
to
a9d51f7
Compare
[puLL-Merge] - brave/brave-core@27731 DescriptionThis PR implements a new storage system for creator hash prefixes in Brave Rewards, moving them from a SQLite database table to a dedicated memory-mapped file. This change aims to improve performance and reduce memory usage by keeping the hash prefixes in a more efficient format that can be searched directly without database queries. ChangesChanges
sequenceDiagram
participant Client
participant RewardsServiceImpl
participant HashPrefixStore
participant MemoryMappedFile
Client->>RewardsServiceImpl: UpdateCreatorPrefixStore(data)
RewardsServiceImpl->>HashPrefixStore: UpdatePrefixes(prefixes, size)
HashPrefixStore->>HashPrefixStore: Close()
HashPrefixStore->>HashPrefixStore: WriteFileHeader()
HashPrefixStore->>HashPrefixStore: WritePrefixes()
HashPrefixStore-->>RewardsServiceImpl: success
RewardsServiceImpl-->>Client: success
Client->>RewardsServiceImpl: ContainsPrefix(value)
RewardsServiceImpl->>HashPrefixStore: ContainsPrefix(value)
HashPrefixStore->>MemoryMappedFile: Open()
HashPrefixStore->>HashPrefixStore: BinarySearch()
HashPrefixStore-->>RewardsServiceImpl: result
RewardsServiceImpl-->>Client: result
Security Hotspots
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++rewards
@@ -236,12 +237,14 @@ void DeferCallback(base::Location location, Callback callback, Args&&... args) { | |||
// read comment about file pathes at src\base\files\file_path.h | |||
#if BUILDFLAG(IS_WIN) | |||
const base::FilePath::StringType kDiagnosticLogPath(L"Rewards.log"); | |||
const base::FilePath::StringType kCreatorPrefixStore(L"RewardsCreators.db"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep these in alphabetical order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
a9d51f7
to
0cb3a99
Compare
Resolves brave/brave-browser#43994
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan: