@zilliz/milvus2-sdk-node 2.6.9 → 2.6.11-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -196
- package/dist/milvus/HttpClient.d.ts +48 -9
- package/dist/milvus/HttpClient.js +1 -1
- package/dist/milvus/HttpClient.js.map +1 -1
- package/dist/milvus/const/client.d.ts +3 -1
- package/dist/milvus/const/client.js +2 -0
- package/dist/milvus/const/client.js.map +1 -1
- package/dist/milvus/const/error.d.ts +3 -0
- package/dist/milvus/const/error.js +4 -1
- package/dist/milvus/const/error.js.map +1 -1
- package/dist/milvus/const/milvus.d.ts +3 -1
- package/dist/milvus/const/milvus.js +2 -0
- package/dist/milvus/const/milvus.js.map +1 -1
- package/dist/milvus/grpc/BaseClient.d.ts +7 -1
- package/dist/milvus/grpc/BaseClient.js +18 -3
- package/dist/milvus/grpc/BaseClient.js.map +1 -1
- package/dist/milvus/grpc/Collection.d.ts +86 -1
- package/dist/milvus/grpc/Collection.js +138 -0
- package/dist/milvus/grpc/Collection.js.map +1 -1
- package/dist/milvus/grpc/Data.d.ts +68 -4
- package/dist/milvus/grpc/Data.js +106 -6
- package/dist/milvus/grpc/Data.js.map +1 -1
- package/dist/milvus/grpc/GrpcClient.d.ts +19 -3
- package/dist/milvus/grpc/GrpcClient.js +170 -10
- package/dist/milvus/grpc/GrpcClient.js.map +1 -1
- package/dist/milvus/http/Alias.d.ts +1 -1
- package/dist/milvus/http/Collection.d.ts +10 -2
- package/dist/milvus/http/Collection.js +48 -0
- package/dist/milvus/http/Collection.js.map +1 -1
- package/dist/milvus/http/Database.d.ts +42 -0
- package/dist/milvus/http/Database.js +71 -0
- package/dist/milvus/http/Database.js.map +1 -0
- package/dist/milvus/http/Import.d.ts +1 -1
- package/dist/milvus/http/MilvusIndex.d.ts +4 -2
- package/dist/milvus/http/MilvusIndex.js +12 -0
- package/dist/milvus/http/MilvusIndex.js.map +1 -1
- package/dist/milvus/http/Partition.d.ts +1 -1
- package/dist/milvus/http/Role.d.ts +1 -1
- package/dist/milvus/http/User.d.ts +1 -1
- package/dist/milvus/http/Vector.d.ts +1 -1
- package/dist/milvus/http/Vector.js +1 -1
- package/dist/milvus/http/Vector.js.map +1 -1
- package/dist/milvus/http/index.d.ts +1 -0
- package/dist/milvus/http/index.js +1 -0
- package/dist/milvus/http/index.js.map +1 -1
- package/dist/milvus/proto-json/milvus.base.d.ts +34 -514
- package/dist/milvus/proto-json/milvus.base.js +36 -522
- package/dist/milvus/proto-json/milvus.base.js.map +1 -1
- package/dist/milvus/proto-json/milvus.d.ts +90 -570
- package/dist/milvus/proto-json/milvus.js +92 -578
- package/dist/milvus/proto-json/milvus.js.map +1 -1
- package/dist/milvus/proto-json/schema.base.d.ts +6 -44
- package/dist/milvus/proto-json/schema.base.js +8 -46
- package/dist/milvus/proto-json/schema.base.js.map +1 -1
- package/dist/milvus/types/Client.d.ts +8 -3
- package/dist/milvus/types/Collection.d.ts +24 -0
- package/dist/milvus/types/Common.d.ts +2 -0
- package/dist/milvus/types/GlobalCluster.d.ts +23 -0
- package/dist/milvus/types/GlobalCluster.js +12 -0
- package/dist/milvus/types/GlobalCluster.js.map +1 -0
- package/dist/milvus/types/Http.d.ts +99 -0
- package/dist/milvus/types/Search.d.ts +4 -2
- package/dist/milvus/types/Segments.d.ts +33 -1
- package/dist/milvus/types/index.d.ts +1 -0
- package/dist/milvus/types/index.js +1 -0
- package/dist/milvus/types/index.js.map +1 -1
- package/dist/milvus/utils/Function.d.ts +31 -4
- package/dist/milvus/utils/Function.js +95 -17
- package/dist/milvus/utils/Function.js.map +1 -1
- package/dist/milvus/utils/GlobalTopology.d.ts +56 -0
- package/dist/milvus/utils/GlobalTopology.js +215 -0
- package/dist/milvus/utils/GlobalTopology.js.map +1 -0
- package/dist/milvus/utils/Grpc.d.ts +6 -0
- package/dist/milvus/utils/Grpc.js +29 -1
- package/dist/milvus/utils/Grpc.js.map +1 -1
- package/dist/milvus/utils/Schema.d.ts +12 -1
- package/dist/milvus/utils/Schema.js +21 -1
- package/dist/milvus/utils/Schema.js.map +1 -1
- package/dist/milvus/utils/Search.d.ts +16 -0
- package/dist/milvus/utils/Search.js +47 -3
- package/dist/milvus/utils/Search.js.map +1 -1
- package/dist/milvus/utils/index.d.ts +1 -0
- package/dist/milvus/utils/index.js +1 -0
- package/dist/milvus/utils/index.js.map +1 -1
- package/dist/sdk.json +1 -1
- package/package.json +10 -5
|
@@ -24,13 +24,14 @@ export interface SearchReq extends collectionNameReq {
|
|
|
24
24
|
expr?: string;
|
|
25
25
|
exprValues?: keyValueObj;
|
|
26
26
|
search_params: SearchParam;
|
|
27
|
-
vectors
|
|
27
|
+
vectors?: SearchData | SearchData[];
|
|
28
28
|
output_fields?: string[];
|
|
29
29
|
travel_timestamp?: string;
|
|
30
30
|
vector_type: DataType.BinaryVector | DataType.FloatVector;
|
|
31
31
|
nq?: number;
|
|
32
32
|
consistency_level?: ConsistencyLevelEnum;
|
|
33
33
|
transformers?: OutputTransformers;
|
|
34
|
+
ids?: number[] | string[];
|
|
34
35
|
}
|
|
35
36
|
export interface FunctionScore {
|
|
36
37
|
functions: FunctionObject[];
|
|
@@ -39,7 +40,7 @@ export interface FunctionScore {
|
|
|
39
40
|
export interface SearchSimpleReq extends collectionNameReq {
|
|
40
41
|
partition_names?: string[];
|
|
41
42
|
anns_field?: string;
|
|
42
|
-
data
|
|
43
|
+
data?: SearchData | SearchData[];
|
|
43
44
|
vector?: SearchData | SearchData[];
|
|
44
45
|
output_fields?: string[];
|
|
45
46
|
limit?: number;
|
|
@@ -60,6 +61,7 @@ export interface SearchSimpleReq extends collectionNameReq {
|
|
|
60
61
|
transformers?: OutputTransformers;
|
|
61
62
|
rerank?: RerankerObj | FunctionObject | FunctionScore;
|
|
62
63
|
nq?: number;
|
|
64
|
+
ids?: number[] | string[];
|
|
63
65
|
}
|
|
64
66
|
export type HybridSearchSingleReq = Pick<SearchParam, 'anns_field' | 'ignore_growing' | 'group_by_field'> & {
|
|
65
67
|
data: SearchData;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { SegmentState, SegmentLevel } from '../const';
|
|
2
2
|
import { resStatusResponse, collectionNameReq, GrpcTimeOut } from './Common';
|
|
3
3
|
export interface GetFlushStateReq extends GrpcTimeOut {
|
|
4
|
-
segmentIDs
|
|
4
|
+
segmentIDs?: number[];
|
|
5
|
+
flush_ts?: number;
|
|
6
|
+
db_name?: string;
|
|
7
|
+
collection_name?: string;
|
|
5
8
|
}
|
|
6
9
|
export interface FlushReq extends GrpcTimeOut {
|
|
7
10
|
collection_names: string[];
|
|
@@ -25,6 +28,8 @@ export interface QuerySegmentInfo {
|
|
|
25
28
|
state: SegmentState;
|
|
26
29
|
nodeIds: number[];
|
|
27
30
|
level: SegmentLevel;
|
|
31
|
+
is_sorted: boolean;
|
|
32
|
+
storage_version: number;
|
|
28
33
|
}
|
|
29
34
|
export interface GetQuerySegmentInfoResponse extends resStatusResponse {
|
|
30
35
|
infos: QuerySegmentInfo[];
|
|
@@ -35,6 +40,9 @@ export interface PersistentSegmentInfo {
|
|
|
35
40
|
partitionID: number;
|
|
36
41
|
num_rows: number;
|
|
37
42
|
state: SegmentState;
|
|
43
|
+
level: SegmentLevel;
|
|
44
|
+
is_sorted: boolean;
|
|
45
|
+
storage_version: number;
|
|
38
46
|
}
|
|
39
47
|
export interface GePersistentSegmentInfoResponse extends resStatusResponse {
|
|
40
48
|
infos: PersistentSegmentInfo[];
|
|
@@ -53,6 +61,28 @@ export interface DescribeSegmentIndexDataResponse extends resStatusResponse {
|
|
|
53
61
|
index_params: any;
|
|
54
62
|
index_data: any;
|
|
55
63
|
}
|
|
64
|
+
export interface FlushAllReq extends GrpcTimeOut {
|
|
65
|
+
db_name?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface FlushClusterInfo {
|
|
68
|
+
cluster_id: string;
|
|
69
|
+
cchannel: string;
|
|
70
|
+
pchannels: string[];
|
|
71
|
+
}
|
|
72
|
+
export interface FlushAllResponse extends resStatusResponse {
|
|
73
|
+
flush_all_ts: number;
|
|
74
|
+
flush_all_tss: Record<string, number>;
|
|
75
|
+
flush_all_msgs: Record<string, any>;
|
|
76
|
+
cluster_info: FlushClusterInfo;
|
|
77
|
+
}
|
|
78
|
+
export interface GetFlushAllStateReq extends GrpcTimeOut {
|
|
79
|
+
flush_all_ts?: number;
|
|
80
|
+
db_name?: string;
|
|
81
|
+
flush_all_tss?: Record<string, number>;
|
|
82
|
+
}
|
|
83
|
+
export interface GetFlushAllStateResponse extends resStatusResponse {
|
|
84
|
+
flushed: boolean;
|
|
85
|
+
}
|
|
56
86
|
export interface GetQuerySegmentInfoReq extends GrpcTimeOut {
|
|
57
87
|
collectionName: string;
|
|
58
88
|
dbName?: string;
|
|
@@ -65,4 +95,6 @@ export interface LoadBalanceReq extends GrpcTimeOut {
|
|
|
65
95
|
src_nodeID: number;
|
|
66
96
|
dst_nodeIDs?: number[];
|
|
67
97
|
sealed_segmentIDs?: number[];
|
|
98
|
+
collectionName?: string;
|
|
99
|
+
db_name?: string;
|
|
68
100
|
}
|
|
@@ -32,4 +32,5 @@ __exportStar(require("./Segments"), exports);
|
|
|
32
32
|
__exportStar(require("./Insert"), exports);
|
|
33
33
|
__exportStar(require("./Search"), exports);
|
|
34
34
|
__exportStar(require("./DataTypes"), exports);
|
|
35
|
+
__exportStar(require("./GlobalCluster"), exports);
|
|
35
36
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../milvus/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,eAAe;AACf,6CAA2B;AAC3B,+CAA6B;AAC7B,yCAAuB;AACvB,2CAAyB;AACzB,gDAA8B;AAC9B,8CAA4B;AAC5B,6CAA2B;AAC3B,yCAAuB;AACvB,6CAA2B;AAC3B,2CAAyB;AACzB,gDAA8B;AAC9B,8CAA4B;AAC5B,yCAAuB;AACvB,6CAA2B;AAC3B,2CAAyB;AACzB,2CAAyB;AACzB,8CAA4B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../milvus/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,eAAe;AACf,6CAA2B;AAC3B,+CAA6B;AAC7B,yCAAuB;AACvB,2CAAyB;AACzB,gDAA8B;AAC9B,8CAA4B;AAC5B,6CAA2B;AAC3B,yCAAuB;AACvB,6CAA2B;AAC3B,2CAAyB;AACzB,gDAA8B;AAC9B,8CAA4B;AAC5B,yCAAuB;AACvB,6CAA2B;AAC3B,2CAAyB;AACzB,2CAAyB;AACzB,8CAA4B;AAC5B,kDAAgC"}
|
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
import { KeyValuePair, FieldSchema, SparseFloatVector, FieldData } from '../';
|
|
2
2
|
import { Pool } from 'generic-pool';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Failover handler type for global cluster support.
|
|
5
|
+
* When attached to a pool, promisify will call this on UNAVAILABLE errors
|
|
6
|
+
* after all interceptor retries are exhausted.
|
|
7
|
+
* Should return a new pool to retry with, or null if no failover occurred.
|
|
8
|
+
*/
|
|
9
|
+
export type FailoverHandler = (error: any) => Promise<Pool<any> | null>;
|
|
10
|
+
/** Well-known property key for attaching a failover handler to a pool. */
|
|
11
|
+
export declare const FAILOVER_HANDLER_KEY = "__failoverHandler";
|
|
12
|
+
/**
|
|
13
|
+
* Attach a failover handler to a pool for global cluster support.
|
|
14
|
+
*/
|
|
15
|
+
export declare function setPoolFailoverHandler(pool: Pool<any>, handler: FailoverHandler): void;
|
|
16
|
+
/**
|
|
17
|
+
* Promisify a function call with optional timeout, metadata, and global cluster failover.
|
|
18
|
+
* @param pool - The pool of gRPC clients
|
|
6
19
|
* @param target - The name of the target function to call
|
|
7
|
-
* @param params - The parameters to pass to the target function
|
|
20
|
+
* @param params - The parameters to pass to the target function (may contain client_request_id or client-request-id)
|
|
8
21
|
* @param timeout - Optional timeout in milliseconds
|
|
22
|
+
* @param requestMetadata - Optional metadata to include in the request (e.g., client-request-id). If not provided, will be extracted from params automatically.
|
|
9
23
|
* @returns A Promise that resolves with the result of the target function call
|
|
10
24
|
*/
|
|
11
|
-
export declare function promisify(pool: Pool<any>, target: string, params: any, timeout: number
|
|
25
|
+
export declare function promisify(pool: Pool<any>, target: string, params: any, timeout: number, requestMetadata?: {
|
|
26
|
+
'client-request-id'?: string;
|
|
27
|
+
client_request_id?: string;
|
|
28
|
+
}): Promise<any>;
|
|
12
29
|
export declare const findKeyValue: (obj: KeyValuePair[], key: string) => string | number | undefined;
|
|
13
30
|
export declare const sleep: (time: number) => Promise<unknown>;
|
|
14
31
|
/**
|
|
@@ -34,3 +51,13 @@ export declare const getPKFieldExpr: (data: {
|
|
|
34
51
|
}) => string;
|
|
35
52
|
export declare const getSparseDim: (data: SparseFloatVector[]) => number;
|
|
36
53
|
export declare const getValidDataArray: (data: FieldData[], length: number) => boolean[];
|
|
54
|
+
/**
|
|
55
|
+
* Extracts request metadata (traceid) from request data.
|
|
56
|
+
* Supports both client_request_id and client-request-id formats.
|
|
57
|
+
* Priority: client_request_id > client-request-id (JavaScript/TypeScript convention)
|
|
58
|
+
* @param data - Request data that may contain traceid
|
|
59
|
+
* @returns Request metadata object or undefined if no traceid provided
|
|
60
|
+
*/
|
|
61
|
+
export declare const extractRequestMetadata: (data: any) => {
|
|
62
|
+
'client-request-id': string;
|
|
63
|
+
} | undefined;
|
|
@@ -9,33 +9,54 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getValidDataArray = exports.getSparseDim = exports.getPKFieldExpr = exports.getQueryIteratorExpr = exports.sleep = exports.findKeyValue = exports.promisify = void 0;
|
|
12
|
+
exports.extractRequestMetadata = exports.getValidDataArray = exports.getSparseDim = exports.getPKFieldExpr = exports.getQueryIteratorExpr = exports.sleep = exports.findKeyValue = exports.promisify = exports.setPoolFailoverHandler = exports.FAILOVER_HANDLER_KEY = void 0;
|
|
13
13
|
const __1 = require("../");
|
|
14
|
+
const logger_1 = require("./logger");
|
|
15
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
16
|
+
/** Well-known property key for attaching a failover handler to a pool. */
|
|
17
|
+
exports.FAILOVER_HANDLER_KEY = '__failoverHandler';
|
|
14
18
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param obj - The object containing the target function
|
|
17
|
-
* @param target - The name of the target function to call
|
|
18
|
-
* @param params - The parameters to pass to the target function
|
|
19
|
-
* @param timeout - Optional timeout in milliseconds
|
|
20
|
-
* @returns A Promise that resolves with the result of the target function call
|
|
19
|
+
* Attach a failover handler to a pool for global cluster support.
|
|
21
20
|
*/
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
function setPoolFailoverHandler(pool, handler) {
|
|
22
|
+
pool[exports.FAILOVER_HANDLER_KEY] = handler;
|
|
23
|
+
}
|
|
24
|
+
exports.setPoolFailoverHandler = setPoolFailoverHandler;
|
|
25
|
+
/**
|
|
26
|
+
* Check if an error is a gRPC UNAVAILABLE error.
|
|
27
|
+
*/
|
|
28
|
+
function isUnavailableError(err) {
|
|
29
|
+
return err && err.code === grpc_js_1.status.UNAVAILABLE;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Execute a single gRPC call via the pool.
|
|
33
|
+
*/
|
|
34
|
+
function executeCall(pool, target, params, timeout, requestMetadata) {
|
|
35
|
+
const t = timeout === 0 ? 1000 * 60 * 60 * 24 : timeout;
|
|
36
|
+
return (() => __awaiter(this, void 0, void 0, function* () {
|
|
27
37
|
const client = yield pool.acquire();
|
|
28
|
-
|
|
38
|
+
let finalRequestMetadata = requestMetadata;
|
|
39
|
+
if (!finalRequestMetadata && params) {
|
|
40
|
+
finalRequestMetadata = (0, exports.extractRequestMetadata)(params);
|
|
41
|
+
}
|
|
42
|
+
const metadata = finalRequestMetadata ? new grpc_js_1.Metadata() : undefined;
|
|
43
|
+
if (metadata && finalRequestMetadata) {
|
|
44
|
+
const clientRequestId = getClientRequestId(finalRequestMetadata);
|
|
45
|
+
if (clientRequestId) {
|
|
46
|
+
metadata.add(__1.METADATA.CLIENT_REQUEST_ID, String(clientRequestId));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
29
49
|
return new Promise((resolve, reject) => {
|
|
30
50
|
try {
|
|
31
|
-
|
|
32
|
-
|
|
51
|
+
const callOptions = { deadline: new Date(Date.now() + t) };
|
|
52
|
+
if (metadata) {
|
|
53
|
+
callOptions.metadata = metadata;
|
|
54
|
+
}
|
|
55
|
+
client[target](params, callOptions, (err, result) => {
|
|
33
56
|
if (err) {
|
|
34
|
-
// If there was an error, reject the Promise with the error
|
|
35
57
|
reject(err);
|
|
36
58
|
}
|
|
37
59
|
else {
|
|
38
|
-
// Otherwise, resolve the Promise with the result
|
|
39
60
|
resolve(result);
|
|
40
61
|
}
|
|
41
62
|
if (client) {
|
|
@@ -50,6 +71,36 @@ function promisify(pool, target, params, timeout) {
|
|
|
50
71
|
}
|
|
51
72
|
}
|
|
52
73
|
});
|
|
74
|
+
}))();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Promisify a function call with optional timeout, metadata, and global cluster failover.
|
|
78
|
+
* @param pool - The pool of gRPC clients
|
|
79
|
+
* @param target - The name of the target function to call
|
|
80
|
+
* @param params - The parameters to pass to the target function (may contain client_request_id or client-request-id)
|
|
81
|
+
* @param timeout - Optional timeout in milliseconds
|
|
82
|
+
* @param requestMetadata - Optional metadata to include in the request (e.g., client-request-id). If not provided, will be extracted from params automatically.
|
|
83
|
+
* @returns A Promise that resolves with the result of the target function call
|
|
84
|
+
*/
|
|
85
|
+
function promisify(pool, target, params, timeout, requestMetadata) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
try {
|
|
88
|
+
return yield executeCall(pool, target, params, timeout, requestMetadata);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
// Check for global cluster failover handler
|
|
92
|
+
const handler = pool[exports.FAILOVER_HANDLER_KEY];
|
|
93
|
+
if (handler && isUnavailableError(error)) {
|
|
94
|
+
logger_1.logger.debug(`\x1b[36m[Global]\x1b[0m UNAVAILABLE error on \x1b[1m${target}\x1b[0m, triggering failover handler`);
|
|
95
|
+
const newPool = yield handler(error);
|
|
96
|
+
if (newPool) {
|
|
97
|
+
logger_1.logger.debug(`\x1b[36m[Global]\x1b[0m Failover complete, retrying \x1b[1m${target}\x1b[0m with new pool`);
|
|
98
|
+
// Retry once with the new pool (after failover)
|
|
99
|
+
return yield executeCall(newPool, target, params, timeout, requestMetadata);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
53
104
|
});
|
|
54
105
|
}
|
|
55
106
|
exports.promisify = promisify;
|
|
@@ -122,4 +173,31 @@ const getValidDataArray = (data, length) => {
|
|
|
122
173
|
});
|
|
123
174
|
};
|
|
124
175
|
exports.getValidDataArray = getValidDataArray;
|
|
176
|
+
/**
|
|
177
|
+
* Extracts client request ID from metadata object with priority handling.
|
|
178
|
+
* Priority: client_request_id > client-request-id (JavaScript/TypeScript convention)
|
|
179
|
+
* @param metadata - Metadata object that may contain traceid
|
|
180
|
+
* @returns Client request ID as string or undefined if not found
|
|
181
|
+
*/
|
|
182
|
+
const getClientRequestId = (metadata) => {
|
|
183
|
+
if (!metadata) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
// Priority: client_request_id > client-request-id (JavaScript/TypeScript convention)
|
|
187
|
+
return metadata.client_request_id || metadata['client-request-id'];
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Extracts request metadata (traceid) from request data.
|
|
191
|
+
* Supports both client_request_id and client-request-id formats.
|
|
192
|
+
* Priority: client_request_id > client-request-id (JavaScript/TypeScript convention)
|
|
193
|
+
* @param data - Request data that may contain traceid
|
|
194
|
+
* @returns Request metadata object or undefined if no traceid provided
|
|
195
|
+
*/
|
|
196
|
+
const extractRequestMetadata = (data) => {
|
|
197
|
+
const clientRequestId = getClientRequestId(data);
|
|
198
|
+
return clientRequestId
|
|
199
|
+
? { 'client-request-id': String(clientRequestId) }
|
|
200
|
+
: undefined;
|
|
201
|
+
};
|
|
202
|
+
exports.extractRequestMetadata = extractRequestMetadata;
|
|
125
203
|
//# sourceMappingURL=Function.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Function.js","sourceRoot":"","sources":["../../../milvus/utils/Function.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"Function.js","sourceRoot":"","sources":["../../../milvus/utils/Function.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2BAQa;AACb,qCAAkC;AAElC,2CAA+D;AAY/D,0EAA0E;AAC7D,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAExD;;GAEG;AACH,SAAgB,sBAAsB,CACpC,IAAe,EACf,OAAwB;IAEvB,IAAY,CAAC,4BAAoB,CAAC,GAAG,OAAO,CAAC;AAChD,CAAC;AALD,wDAKC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,GAAQ;IAClC,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,gBAAU,CAAC,WAAW,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAClB,IAAe,EACf,MAAc,EACd,MAAW,EACX,OAAe,EACf,eAA8E;IAE9E,MAAM,CAAC,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAExD,OAAO,CAAC,GAAS,EAAE;QACjB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,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C;AAChB,CAAC,CAAC;AAXW,QAAA,sBAAsB,0BAWjC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ClusterCapability, ClusterInfo, GlobalTopology } from '../types/GlobalCluster';
|
|
2
|
+
export { ClusterCapability, ClusterInfo, GlobalTopology };
|
|
3
|
+
export declare const GLOBAL_CLUSTER_IDENTIFIER = "global-cluster";
|
|
4
|
+
export declare const DEFAULT_REFRESH_INTERVAL = 300000;
|
|
5
|
+
/**
|
|
6
|
+
* Check if a ClusterInfo is the primary (writable) cluster.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isPrimaryCluster(cluster: ClusterInfo): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Get the primary cluster from a topology.
|
|
11
|
+
* @throws Error if no primary cluster is found.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getPrimaryCluster(topology: GlobalTopology): ClusterInfo;
|
|
14
|
+
/**
|
|
15
|
+
* Check if the URI points to a global cluster endpoint.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isGlobalEndpoint(uri: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Fetch the global cluster topology from the REST API.
|
|
20
|
+
*
|
|
21
|
+
* @param globalEndpoint - The global cluster endpoint URL
|
|
22
|
+
* @param token - Authentication token
|
|
23
|
+
* @returns GlobalTopology object containing cluster information
|
|
24
|
+
* @throws Error if topology cannot be fetched after retries
|
|
25
|
+
*/
|
|
26
|
+
export declare function fetchTopology(globalEndpoint: string, token: string): Promise<GlobalTopology>;
|
|
27
|
+
/**
|
|
28
|
+
* Background refresher that periodically fetches the global cluster topology.
|
|
29
|
+
*/
|
|
30
|
+
export declare class TopologyRefresher {
|
|
31
|
+
private globalEndpoint;
|
|
32
|
+
private token;
|
|
33
|
+
private topology;
|
|
34
|
+
private refreshInterval;
|
|
35
|
+
private onTopologyChange?;
|
|
36
|
+
private intervalId;
|
|
37
|
+
private refreshing;
|
|
38
|
+
constructor(options: {
|
|
39
|
+
globalEndpoint: string;
|
|
40
|
+
token: string;
|
|
41
|
+
topology: GlobalTopology;
|
|
42
|
+
refreshInterval?: number;
|
|
43
|
+
onTopologyChange?: (topology: GlobalTopology) => void;
|
|
44
|
+
});
|
|
45
|
+
/** Start the background refresh interval. */
|
|
46
|
+
start(): void;
|
|
47
|
+
/** Stop the background refresh interval. */
|
|
48
|
+
stop(): void;
|
|
49
|
+
/** Check if the refresher is running. */
|
|
50
|
+
isRunning(): boolean;
|
|
51
|
+
/** Get the current topology. */
|
|
52
|
+
getTopology(): GlobalTopology;
|
|
53
|
+
/** Trigger an immediate topology refresh (debounced). */
|
|
54
|
+
triggerRefresh(): void;
|
|
55
|
+
private tryRefresh;
|
|
56
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TopologyRefresher = exports.fetchTopology = exports.isGlobalEndpoint = exports.getPrimaryCluster = exports.isPrimaryCluster = exports.DEFAULT_REFRESH_INTERVAL = exports.GLOBAL_CLUSTER_IDENTIFIER = exports.ClusterCapability = void 0;
|
|
13
|
+
const logger_1 = require("./logger");
|
|
14
|
+
const GlobalCluster_1 = require("../types/GlobalCluster");
|
|
15
|
+
Object.defineProperty(exports, "ClusterCapability", { enumerable: true, get: function () { return GlobalCluster_1.ClusterCapability; } });
|
|
16
|
+
// Identifier used in URIs to detect global cluster endpoints
|
|
17
|
+
exports.GLOBAL_CLUSTER_IDENTIFIER = 'global-cluster';
|
|
18
|
+
// Retry constants for topology fetch
|
|
19
|
+
const MAX_RETRIES = 3;
|
|
20
|
+
const BASE_DELAY = 1000; // ms
|
|
21
|
+
const MAX_DELAY = 10000; // ms
|
|
22
|
+
const REQUEST_TIMEOUT = 10000; // ms
|
|
23
|
+
// Default refresh interval for topology refresher
|
|
24
|
+
exports.DEFAULT_REFRESH_INTERVAL = 300000; // 5 minutes in ms
|
|
25
|
+
/**
|
|
26
|
+
* Check if a ClusterInfo is the primary (writable) cluster.
|
|
27
|
+
*/
|
|
28
|
+
function isPrimaryCluster(cluster) {
|
|
29
|
+
return (cluster.capability & GlobalCluster_1.ClusterCapability.WRITABLE) !== 0;
|
|
30
|
+
}
|
|
31
|
+
exports.isPrimaryCluster = isPrimaryCluster;
|
|
32
|
+
/**
|
|
33
|
+
* Get the primary cluster from a topology.
|
|
34
|
+
* @throws Error if no primary cluster is found.
|
|
35
|
+
*/
|
|
36
|
+
function getPrimaryCluster(topology) {
|
|
37
|
+
const primary = topology.clusters.find(isPrimaryCluster);
|
|
38
|
+
if (!primary) {
|
|
39
|
+
throw new Error('No primary cluster found in topology');
|
|
40
|
+
}
|
|
41
|
+
return primary;
|
|
42
|
+
}
|
|
43
|
+
exports.getPrimaryCluster = getPrimaryCluster;
|
|
44
|
+
/**
|
|
45
|
+
* Check if the URI points to a global cluster endpoint.
|
|
46
|
+
*/
|
|
47
|
+
function isGlobalEndpoint(uri) {
|
|
48
|
+
if (!uri)
|
|
49
|
+
return false;
|
|
50
|
+
return uri.toLowerCase().includes(exports.GLOBAL_CLUSTER_IDENTIFIER);
|
|
51
|
+
}
|
|
52
|
+
exports.isGlobalEndpoint = isGlobalEndpoint;
|
|
53
|
+
/**
|
|
54
|
+
* Parse the topology response from the REST API.
|
|
55
|
+
*/
|
|
56
|
+
function parseTopologyResponse(data) {
|
|
57
|
+
return {
|
|
58
|
+
version: parseInt(data.version, 10),
|
|
59
|
+
clusters: data.clusters.map(c => ({
|
|
60
|
+
clusterId: c.clusterId,
|
|
61
|
+
endpoint: c.endpoint,
|
|
62
|
+
capability: c.capability,
|
|
63
|
+
})),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Fetch the global cluster topology from the REST API.
|
|
68
|
+
*
|
|
69
|
+
* @param globalEndpoint - The global cluster endpoint URL
|
|
70
|
+
* @param token - Authentication token
|
|
71
|
+
* @returns GlobalTopology object containing cluster information
|
|
72
|
+
* @throws Error if topology cannot be fetched after retries
|
|
73
|
+
*/
|
|
74
|
+
function fetchTopology(globalEndpoint, token) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
// Build the topology URL
|
|
78
|
+
let endpoint = globalEndpoint.replace(/\/+$/, '');
|
|
79
|
+
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
|
|
80
|
+
endpoint = `https://${endpoint}`;
|
|
81
|
+
}
|
|
82
|
+
const url = `${endpoint}/${exports.GLOBAL_CLUSTER_IDENTIFIER}/topology`;
|
|
83
|
+
const headers = {
|
|
84
|
+
Authorization: `Bearer ${token}`,
|
|
85
|
+
};
|
|
86
|
+
logger_1.logger.debug(`\x1b[36m[Global]\x1b[0m Fetching topology from ${url}`);
|
|
87
|
+
let lastError = null;
|
|
88
|
+
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
89
|
+
try {
|
|
90
|
+
const controller = new AbortController();
|
|
91
|
+
const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT);
|
|
92
|
+
const response = yield fetch(url, {
|
|
93
|
+
headers,
|
|
94
|
+
signal: controller.signal,
|
|
95
|
+
});
|
|
96
|
+
clearTimeout(timeoutId);
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
const text = yield response.text();
|
|
99
|
+
const err = new Error(`Topology request failed with status ${response.status}: ${text}`);
|
|
100
|
+
// Only retry on 5xx server errors; 4xx are permanent (auth, bad request, etc.)
|
|
101
|
+
if (response.status >= 400 && response.status < 500) {
|
|
102
|
+
logger_1.logger.debug(`\x1b[36m[Global]\x1b[0m Topology fetch failed with ${response.status} (not retryable)`);
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
throw Object.assign(err, { retryable: true });
|
|
106
|
+
}
|
|
107
|
+
const result = yield response.json();
|
|
108
|
+
if (result.code !== undefined && result.code !== 0) {
|
|
109
|
+
// API-level error, don't retry
|
|
110
|
+
logger_1.logger.debug(`\x1b[36m[Global]\x1b[0m Topology API error code=${result.code}: ${result.message}`);
|
|
111
|
+
throw new Error(result.message || 'Unknown API error');
|
|
112
|
+
}
|
|
113
|
+
const topology = parseTopologyResponse(result.data);
|
|
114
|
+
logger_1.logger.debug(`\x1b[36m[Global]\x1b[0m Topology fetched: version=${topology.version}, clusters=${topology.clusters.length}, primary=${((_a = topology.clusters.find(c => isPrimaryCluster(c))) === null || _a === void 0 ? void 0 : _a.endpoint) || 'none'}`);
|
|
115
|
+
return topology;
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
// Only retry network errors, timeouts, and 5xx errors
|
|
119
|
+
if (!e.retryable && e.name !== 'AbortError' && !((_b = e.message) === null || _b === void 0 ? void 0 : _b.includes('fetch failed'))) {
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
122
|
+
lastError = e;
|
|
123
|
+
if (attempt < MAX_RETRIES - 1) {
|
|
124
|
+
const delay = Math.min(BASE_DELAY * Math.pow(2, attempt), MAX_DELAY);
|
|
125
|
+
const jitter = delay * 0.1 * Math.random();
|
|
126
|
+
logger_1.logger.warn(`Topology fetch attempt ${attempt + 1} failed: ${e.message}. Retrying in ${(delay + jitter).toFixed(0)}ms`);
|
|
127
|
+
yield new Promise(resolve => setTimeout(resolve, delay + jitter));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
throw new Error(`Failed to fetch global topology after ${MAX_RETRIES} attempts: ${lastError === null || lastError === void 0 ? void 0 : lastError.message}`);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
exports.fetchTopology = fetchTopology;
|
|
135
|
+
/**
|
|
136
|
+
* Background refresher that periodically fetches the global cluster topology.
|
|
137
|
+
*/
|
|
138
|
+
class TopologyRefresher {
|
|
139
|
+
constructor(options) {
|
|
140
|
+
var _a;
|
|
141
|
+
this.intervalId = null;
|
|
142
|
+
this.refreshing = false;
|
|
143
|
+
this.globalEndpoint = options.globalEndpoint;
|
|
144
|
+
this.token = options.token;
|
|
145
|
+
this.topology = options.topology;
|
|
146
|
+
this.refreshInterval =
|
|
147
|
+
(_a = options.refreshInterval) !== null && _a !== void 0 ? _a : exports.DEFAULT_REFRESH_INTERVAL;
|
|
148
|
+
this.onTopologyChange = options.onTopologyChange;
|
|
149
|
+
}
|
|
150
|
+
/** Start the background refresh interval. */
|
|
151
|
+
start() {
|
|
152
|
+
if (this.intervalId !== null)
|
|
153
|
+
return;
|
|
154
|
+
logger_1.logger.debug(`\x1b[36m[Global]\x1b[0m TopologyRefresher started, interval=${this.refreshInterval}ms`);
|
|
155
|
+
this.intervalId = setInterval(() => this.tryRefresh(), this.refreshInterval);
|
|
156
|
+
// Allow the Node.js process to exit even if the interval is still running
|
|
157
|
+
if (this.intervalId && typeof this.intervalId === 'object' && 'unref' in this.intervalId) {
|
|
158
|
+
this.intervalId.unref();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** Stop the background refresh interval. */
|
|
162
|
+
stop() {
|
|
163
|
+
if (this.intervalId !== null) {
|
|
164
|
+
clearInterval(this.intervalId);
|
|
165
|
+
this.intervalId = null;
|
|
166
|
+
logger_1.logger.debug(`\x1b[36m[Global]\x1b[0m TopologyRefresher stopped`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** Check if the refresher is running. */
|
|
170
|
+
isRunning() {
|
|
171
|
+
return this.intervalId !== null;
|
|
172
|
+
}
|
|
173
|
+
/** Get the current topology. */
|
|
174
|
+
getTopology() {
|
|
175
|
+
return this.topology;
|
|
176
|
+
}
|
|
177
|
+
/** Trigger an immediate topology refresh (debounced). */
|
|
178
|
+
triggerRefresh() {
|
|
179
|
+
if (this.refreshing) {
|
|
180
|
+
logger_1.logger.debug(`\x1b[36m[Global]\x1b[0m Topology refresh already in progress, skipping`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
logger_1.logger.debug(`\x1b[36m[Global]\x1b[0m Triggering immediate topology refresh`);
|
|
184
|
+
this.refreshing = true;
|
|
185
|
+
this.tryRefresh().finally(() => {
|
|
186
|
+
this.refreshing = false;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
tryRefresh() {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
try {
|
|
192
|
+
const newTopology = yield fetchTopology(this.globalEndpoint, this.token);
|
|
193
|
+
if (newTopology.version > this.topology.version) {
|
|
194
|
+
const oldVersion = this.topology.version;
|
|
195
|
+
this.topology = newTopology;
|
|
196
|
+
logger_1.logger.info(`Topology updated: version ${oldVersion} -> ${newTopology.version}`);
|
|
197
|
+
if (this.onTopologyChange) {
|
|
198
|
+
try {
|
|
199
|
+
this.onTopologyChange(newTopology);
|
|
200
|
+
}
|
|
201
|
+
catch (_a) {
|
|
202
|
+
logger_1.logger.warn('Topology change callback failed');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch (_b) {
|
|
208
|
+
logger_1.logger.warn('Topology refresh failed');
|
|
209
|
+
// Keep using cached topology, will retry next interval
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
exports.TopologyRefresher = TopologyRefresher;
|
|
215
|
+
//# sourceMappingURL=GlobalTopology.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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AAC,UAAU,GAAG,KAAK,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IAEa,UAAU;;YACtB,IAAI;gBACF,MAAM,WAAW,GAAG,MAAM,aAAa,CACrC,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,KAAK,CACX,CAAC;gBAEF,IAAI,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;oBAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;oBACzC,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAC;oBAC5B,eAAM,CAAC,IAAI,CACT,6BAA6B,UAAU,OAAO,WAAW,CAAC,OAAO,EAAE,CACpE,CAAC;oBAEF,IAAI,IAAI,CAAC,gBAAgB,EAAE;wBACzB,IAAI;4BACF,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;yBACpC;wBAAC,WAAM;4BACN,eAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;yBAChD;qBACF;iBACF;aACF;YAAC,WAAM;gBACN,eAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;gBACvC,uDAAuD;aACxD;QACH,CAAC;KAAA;CACF;AA1GD,8CA0GC"}
|
|
@@ -32,6 +32,12 @@ export declare const getRetryInterceptor: ({ maxRetries, retryDelay, clientId, }
|
|
|
32
32
|
retryDelay: number;
|
|
33
33
|
clientId: string;
|
|
34
34
|
}) => (options: any, nextCall: any) => InterceptingCall;
|
|
35
|
+
/**
|
|
36
|
+
* Returns a gRPC interceptor function that adds request-level metadata to outgoing requests.
|
|
37
|
+
* This interceptor automatically adds client-request-unixmsec timestamp to every request.
|
|
38
|
+
* The client-request-id should be passed via promisify's requestMetadata parameter.
|
|
39
|
+
*/
|
|
40
|
+
export declare const getRequestMetadataInterceptor: () => (options: any, nextCall: any) => InterceptingCall;
|
|
35
41
|
/**
|
|
36
42
|
* Returns a gRPC interceptor function that adds trace context to outgoing requests.
|
|
37
43
|
*/
|