mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
In DB::NewIterator(), try to allocate the whole iterator tree in an arena
Summary: In this patch, try to allocate the whole iterator tree starting from DBIter from an arena 1. ArenaWrappedDBIter is created when serves as the entry point of an iterator tree, with an arena in it. 2. Add an option to create iterator from arena for following iterators: DBIter, MergingIterator, MemtableIterator, all mem table's iterators, all table reader's iterators and two level iterator. 3. MergeIteratorBuilder is created to incrementally build the tree of internal iterators. It is passed to mem table list and version set and add iterators to it. Limitations: (1) Only DB::NewIterator() without tailing uses the arena. Other cases, including readonly DB and compactions are still from malloc (2) Two level iterator itself is allocated in arena, but not iterators inside it. Test Plan: make all check Reviewers: ljin, haobo Reviewed By: haobo Subscribers: leveldb, dhruba, yhchiang, igor Differential Revision: https://reviews.facebook.net/D18513
This commit is contained in:
@@ -95,7 +95,7 @@ class VectorRep : public MemTableRep {
|
||||
using MemTableRep::GetIterator;
|
||||
|
||||
// Return an iterator over the keys in this representation.
|
||||
virtual MemTableRep::Iterator* GetIterator() override;
|
||||
virtual MemTableRep::Iterator* GetIterator(Arena* arena) override;
|
||||
|
||||
private:
|
||||
friend class Iterator;
|
||||
@@ -259,16 +259,28 @@ void VectorRep::Get(const LookupKey& k, void* callback_args,
|
||||
}
|
||||
}
|
||||
|
||||
MemTableRep::Iterator* VectorRep::GetIterator() {
|
||||
MemTableRep::Iterator* VectorRep::GetIterator(Arena* arena) {
|
||||
char* mem = nullptr;
|
||||
if (arena != nullptr) {
|
||||
mem = arena->AllocateAligned(sizeof(Iterator));
|
||||
}
|
||||
ReadLock l(&rwlock_);
|
||||
// Do not sort here. The sorting would be done the first time
|
||||
// a Seek is performed on the iterator.
|
||||
if (immutable_) {
|
||||
return new Iterator(this, bucket_, compare_);
|
||||
if (arena == nullptr) {
|
||||
return new Iterator(this, bucket_, compare_);
|
||||
} else {
|
||||
return new (mem) Iterator(this, bucket_, compare_);
|
||||
}
|
||||
} else {
|
||||
std::shared_ptr<Bucket> tmp;
|
||||
tmp.reset(new Bucket(*bucket_)); // make a copy
|
||||
return new Iterator(nullptr, tmp, compare_);
|
||||
if (arena == nullptr) {
|
||||
return new Iterator(nullptr, tmp, compare_);
|
||||
} else {
|
||||
return new (mem) Iterator(nullptr, tmp, compare_);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // anon namespace
|
||||
|
||||
Reference in New Issue
Block a user