Skip to content

Optimize serialization for WriteOnly with PendingWritesQueue - #4420

Open
jjezra wants to merge 8 commits into
FoundationDB:mainfrom
jjezra:vector_index_remove_common_keys
Open

Optimize serialization for WriteOnly with PendingWritesQueue#4420
jjezra wants to merge 8 commits into
FoundationDB:mainfrom
jjezra:vector_index_remove_common_keys

Conversation

@jjezra

@jjezra jjezra commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

This PR is a followup of #4370.

If an update is not needed (i.e both new and old records were filtered out), skip pushing a pending write queue item as the operation is a no-op.
Vector index, when updating from queue, will remove common entries (i.e. replacing an entry with an exact copy) similar to what IndexStandardMaintainer does during regular update.

@jjezra jjezra added the enhancement New feature or request label Aug 4, 2026
@jjezra
jjezra marked this pull request as ready for review August 4, 2026 22:00
@jjezra
jjezra requested a review from ScottDugas August 4, 2026 22:00
@jjezra
jjezra requested a review from ScottDugas August 6, 2026 01:52
.as("removing a record the filter excludes must not be deferred either")
.isNull();

assertThat(nearestRecNos(index, query, 10))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to have a call to updateFromQueue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the Any returned from serializations in this test are null and cannot be used in updateFromQueue. What am I missing?

Comment on lines +856 to +865
final Tuple primaryKey = stored.getPrimaryKey();
final Message rec = VectorRecord.newBuilder()
.setGroupId(Ints.checkedCast(primaryKey.getLong(0)))
.setRecNo(primaryKey.getLong(1))
.setVectorData(ByteString.copyFrom(vector.getRawData()))
.build();
return FDBStoredRecord.newBuilder(rec)
.setPrimaryKey(primaryKey)
.setRecordType(stored.getRecordType())
.build();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simpler and cleaner with:

return stored.toBuilder().setVectorData(ByteString.copyFrom(vector.getRawData())).build()

@jjezra jjezra Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like stored.asBuilder() returns a generic FDBStoredRecordBuilder which wouldn't support setVectorData. Casting may be a little tricky in this elegant one liner.

@Nonnull
private VectorIndexMaintainer maintainerExcludingRecordsWithoutVector(@Nonnull final Index index) {
final IndexMaintenanceFilter filter = (ignored, record) ->
record instanceof VectorRecord && ((VectorRecord)record).hasVectorData()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
record instanceof VectorRecord && ((VectorRecord)record).hasVectorData()
final IndexMaintenanceFilter filter = (ignored, rec) ->
rec instanceof VectorRecord && ((VectorRecord)record).hasVectorData()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ScottDugas ScottDugas changed the title Optimize PWQ serialization Optimize serialization for WriteOnlyWithPendingWritesQueue Aug 11, 2026
@ScottDugas ScottDugas changed the title Optimize serialization for WriteOnlyWithPendingWritesQueue Optimize serialization for WriteOnly with PendingWritesQueue Aug 11, 2026
@jjezra
jjezra requested a review from ScottDugas August 13, 2026 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants