-
Notifications
You must be signed in to change notification settings - Fork 611
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
c1b3599
0432f58
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; | ||
|
|
||
|
|
@@ -215,6 +216,16 @@ protected BackendColumnIterator queryByIds(RocksDBSessions.Session session, | |
| )); | ||
| } | ||
|
|
||
| protected BackendColumnIterator queryByIdsWithGet(RocksDBSessions.Session session, | ||
| Collection<Id> ids) { | ||
| E.checkState(!session.hasChanges(), | ||
| "Can't queryByIds() when RocksDB session has pending changes"); | ||
| if (ids.isEmpty()) { | ||
| return BackendColumnIterator.empty(); | ||
| } | ||
| return this.getByIds(session, ids); | ||
| } | ||
|
Comment on lines
+219
to
+227
|
||
|
|
||
| protected BackendColumnIterator getById(RocksDBSessions.Session session, Id id) { | ||
| byte[] value = session.get(this.table(), id.asBytes()); | ||
| if (value == null) { | ||
|
|
@@ -224,13 +235,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 +322,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(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,8 +182,7 @@ protected BackendColumnIterator queryById(RocksDBSessions.Session session, Id id | |
| @Override | ||
| protected BackendColumnIterator queryByIds(RocksDBSessions.Session session, | ||
| Collection<Id> ids) { | ||
| // TODO: use getByIds() after batch version multi-get is ready | ||
| return super.queryByIds(session, ids); | ||
| return this.queryByIdsWithGet(session, ids); | ||
| } | ||
|
Comment on lines
182
to
186
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. Catch! This PR is RocksDB-only. I’ve updated the description to change closes 2674 to related 2674 |
||
| } | ||
|
|
||
|
|
@@ -208,6 +207,12 @@ public static Edge in(String database) { | |
| protected BackendColumnIterator queryById(RocksDBSessions.Session session, Id id) { | ||
| return this.getById(session, id); | ||
| } | ||
|
|
||
| @Override | ||
| protected BackendColumnIterator queryByIds(RocksDBSessions.Session session, | ||
| Collection<Id> ids) { | ||
| return this.queryByIdsWithGet(session, ids); | ||
| } | ||
| } | ||
|
|
||
| public static class IndexTable extends RocksDBTable { | ||
|
|
||
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.
Non-blocking: enabling
queryByIdsWithGet()for vertex/edge changes pending-write behavior: anysession.hasChanges()now throws before even the single-id path. Please confirm all callers reach this only after commit/rollback, or keep the old per-id fallback for pending sessions and add a test through a public query path.