-
Notifications
You must be signed in to change notification settings - Fork 597
optimize: Optimize rockdb batch query performance #2982
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
base: master
Are you sure you want to change the base?
Changes from all commits
5ba6d4a
f5405a0
939ace0
502c7df
352f66b
0d9052d
45298f9
223fb28
ce4e2cb
6fe08a7
0391069
ce802b9
c06225c
a99491b
10cb0a4
d33123e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.Iterator; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
|
|
@@ -209,6 +210,10 @@ protected BackendColumnIterator queryByIds(RocksDBSessions.Session session, | |
| return this.queryById(session, ids.iterator().next()); | ||
| } | ||
|
|
||
| if (!session.hasChanges()) { | ||
| return this.getByIds(session, ids); | ||
| } | ||
|
|
||
| // NOTE: this will lead to lazy create rocksdb iterator | ||
| return BackendColumnIterator.wrap(new FlatMapperIterator<>( | ||
| ids.iterator(), id -> this.queryById(session, id) | ||
|
|
@@ -224,13 +229,15 @@ protected BackendColumnIterator getById(RocksDBSessions.Session session, Id id) | |
| return BackendColumnIterator.iterator(col); | ||
| } | ||
|
|
||
| protected BackendColumnIterator getByIds(RocksDBSessions.Session session, Set<Id> ids) { | ||
| protected BackendColumnIterator getByIds(RocksDBSessions.Session session, | ||
| Collection<Id> ids) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
原方法接收 测试 建议:在
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added LinkedHashSet deduplication at the getByIds() entry point while preserving input order; skips if Set is already passed. Test updated to verify dedup behavior. The |
||
| if (ids.size() == 1) { | ||
| return this.getById(session, ids.iterator().next()); | ||
| } | ||
|
|
||
| List<byte[]> keys = new ArrayList<>(ids.size()); | ||
| for (Id id : ids) { | ||
| Collection<Id> uniqueIds = ids instanceof Set ? ids : new LinkedHashSet<>(ids); | ||
| List<byte[]> keys = new ArrayList<>(uniqueIds.size()); | ||
| for (Id id : uniqueIds) { | ||
| keys.add(id.asBytes()); | ||
| } | ||
| return session.get(this.table(), keys); | ||
|
|
@@ -309,7 +316,7 @@ protected static BackendEntryIterator newEntryIterator(BackendColumnIterator col | |
| } | ||
|
|
||
| protected static BackendEntryIterator newEntryIteratorOlap( | ||
| BackendColumnIterator cols, Query query, boolean isOlap) { | ||
| BackendColumnIterator cols, Query query, boolean isOlap) { | ||
| return new BinaryEntryIterator<>(cols, query, (entry, col) -> { | ||
| if (entry == null || !entry.belongToMe(col)) { | ||
| HugeType type = query.resultType(); | ||
|
|
||
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.
getByIds()放到RocksDBTable父类会改变非 Vertex/Edge 表的查询语义。父类queryById()仍然使用session.scan(table, id.asBytes()),并且注释里说明 vertex/schema 目前还不能统一改成 point get;但这个分支会让所有未 overridequeryByIds()的 RocksDB table 在多 id 查询时改走 exact multi-get。这对
Vertex/Edge是合理的,因为它们的queryById()已经是getById();但 schema/index 等表原本依赖 prefix scan,放在父类可能导致多 id 查询查不到本应返回的列。建议父类保留旧的 scan-based 实现,把 multi-get 下沉到Vertex/Edge的 override 中。然后在
RocksDBTables.Vertex/RocksDBTables.Edge中分别 overridequeryByIds(),仅在!session.hasChanges()时调用getByIds()。