|
@@ -71,9 +71,11 @@ export class CollectionsService {
|
|
async createCollection(clientId: string, data: CreateCollectionReq) {
|
|
async createCollection(clientId: string, data: CreateCollectionReq) {
|
|
const { milvusClient } = clientCache.get(clientId);
|
|
const { milvusClient } = clientCache.get(clientId);
|
|
const res = await milvusClient.createCollection(data);
|
|
const res = await milvusClient.createCollection(data);
|
|
- const newCollection = (await this.getAllCollections(clientId, [
|
|
|
|
- data.collection_name,
|
|
|
|
- ])) as CollectionFullObject[];
|
|
|
|
|
|
+ const newCollection = (await this.getAllCollections(
|
|
|
|
+ clientId,
|
|
|
|
+ [data.collection_name],
|
|
|
|
+ data.db_name
|
|
|
|
+ )) as CollectionFullObject[];
|
|
|
|
|
|
throwErrorFromSDK(res);
|
|
throwErrorFromSDK(res);
|
|
return newCollection[0];
|
|
return newCollection[0];
|
|
@@ -159,9 +161,11 @@ export class CollectionsService {
|
|
const res = await milvusClient.renameCollection(data);
|
|
const res = await milvusClient.renameCollection(data);
|
|
throwErrorFromSDK(res);
|
|
throwErrorFromSDK(res);
|
|
|
|
|
|
- const newCollection = (await this.getAllCollections(clientId, [
|
|
|
|
- data.new_collection_name,
|
|
|
|
- ])) as CollectionFullObject[];
|
|
|
|
|
|
+ const newCollection = (await this.getAllCollections(
|
|
|
|
+ clientId,
|
|
|
|
+ [data.new_collection_name],
|
|
|
|
+ data.db_name
|
|
|
|
+ )) as CollectionFullObject[];
|
|
|
|
|
|
return newCollection[0];
|
|
return newCollection[0];
|
|
}
|
|
}
|
|
@@ -171,9 +175,11 @@ export class CollectionsService {
|
|
const res = await milvusClient.alterCollection(data);
|
|
const res = await milvusClient.alterCollection(data);
|
|
throwErrorFromSDK(res);
|
|
throwErrorFromSDK(res);
|
|
|
|
|
|
- const newCollection = (await this.getAllCollections(clientId, [
|
|
|
|
- data.collection_name,
|
|
|
|
- ])) as CollectionFullObject[];
|
|
|
|
|
|
+ const newCollection = (await this.getAllCollections(
|
|
|
|
+ clientId,
|
|
|
|
+ [data.collection_name],
|
|
|
|
+ data.db_name
|
|
|
|
+ )) as CollectionFullObject[];
|
|
|
|
|
|
return newCollection[0];
|
|
return newCollection[0];
|
|
}
|
|
}
|
|
@@ -193,13 +199,25 @@ export class CollectionsService {
|
|
return data.collection_name;
|
|
return data.collection_name;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async loadCollectionAsync(clientId: string, data: LoadCollectionReq) {
|
|
|
|
+ const { milvusClient } = clientCache.get(clientId);
|
|
|
|
+ const res = await milvusClient.loadCollectionAsync(data);
|
|
|
|
+ throwErrorFromSDK(res);
|
|
|
|
+
|
|
|
|
+ return data.collection_name;
|
|
|
|
+ }
|
|
|
|
+
|
|
async releaseCollection(clientId: string, data: ReleaseLoadCollectionReq) {
|
|
async releaseCollection(clientId: string, data: ReleaseLoadCollectionReq) {
|
|
const { milvusClient } = clientCache.get(clientId);
|
|
const { milvusClient } = clientCache.get(clientId);
|
|
const res = await milvusClient.releaseCollection(data);
|
|
const res = await milvusClient.releaseCollection(data);
|
|
throwErrorFromSDK(res);
|
|
throwErrorFromSDK(res);
|
|
|
|
|
|
// emit update to client
|
|
// emit update to client
|
|
- this.updateCollectionsDetails(clientId, [data.collection_name]);
|
|
|
|
|
|
+ this.updateCollectionsDetails(
|
|
|
|
+ clientId,
|
|
|
|
+ [data.collection_name],
|
|
|
|
+ data.db_name
|
|
|
|
+ );
|
|
|
|
|
|
return data.collection_name;
|
|
return data.collection_name;
|
|
}
|
|
}
|
|
@@ -251,7 +269,6 @@ export class CollectionsService {
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
async deleteEntities(clientId: string, data: DeleteEntitiesReq) {
|
|
async deleteEntities(clientId: string, data: DeleteEntitiesReq) {
|
|
const { milvusClient } = clientCache.get(clientId);
|
|
const { milvusClient } = clientCache.get(clientId);
|
|
const res = await milvusClient.deleteEntities(data);
|
|
const res = await milvusClient.deleteEntities(data);
|
|
@@ -298,9 +315,11 @@ export class CollectionsService {
|
|
const res = await milvusClient.createAlias(data);
|
|
const res = await milvusClient.createAlias(data);
|
|
throwErrorFromSDK(res);
|
|
throwErrorFromSDK(res);
|
|
|
|
|
|
- const newCollection = (await this.getAllCollections(clientId, [
|
|
|
|
- data.collection_name,
|
|
|
|
- ])) as CollectionFullObject[];
|
|
|
|
|
|
+ const newCollection = (await this.getAllCollections(
|
|
|
|
+ clientId,
|
|
|
|
+ [data.collection_name],
|
|
|
|
+ data.db_name
|
|
|
|
+ )) as CollectionFullObject[];
|
|
|
|
|
|
return newCollection[0];
|
|
return newCollection[0];
|
|
}
|
|
}
|
|
@@ -312,23 +331,21 @@ export class CollectionsService {
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
- async dropAlias(
|
|
|
|
- clientId: string,
|
|
|
|
- collection_name: string,
|
|
|
|
- data: DropAliasReq
|
|
|
|
- ) {
|
|
|
|
|
|
+ async dropAlias(clientId: string, collection_name: string, data: any) {
|
|
const { milvusClient } = clientCache.get(clientId);
|
|
const { milvusClient } = clientCache.get(clientId);
|
|
const res = await milvusClient.dropAlias(data);
|
|
const res = await milvusClient.dropAlias(data);
|
|
throwErrorFromSDK(res);
|
|
throwErrorFromSDK(res);
|
|
|
|
|
|
- const newCollection = (await this.getAllCollections(clientId, [
|
|
|
|
- collection_name,
|
|
|
|
- ])) as CollectionFullObject[];
|
|
|
|
|
|
+ const newCollection = (await this.getAllCollections(
|
|
|
|
+ clientId,
|
|
|
|
+ [collection_name],
|
|
|
|
+ data.db_name
|
|
|
|
+ )) as CollectionFullObject[];
|
|
|
|
|
|
return newCollection[0];
|
|
return newCollection[0];
|
|
}
|
|
}
|
|
|
|
|
|
- async getReplicas(clientId: string, data: GetReplicasDto) {
|
|
|
|
|
|
+ async getReplicas(clientId: string, data: any) {
|
|
const { milvusClient } = clientCache.get(clientId);
|
|
const { milvusClient } = clientCache.get(clientId);
|
|
const res = await milvusClient.getReplicas(data);
|
|
const res = await milvusClient.getReplicas(data);
|
|
return res;
|
|
return res;
|
|
@@ -356,7 +373,8 @@ export class CollectionsService {
|
|
clientId: string,
|
|
clientId: string,
|
|
collection: CollectionData,
|
|
collection: CollectionData,
|
|
loadCollection: CollectionData,
|
|
loadCollection: CollectionData,
|
|
- lazy: boolean = false
|
|
|
|
|
|
+ lazy: boolean = false,
|
|
|
|
+ database?: string
|
|
) {
|
|
) {
|
|
const { collectionsQueue } = clientCache.get(clientId);
|
|
const { collectionsQueue } = clientCache.get(clientId);
|
|
if (lazy) {
|
|
if (lazy) {
|
|
@@ -382,6 +400,7 @@ export class CollectionsService {
|
|
// get collection schema and properties
|
|
// get collection schema and properties
|
|
const collectionInfo = await this.describeCollection(clientId, {
|
|
const collectionInfo = await this.describeCollection(clientId, {
|
|
collection_name: collection.name,
|
|
collection_name: collection.name,
|
|
|
|
+ db_name: database,
|
|
});
|
|
});
|
|
|
|
|
|
// get collection statistic data
|
|
// get collection statistic data
|
|
@@ -390,6 +409,7 @@ export class CollectionsService {
|
|
try {
|
|
try {
|
|
const res = await this.count(clientId, {
|
|
const res = await this.count(clientId, {
|
|
collection_name: collection.name,
|
|
collection_name: collection.name,
|
|
|
|
+ db_name: database,
|
|
});
|
|
});
|
|
count = res.rowCount;
|
|
count = res.rowCount;
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -407,6 +427,7 @@ export class CollectionsService {
|
|
replicas = loadCollection
|
|
replicas = loadCollection
|
|
? await this.getReplicas(clientId, {
|
|
? await this.getReplicas(clientId, {
|
|
collectionID: collectionInfo.collectionID,
|
|
collectionID: collectionInfo.collectionID,
|
|
|
|
+ db_name: database,
|
|
})
|
|
})
|
|
: replicas;
|
|
: replicas;
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -446,7 +467,8 @@ export class CollectionsService {
|
|
// get all collections details
|
|
// get all collections details
|
|
async getAllCollections(
|
|
async getAllCollections(
|
|
clientId: string,
|
|
clientId: string,
|
|
- collections: string[] = []
|
|
|
|
|
|
+ collections: string[] = [],
|
|
|
|
+ database?: string
|
|
): Promise<CollectionObject[]> {
|
|
): Promise<CollectionObject[]> {
|
|
const currentClient = clientCache.get(clientId);
|
|
const currentClient = clientCache.get(clientId);
|
|
|
|
|
|
@@ -457,10 +479,13 @@ export class CollectionsService {
|
|
}
|
|
}
|
|
|
|
|
|
// get all collections(name, timestamp, id)
|
|
// get all collections(name, timestamp, id)
|
|
- const allCollections = await this.showCollections(clientId);
|
|
|
|
|
|
+ const allCollections = await this.showCollections(clientId, {
|
|
|
|
+ db_name: database,
|
|
|
|
+ });
|
|
// get all loaded collection
|
|
// get all loaded collection
|
|
const loadedCollections = await this.showCollections(clientId, {
|
|
const loadedCollections = await this.showCollections(clientId, {
|
|
type: ShowCollectionsType.Loaded,
|
|
type: ShowCollectionsType.Loaded,
|
|
|
|
+ db_name: database,
|
|
});
|
|
});
|
|
|
|
|
|
// data container
|
|
// data container
|
|
@@ -491,7 +516,8 @@ export class CollectionsService {
|
|
clientId,
|
|
clientId,
|
|
collection,
|
|
collection,
|
|
loadedCollection,
|
|
loadedCollection,
|
|
- !notLazy
|
|
|
|
|
|
+ !notLazy,
|
|
|
|
+ database
|
|
)
|
|
)
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -504,7 +530,11 @@ export class CollectionsService {
|
|
if (q.isObseleted) {
|
|
if (q.isObseleted) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- await this.updateCollectionsDetails(clientId, collectionsToGet);
|
|
|
|
|
|
+ await this.updateCollectionsDetails(
|
|
|
|
+ clientId,
|
|
|
|
+ collectionsToGet,
|
|
|
|
+ database
|
|
|
|
+ );
|
|
},
|
|
},
|
|
5
|
|
5
|
|
);
|
|
);
|
|
@@ -516,32 +546,37 @@ export class CollectionsService {
|
|
|
|
|
|
// update collections details
|
|
// update collections details
|
|
// send new info to the client
|
|
// send new info to the client
|
|
- async updateCollectionsDetails(clientId: string, collections: string[]) {
|
|
|
|
|
|
+ async updateCollectionsDetails(
|
|
|
|
+ clientId: string,
|
|
|
|
+ collections: string[],
|
|
|
|
+ database: string
|
|
|
|
+ ) {
|
|
try {
|
|
try {
|
|
// get current socket
|
|
// get current socket
|
|
const socketClient = clients.get(clientId);
|
|
const socketClient = clients.get(clientId);
|
|
// get collections
|
|
// get collections
|
|
- const res = await this.getAllCollections(clientId, collections);
|
|
|
|
|
|
+ const res = await this.getAllCollections(clientId, collections, database);
|
|
|
|
|
|
// emit event to current client
|
|
// emit event to current client
|
|
if (socketClient) {
|
|
if (socketClient) {
|
|
- socketClient.emit(WS_EVENTS.COLLECTION_UPDATE, res);
|
|
|
|
|
|
+ socketClient.emit(WS_EVENTS.COLLECTION_UPDATE, { collections: res });
|
|
}
|
|
}
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.log('ignore queue error');
|
|
console.log('ignore queue error');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- async getLoadedCollections(clientId: string) {
|
|
|
|
|
|
+ async getLoadedCollections(clientId: string, db_name?: string) {
|
|
const data = [];
|
|
const data = [];
|
|
const res = await this.showCollections(clientId, {
|
|
const res = await this.showCollections(clientId, {
|
|
type: ShowCollectionsType.Loaded,
|
|
type: ShowCollectionsType.Loaded,
|
|
|
|
+ db_name,
|
|
});
|
|
});
|
|
if (res.data.length > 0) {
|
|
if (res.data.length > 0) {
|
|
for (const item of res.data) {
|
|
for (const item of res.data) {
|
|
const { id, name } = item;
|
|
const { id, name } = item;
|
|
|
|
|
|
- const count = this.count(clientId, { collection_name: name });
|
|
|
|
|
|
+ const count = this.count(clientId, { collection_name: name, db_name });
|
|
data.push({
|
|
data.push({
|
|
id,
|
|
id,
|
|
collection_name: name,
|
|
collection_name: name,
|
|
@@ -557,12 +592,12 @@ export class CollectionsService {
|
|
* Get collections statistics data
|
|
* Get collections statistics data
|
|
* @returns {collectionCount:number, totalData:number}
|
|
* @returns {collectionCount:number, totalData:number}
|
|
*/
|
|
*/
|
|
- async getStatistics(clientId: string) {
|
|
|
|
|
|
+ async getStatistics(clientId: string, db_name?: string) {
|
|
const data = {
|
|
const data = {
|
|
collectionCount: 0,
|
|
collectionCount: 0,
|
|
totalData: 0,
|
|
totalData: 0,
|
|
} as StatisticsObject;
|
|
} as StatisticsObject;
|
|
- const res = await this.showCollections(clientId);
|
|
|
|
|
|
+ const res = await this.showCollections(clientId, { db_name });
|
|
data.collectionCount = res.data.length;
|
|
data.collectionCount = res.data.length;
|
|
if (res.data.length > 0) {
|
|
if (res.data.length > 0) {
|
|
for (const item of res.data) {
|
|
for (const item of res.data) {
|
|
@@ -570,6 +605,7 @@ export class CollectionsService {
|
|
clientId,
|
|
clientId,
|
|
{
|
|
{
|
|
collection_name: item.name,
|
|
collection_name: item.name,
|
|
|
|
+ db_name,
|
|
}
|
|
}
|
|
);
|
|
);
|
|
const rowCount = findKeyValue(collectionStatistics.stats, ROW_COUNT);
|
|
const rowCount = findKeyValue(collectionStatistics.stats, ROW_COUNT);
|
|
@@ -584,10 +620,11 @@ export class CollectionsService {
|
|
*/
|
|
*/
|
|
async importSample(
|
|
async importSample(
|
|
clientId: string,
|
|
clientId: string,
|
|
- { collection_name, size, download, format }: ImportSampleDto
|
|
|
|
|
|
+ { collection_name, size, download, format, db_name }: ImportSampleDto
|
|
) {
|
|
) {
|
|
const collectionInfo = await this.describeCollection(clientId, {
|
|
const collectionInfo = await this.describeCollection(clientId, {
|
|
collection_name,
|
|
collection_name,
|
|
|
|
+ db_name,
|
|
});
|
|
});
|
|
const fields_data = genRows(
|
|
const fields_data = genRows(
|
|
collectionInfo.schema.fields,
|
|
collectionInfo.schema.fields,
|
|
@@ -605,7 +642,11 @@ export class CollectionsService {
|
|
return { sampleFile };
|
|
return { sampleFile };
|
|
} else {
|
|
} else {
|
|
// Otherwise, insert the data into the collection
|
|
// Otherwise, insert the data into the collection
|
|
- return await this.insert(clientId, { collection_name, fields_data });
|
|
|
|
|
|
+ return await this.insert(clientId, {
|
|
|
|
+ collection_name,
|
|
|
|
+ fields_data,
|
|
|
|
+ db_name,
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -650,6 +691,7 @@ export class CollectionsService {
|
|
async duplicateCollection(clientId: string, data: RenameCollectionReq) {
|
|
async duplicateCollection(clientId: string, data: RenameCollectionReq) {
|
|
const collection = await this.describeCollection(clientId, {
|
|
const collection = await this.describeCollection(clientId, {
|
|
collection_name: data.collection_name,
|
|
collection_name: data.collection_name,
|
|
|
|
+ db_name: data.db_name,
|
|
});
|
|
});
|
|
|
|
|
|
const createCollectionParams: CreateCollectionReq = {
|
|
const createCollectionParams: CreateCollectionReq = {
|
|
@@ -678,6 +720,7 @@ export class CollectionsService {
|
|
collection_name: data.collection_name,
|
|
collection_name: data.collection_name,
|
|
filter:
|
|
filter:
|
|
pkType === 'Int64' ? `${pkField} >= ${MIN_INT64}` : `${pkField} != ''`,
|
|
pkType === 'Int64' ? `${pkField} >= ${MIN_INT64}` : `${pkField} != ''`,
|
|
|
|
+ db_name: data.db_name,
|
|
});
|
|
});
|
|
|
|
|
|
return res;
|
|
return res;
|
|
@@ -692,9 +735,11 @@ export class CollectionsService {
|
|
indexCache.delete(key);
|
|
indexCache.delete(key);
|
|
|
|
|
|
// fetch new collections
|
|
// fetch new collections
|
|
- const newCollection = (await this.getAllCollections(clientId, [
|
|
|
|
- data.collection_name,
|
|
|
|
- ])) as CollectionFullObject[];
|
|
|
|
|
|
+ const newCollection = (await this.getAllCollections(
|
|
|
|
+ clientId,
|
|
|
|
+ [data.collection_name],
|
|
|
|
+ data.db_name
|
|
|
|
+ )) as CollectionFullObject[];
|
|
|
|
|
|
throwErrorFromSDK(res);
|
|
throwErrorFromSDK(res);
|
|
return newCollection[0];
|
|
return newCollection[0];
|
|
@@ -760,9 +805,11 @@ export class CollectionsService {
|
|
// clear cache;
|
|
// clear cache;
|
|
indexCache.delete(key);
|
|
indexCache.delete(key);
|
|
// fetch new collections
|
|
// fetch new collections
|
|
- const newCollection = (await this.getAllCollections(clientId, [
|
|
|
|
- data.collection_name,
|
|
|
|
- ])) as CollectionFullObject[];
|
|
|
|
|
|
+ const newCollection = (await this.getAllCollections(
|
|
|
|
+ clientId,
|
|
|
|
+ [data.collection_name],
|
|
|
|
+ data.db_name
|
|
|
|
+ )) as CollectionFullObject[];
|
|
|
|
|
|
return newCollection[0];
|
|
return newCollection[0];
|
|
}
|
|
}
|