@@ -68,22 +68,31 @@ public abstract class AbstractMilvusGrpcClient implements MilvusClient {
6868 protected static final Logger logger = LoggerFactory .getLogger (AbstractMilvusGrpcClient .class );
6969 protected LogLevel logLevel = LogLevel .Info ;
7070
71- private ConcurrentHashMap <String , DescribeCollectionResponse > cacheCollectionInfo = new ConcurrentHashMap <>();
71+ protected ConcurrentHashMap <String , DescribeCollectionResponse > cacheCollectionInfo = new ConcurrentHashMap <>();
7272
7373 protected abstract MilvusServiceGrpc .MilvusServiceBlockingStub blockingStub ();
7474
7575 protected abstract MilvusServiceGrpc .MilvusServiceFutureStub futureStub ();
7676
7777 protected abstract boolean clientIsReady ();
7878
79+ protected abstract String currentDbName ();
80+
81+ private String actualDbName (String overwriteName ) {
82+ if (StringUtils .isNotEmpty (overwriteName )) {
83+ return overwriteName ;
84+ }
85+ return currentDbName ();
86+ }
87+
7988 /**
8089 * This method is for insert/upsert requests to reduce the rpc call of describeCollection()
8190 * Always try to get the collection info from cache.
8291 * If the cache doesn't have the collection info, call describeCollection() and cache it.
8392 * If insert/upsert get server error, remove the cached collection info.
8493 */
8594 private DescribeCollectionResponse getCollectionInfo (String databaseName , String collectionName , boolean forceUpdate ) {
86- String key = combineCacheKey ( databaseName , collectionName );
95+ String key = GTsDict . CombineCollectionName ( actualDbName ( databaseName ) , collectionName );
8796 DescribeCollectionResponse info = cacheCollectionInfo .get (key );
8897 if (info == null || forceUpdate ) {
8998 String msg = String .format ("Fail to describe collection '%s'" , collectionName );
@@ -104,17 +113,6 @@ private DescribeCollectionResponse getCollectionInfo(String databaseName, String
104113 return info ;
105114 }
106115
107- private String combineCacheKey (String databaseName , String collectionName ) {
108- if (collectionName == null || StringUtils .isBlank (collectionName )) {
109- throw new ParamException ("Collection name is empty, not able to get collection info." );
110- }
111- String key = collectionName ;
112- if (StringUtils .isNotEmpty (databaseName )) {
113- key = String .format ("%s|%s" , databaseName , collectionName );
114- }
115- return key ;
116- }
117-
118116 /**
119117 * insert/upsert return an error, but is not a RateLimit error,
120118 * clean the cache so that the next insert will call describeCollection() to get the latest info.
@@ -127,7 +125,8 @@ private void cleanCacheIfFailed(Status status, String databaseName, String colle
127125 }
128126
129127 private void removeCollectionCache (String databaseName , String collectionName ) {
130- cacheCollectionInfo .remove (combineCacheKey (databaseName , collectionName ));
128+ String key = GTsDict .CombineCollectionName (actualDbName (databaseName ), collectionName );
129+ cacheCollectionInfo .remove (key );
131130 }
132131
133132 private void waitForLoadingCollection (String databaseName , String collectionName , List <String > partitionNames ,
@@ -1570,22 +1569,25 @@ public R<MutationResult> delete(@NonNull DeleteParam requestParam) {
15701569 }
15711570
15721571 logDebug (requestParam .toString ());
1573- String title = String .format ("DeleteRequest collectionName:%s" , requestParam .getCollectionName ());
1572+ String dbName = requestParam .getDatabaseName ();
1573+ String collectionName = requestParam .getCollectionName ();
1574+ String title = String .format ("DeleteRequest collectionName:%s" , collectionName );
15741575
15751576 try {
15761577 DeleteRequest .Builder builder = DeleteRequest .newBuilder ()
15771578 .setBase (MsgBase .newBuilder ().setMsgType (MsgType .Delete ).build ())
1578- .setCollectionName (requestParam . getCollectionName () )
1579+ .setCollectionName (collectionName )
15791580 .setPartitionName (requestParam .getPartitionName ())
15801581 .setExpr (requestParam .getExpr ());
15811582
1582- if (StringUtils .isNotEmpty (requestParam . getDatabaseName () )) {
1583- builder .setDbName (requestParam . getDatabaseName () );
1583+ if (StringUtils .isNotEmpty (dbName )) {
1584+ builder .setDbName (dbName );
15841585 }
15851586
15861587 MutationResult response = blockingStub ().delete (builder .build ());
15871588 handleResponse (title , response .getStatus ());
1588- GTsDict .getInstance ().updateCollectionTs (requestParam .getCollectionName (), response .getTimestamp ());
1589+ String key = GTsDict .CombineCollectionName (actualDbName (dbName ), collectionName );
1590+ GTsDict .getInstance ().updateCollectionTs (key , response .getTimestamp ());
15891591 return R .success (response );
15901592 } catch (StatusRuntimeException e ) {
15911593 logError ("{} RPC failed! Exception:{}" , title , e );
@@ -1642,7 +1644,8 @@ public R<MutationResult> insert(@NonNull InsertParam requestParam) {
16421644 // if illegal data, server fails to process insert, else succeed
16431645 cleanCacheIfFailed (response .getStatus (), dbName , collectionName );
16441646 handleResponse (title , response .getStatus ());
1645- GTsDict .getInstance ().updateCollectionTs (collectionName , response .getTimestamp ());
1647+ String key = GTsDict .CombineCollectionName (actualDbName (dbName ), collectionName );
1648+ GTsDict .getInstance ().updateCollectionTs (key , response .getTimestamp ());
16461649 return R .success (response );
16471650 } catch (StatusRuntimeException e ) {
16481651 logError ("{} RPC failed! Exception:{}" , title , e );
@@ -1691,7 +1694,8 @@ public void onSuccess(MutationResult result) {
16911694 cleanCacheIfFailed (result .getStatus (), dbName , collectionName );
16921695 if (result .getStatus ().getErrorCode () == ErrorCode .Success ) {
16931696 logDebug ("{} successfully!" , title );
1694- GTsDict .getInstance ().updateCollectionTs (collectionName , result .getTimestamp ());
1697+ String key = GTsDict .CombineCollectionName (actualDbName (dbName ), collectionName );
1698+ GTsDict .getInstance ().updateCollectionTs (key , result .getTimestamp ());
16951699 } else {
16961700 logError ("{} failed:\n {}" , title , result .getStatus ().getReason ());
16971701 }
@@ -1763,7 +1767,8 @@ public R<MutationResult> upsert(UpsertParam requestParam) {
17631767 // if illegal data, server fails to process upsert, else succeed
17641768 cleanCacheIfFailed (response .getStatus (), dbName , collectionName );
17651769 handleResponse (title , response .getStatus ());
1766- GTsDict .getInstance ().updateCollectionTs (collectionName , response .getTimestamp ());
1770+ String key = GTsDict .CombineCollectionName (actualDbName (dbName ), collectionName );
1771+ GTsDict .getInstance ().updateCollectionTs (key , response .getTimestamp ());
17671772 return R .success (response );
17681773 } catch (StatusRuntimeException e ) {
17691774 logError ("{} RPC failed! Exception:{}" , title , e );
@@ -1811,7 +1816,8 @@ public void onSuccess(MutationResult result) {
18111816 cleanCacheIfFailed (result .getStatus (), dbName , collectionName );
18121817 if (result .getStatus ().getErrorCode () == ErrorCode .Success ) {
18131818 logDebug ("{} successfully!" , title );
1814- GTsDict .getInstance ().updateCollectionTs (collectionName , result .getTimestamp ());
1819+ String key = GTsDict .CombineCollectionName (actualDbName (dbName ), collectionName );
1820+ GTsDict .getInstance ().updateCollectionTs (key , result .getTimestamp ());
18151821 } else {
18161822 logError ("{} failed:\n {}" , title , result .getStatus ().getReason ());
18171823 }
0 commit comments