forked from hazelcast/hazelcast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Static and dynamic configuration for VectorCollection [HZAI-18, HZAI-…
…19, HZAI-20] (#1151) Implemented static and dynamic (member/client) configurations for vector collections in accordance with the checklist https://github.com/hazelcast/hazelcast/wiki/Checklist-for-Hazelcast-config-changes. Programmatic: ``` var vectorIndexConfig = new VectorIndexConfig().setMetric(Metric.EUCLIDEAN).setDimension(1).setName("index-1"); var vectorCollectionConfig = new VectorCollectionConfig("vector-collection-1").addVectorIndexConfig(vectorIndexConfig); Config config = new Config().addVectorCollectionConfig(vectorCollectionConfig); ``` XML: ``` <vector-collection name="vector-1"> <indexes> <index name="index-1"> <dimension>2</dimension> <metric>DOT</metric> </index> </indexes> </vector-collection> ``` YAML: ``` vector-collection: vector-1: indexes: - name: index-1 dimension: 2 metric: DOT ``` Restrictions and questions: 1) Permissions haven't been implemented. 2) The wildcard feature for vector collections operates akin to IMap. This implies that creating a vector collection configuration such as "*_OneIndexCollection" allows vector collections like "myvector_OneIndexCollection" to inherit the configuration. Is this functionality necessary? 3) The allowed pattern for vector collection name is ```[a-zA-Z0-9\\-*_]+```. The allowed pattern for vector collection index name is ```[a-zA-Z0-9\\-_]+```. 4) com.hazelcast.internal.config.*ReadOnly are not implemented as they are not used at the moment. Checklist: - [x] Codecs were generated using hazelcast-client-protocol but fixed after that. Understand how to generate the correct codec without requiring further modifications. - b79fb809c6db9f066d212cdfe42d923a85068efd - [x] check https://github.com/hazelcast/hazelcast/wiki/Checklist-for-Hazelcast-config-changes again - [x] Labels (`Team:`, `Type:`, `Source:`, `Module:`) and Milestone set - [x] Add `Add to Release Notes` label if changes should be mentioned in release notes or `Not Release Notes content` if changes are not relevant for release notes - [x] Request reviewers if possible - [x] New public APIs have `@Nonnull/@Nullable` annotations - [x] New public APIs have `@since` tags in Javadoc - [x] Send backports/forwardports if fix needs to be applied to past/future releases --------- Co-authored-by: Krzysztof Jamróz <[email protected]> Co-authored-by: Vassilis Bekiaris <[email protected]> GitOrigin-RevId: 8c01060ff2e7a4e161e0f2323fdb1b4356523412
- Loading branch information
1 parent
1b8e34e
commit f2fa6ae
Showing
43 changed files
with
1,959 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...com/hazelcast/client/impl/protocol/codec/DynamicConfigAddVectorCollectionConfigCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.client.impl.protocol.codec; | ||
|
||
import com.hazelcast.client.impl.protocol.ClientMessage; | ||
import com.hazelcast.client.impl.protocol.Generated; | ||
import com.hazelcast.client.impl.protocol.codec.builtin.*; | ||
import com.hazelcast.client.impl.protocol.codec.custom.*; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import static com.hazelcast.client.impl.protocol.ClientMessage.*; | ||
import static com.hazelcast.client.impl.protocol.codec.builtin.FixedSizeTypesCodec.*; | ||
|
||
/* | ||
* This file is auto-generated by the Hazelcast Client Protocol Code Generator. | ||
* To change this file, edit the templates or the protocol | ||
* definitions on the https://github.com/hazelcast/hazelcast-client-protocol | ||
* and regenerate it. | ||
*/ | ||
|
||
/** | ||
* Adds a new vector collection configuration to a running cluster. | ||
*/ | ||
@SuppressWarnings("unused") | ||
@Generated("52a7d98dfd816d848ac7f4d5bb84d6d3") | ||
public final class DynamicConfigAddVectorCollectionConfigCodec { | ||
//hex: 0x1B1400 | ||
public static final int REQUEST_MESSAGE_TYPE = 1774592; | ||
//hex: 0x1B1401 | ||
public static final int RESPONSE_MESSAGE_TYPE = 1774593; | ||
private static final int REQUEST_INITIAL_FRAME_SIZE = PARTITION_ID_FIELD_OFFSET + INT_SIZE_IN_BYTES; | ||
private static final int RESPONSE_INITIAL_FRAME_SIZE = RESPONSE_BACKUP_ACKS_FIELD_OFFSET + BYTE_SIZE_IN_BYTES; | ||
|
||
private DynamicConfigAddVectorCollectionConfigCodec() { | ||
} | ||
|
||
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"}) | ||
public static class RequestParameters { | ||
|
||
/** | ||
* vector collection's name | ||
*/ | ||
public java.lang.String name; | ||
|
||
/** | ||
* item vector index configurations | ||
*/ | ||
public java.util.List<com.hazelcast.config.vector.VectorIndexConfig> indexConfigs; | ||
} | ||
|
||
public static ClientMessage encodeRequest(java.lang.String name, java.util.List<com.hazelcast.config.vector.VectorIndexConfig> indexConfigs) { | ||
ClientMessage clientMessage = ClientMessage.createForEncode(); | ||
clientMessage.setRetryable(false); | ||
clientMessage.setOperationName("DynamicConfig.AddVectorCollectionConfig"); | ||
ClientMessage.Frame initialFrame = new ClientMessage.Frame(new byte[REQUEST_INITIAL_FRAME_SIZE], UNFRAGMENTED_MESSAGE); | ||
encodeInt(initialFrame.content, TYPE_FIELD_OFFSET, REQUEST_MESSAGE_TYPE); | ||
encodeInt(initialFrame.content, PARTITION_ID_FIELD_OFFSET, -1); | ||
clientMessage.add(initialFrame); | ||
StringCodec.encode(clientMessage, name); | ||
ListMultiFrameCodec.encode(clientMessage, indexConfigs, VectorIndexConfigCodec::encode); | ||
return clientMessage; | ||
} | ||
|
||
public static DynamicConfigAddVectorCollectionConfigCodec.RequestParameters decodeRequest(ClientMessage clientMessage) { | ||
ClientMessage.ForwardFrameIterator iterator = clientMessage.frameIterator(); | ||
RequestParameters request = new RequestParameters(); | ||
//empty initial frame | ||
iterator.next(); | ||
request.name = StringCodec.decode(iterator); | ||
request.indexConfigs = ListMultiFrameCodec.decode(iterator, VectorIndexConfigCodec::decode); | ||
return request; | ||
} | ||
|
||
public static ClientMessage encodeResponse() { | ||
ClientMessage clientMessage = ClientMessage.createForEncode(); | ||
ClientMessage.Frame initialFrame = new ClientMessage.Frame(new byte[RESPONSE_INITIAL_FRAME_SIZE], UNFRAGMENTED_MESSAGE); | ||
encodeInt(initialFrame.content, TYPE_FIELD_OFFSET, RESPONSE_MESSAGE_TYPE); | ||
clientMessage.add(initialFrame); | ||
|
||
return clientMessage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...src/main/java/com/hazelcast/client/impl/protocol/codec/custom/VectorIndexConfigCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.client.impl.protocol.codec.custom; | ||
|
||
import com.hazelcast.client.impl.protocol.ClientMessage; | ||
import com.hazelcast.client.impl.protocol.Generated; | ||
import com.hazelcast.client.impl.protocol.codec.builtin.*; | ||
|
||
import static com.hazelcast.client.impl.protocol.codec.builtin.CodecUtil.fastForwardToEndFrame; | ||
import static com.hazelcast.client.impl.protocol.ClientMessage.*; | ||
import static com.hazelcast.client.impl.protocol.codec.builtin.FixedSizeTypesCodec.*; | ||
|
||
@SuppressWarnings("unused") | ||
@Generated("68fdb687656a1ea263358c750a00aa99") | ||
public final class VectorIndexConfigCodec { | ||
private static final int METRIC_FIELD_OFFSET = 0; | ||
private static final int DIMENSION_FIELD_OFFSET = METRIC_FIELD_OFFSET + INT_SIZE_IN_BYTES; | ||
private static final int INITIAL_FRAME_SIZE = DIMENSION_FIELD_OFFSET + INT_SIZE_IN_BYTES; | ||
|
||
private VectorIndexConfigCodec() { | ||
} | ||
|
||
public static void encode(ClientMessage clientMessage, com.hazelcast.config.vector.VectorIndexConfig vectorIndexConfig) { | ||
clientMessage.add(BEGIN_FRAME.copy()); | ||
|
||
ClientMessage.Frame initialFrame = new ClientMessage.Frame(new byte[INITIAL_FRAME_SIZE]); | ||
encodeInt(initialFrame.content, METRIC_FIELD_OFFSET, vectorIndexConfig.getMetric()); | ||
encodeInt(initialFrame.content, DIMENSION_FIELD_OFFSET, vectorIndexConfig.getDimension()); | ||
clientMessage.add(initialFrame); | ||
|
||
CodecUtil.encodeNullable(clientMessage, vectorIndexConfig.getName(), StringCodec::encode); | ||
|
||
clientMessage.add(END_FRAME.copy()); | ||
} | ||
|
||
public static com.hazelcast.config.vector.VectorIndexConfig decode(ClientMessage.ForwardFrameIterator iterator) { | ||
// begin frame | ||
iterator.next(); | ||
|
||
ClientMessage.Frame initialFrame = iterator.next(); | ||
int metric = decodeInt(initialFrame.content, METRIC_FIELD_OFFSET); | ||
int dimension = decodeInt(initialFrame.content, DIMENSION_FIELD_OFFSET); | ||
|
||
java.lang.String name = CodecUtil.decodeNullable(iterator, StringCodec::decode); | ||
|
||
fastForwardToEndFrame(iterator); | ||
|
||
return CustomTypeFactory.createVectorIndexConfig(name, metric, dimension); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.