-
Notifications
You must be signed in to change notification settings - Fork 169
Adding serializer and api implementation for segment profiler state #2687
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
Changes from 3 commits
33ad02f
5cce54e
b4a80e1
5b2fbda
40375eb
4a6d45b
6464751
3f9bc09
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.index.query; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.apache.lucene.index.LeafReader; | ||
import org.opensearch.knn.profiler.SegmentProfileKNNCollector; | ||
import org.opensearch.knn.profiler.SegmentProfilerState; | ||
|
||
import java.io.IOException; | ||
import java.util.Locale; | ||
|
||
/** | ||
* Utility class to get segment profiler state for a given field | ||
*/ | ||
@UtilityClass | ||
public class SegmentProfilerUtil { | ||
|
||
/** | ||
* Gets the segment profile state for a given field | ||
* @param leafReader The leaf reader to query | ||
* @param fieldName The field name to profile | ||
* @return The segment profiler state | ||
* @throws IOException If there's an error reading the segment | ||
*/ | ||
public static SegmentProfilerState getSegmentProfileState(final LeafReader leafReader, String fieldName) throws IOException { | ||
final SegmentProfileKNNCollector tempCollector = new SegmentProfileKNNCollector(); | ||
leafReader.searchNearestVectors(fieldName, new float[0], tempCollector, null); | ||
if (tempCollector.getSegmentProfilerState() == null) { | ||
throw new IllegalStateException(String.format(Locale.ROOT, "No segment state found for field %s", fieldName)); | ||
} | ||
return tempCollector.getSegmentProfilerState(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.plugin.transport; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.knn.profiler.SegmentProfilerState; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
public class KNNIndexShardProfileResult implements Writeable { | ||
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. Do we also need deserialization logic with this? 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. I think it may be useful especially when compressing vectors. |
||
List<SegmentProfilerState> segmentProfilerStateList; | ||
String shardId; | ||
|
||
/** | ||
* Constructor for reading from StreamInput | ||
*/ | ||
public KNNIndexShardProfileResult(StreamInput streamInput) throws IOException { | ||
this.shardId = streamInput.readString(); | ||
|
||
int size = streamInput.readInt(); | ||
|
||
this.segmentProfilerStateList = new ArrayList<>(size); | ||
for (int i = 0; i < size; i++) { | ||
byte[] stateBytes = streamInput.readByteArray(); | ||
segmentProfilerStateList.add(SegmentProfilerState.fromBytes(stateBytes)); | ||
} | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput streamOutput) throws IOException { | ||
streamOutput.writeString(shardId); | ||
|
||
// Write the segment profiler state list size | ||
streamOutput.writeInt(segmentProfilerStateList.size()); | ||
|
||
// Write each SegmentProfilerState as bytes | ||
for (SegmentProfilerState state : segmentProfilerStateList) { | ||
byte[] stateBytes = state.toByteArray(); | ||
streamOutput.writeByteArray(stateBytes); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.plugin.transport; | ||
|
||
import org.opensearch.action.ActionType; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
|
||
public class KNNProfileAction extends ActionType<KNNProfileResponse> { | ||
|
||
public static final KNNProfileAction INSTANCE = new KNNProfileAction(); | ||
public static final String NAME = "cluster:admin/knn_profile_action"; | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
private KNNProfileAction() { | ||
super(NAME, KNNProfileResponse::new); | ||
} | ||
|
||
@Override | ||
public Writeable.Reader<KNNProfileResponse> getResponseReader() { | ||
return KNNProfileResponse::new; | ||
} | ||
} |
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.
Why are we adding these changes? Weren't they already merged?
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.
Yes, updated branch to adjust with changes already implemented in feature branch