@@ -98,12 +98,16 @@ public Void createCollection(MilvusServiceGrpc.MilvusServiceBlockingStub blockin
9898 CreateIndexReq createIndexReq = CreateIndexReq .builder ()
9999 .indexParams (Collections .singletonList (indexParam ))
100100 .collectionName (request .getCollectionName ())
101+ .sync (false )
101102 .build ();
102103 indexService .createIndex (blockingStub , createIndexReq );
103104 //load collection, set async to true since no need to wait loading progress
104105 try {
105106 //TimeUnit.MILLISECONDS.sleep(1000);
106- loadCollection (blockingStub , LoadCollectionReq .builder ().async (true ).collectionName (request .getCollectionName ()).build ());
107+ loadCollection (blockingStub , LoadCollectionReq .builder ()
108+ .sync (false )
109+ .collectionName (request .getCollectionName ())
110+ .build ());
107111 } catch (Exception e ) {
108112 throw new MilvusClientException (ErrorCode .SERVER_ERROR , "Load collection failed: " + e );
109113 }
@@ -157,11 +161,15 @@ public Void createCollectionWithSchema(MilvusServiceGrpc.MilvusServiceBlockingSt
157161 CreateIndexReq createIndexReq = CreateIndexReq .builder ()
158162 .indexParams (Collections .singletonList (indexParam ))
159163 .collectionName (request .getCollectionName ())
164+ .sync (false )
160165 .build ();
161166 indexService .createIndex (blockingStub , createIndexReq );
162167 }
163168 //load collection, set async to true since no need to wait loading progress
164- loadCollection (blockingStub , LoadCollectionReq .builder ().async (true ).collectionName (request .getCollectionName ()).build ());
169+ loadCollection (blockingStub , LoadCollectionReq .builder ()
170+ .sync (false )
171+ .collectionName (request .getCollectionName ())
172+ .build ());
165173 }
166174
167175 return null ;
@@ -187,10 +195,6 @@ public Void dropCollection(MilvusServiceGrpc.MilvusServiceBlockingStub blockingS
187195 Status status = blockingStub .dropCollection (dropCollectionRequest );
188196 rpcUtils .handleResponse (title , status );
189197
190- if (request .getAsync ()) {
191- WaitForDropCollection (blockingStub , request );
192- }
193-
194198 return null ;
195199 }
196200
@@ -289,7 +293,7 @@ public Void loadCollection(MilvusServiceGrpc.MilvusServiceBlockingStub blockingS
289293 .build ();
290294 Status status = blockingStub .loadCollection (loadCollectionRequest );
291295 rpcUtils .handleResponse (title , status );
292- if (! request .getAsync ()) {
296+ if (request .getSync ()) {
293297 WaitForLoadCollection (blockingStub , request .getCollectionName (), request .getTimeout ());
294298 }
295299
@@ -304,7 +308,7 @@ public Void refreshLoad(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub
304308 .build ();
305309 Status status = blockingStub .loadCollection (loadCollectionRequest );
306310 rpcUtils .handleResponse (title , status );
307- if (request .getAsync ()) {
311+ if (request .getSync ()) {
308312 WaitForLoadCollection (blockingStub , request .getCollectionName (), request .getTimeout ());
309313 }
310314
@@ -318,9 +322,6 @@ public Void releaseCollection(MilvusServiceGrpc.MilvusServiceBlockingStub blocki
318322 .build ();
319323 Status status = blockingStub .releaseCollection (releaseCollectionRequest );
320324 rpcUtils .handleResponse (title , status );
321- if (request .getAsync ()) {
322- waitForCollectionRelease (blockingStub , request );
323- }
324325
325326 return null ;
326327 }
@@ -407,75 +408,28 @@ public DescribeReplicasResp describeReplicas(MilvusServiceGrpc.MilvusServiceBloc
407408 .build ();
408409 }
409410
410- public void waitForCollectionRelease (MilvusServiceGrpc .MilvusServiceBlockingStub blockingStub , ReleaseCollectionReq request ) {
411- boolean isLoaded = true ;
412- long startTime = System .currentTimeMillis (); // Capture start time/ Timeout in milliseconds (60 seconds)
413-
414- while (isLoaded ) {
415- // Call the getLoadState method
416- isLoaded = getLoadState (blockingStub , GetLoadStateReq .builder ().collectionName (request .getCollectionName ()).build ());
417- if (isLoaded ) {
418- // Check if timeout is exceeded
419- if (System .currentTimeMillis () - startTime > request .getTimeout ()) {
420- throw new MilvusClientException (ErrorCode .SERVER_ERROR , "Load collection timeout" );
421- }
422- // Wait for a certain period before checking again
423- try {
424- Thread .sleep (500 ); // Sleep for 0.5 second. Adjust this value as needed.
425- } catch (InterruptedException e ) {
426- Thread .currentThread ().interrupt ();
427- System .out .println ("Thread was interrupted, Failed to complete operation" );
428- return ; // or handle interruption appropriately
429- }
430- }
431- }
432- }
433-
434411 private void WaitForLoadCollection (MilvusServiceGrpc .MilvusServiceBlockingStub blockingStub ,
435412 String collectionName , long timeoutMs ) {
436- boolean isLoaded = false ;
437413 long startTime = System .currentTimeMillis (); // Capture start time/ Timeout in milliseconds (60 seconds)
438414
439- while (! isLoaded ) {
415+ while (true ) {
440416 // Call the getLoadState method
441- isLoaded = getLoadState (blockingStub , GetLoadStateReq .builder ().collectionName (collectionName ).build ());
442- if (!isLoaded ) {
443- // Check if timeout is exceeded
444- if (System .currentTimeMillis () - startTime > timeoutMs ) {
445- throw new MilvusClientException (ErrorCode .SERVER_ERROR , "Load collection timeout" );
446- }
447- // Wait for a certain period before checking again
448- try {
449- Thread .sleep (500 ); // Sleep for 0.5 second. Adjust this value as needed.
450- } catch (InterruptedException e ) {
451- Thread .currentThread ().interrupt ();
452- System .out .println ("Thread was interrupted, Failed to complete operation" );
453- return ; // or handle interruption appropriately
454- }
417+ boolean isLoaded = getLoadState (blockingStub , GetLoadStateReq .builder ().collectionName (collectionName ).build ());
418+ if (isLoaded ) {
419+ return ;
455420 }
456- }
457- }
458-
459- private void WaitForDropCollection (MilvusServiceGrpc .MilvusServiceBlockingStub blockingStub , DropCollectionReq request ) {
460- boolean hasCollection = true ;
461- long startTime = System .currentTimeMillis (); // Capture start time/ Timeout in milliseconds (60 seconds)
462421
463- while (hasCollection ) {
464- // Call the getLoadState method
465- hasCollection = hasCollection (blockingStub , HasCollectionReq .builder ().collectionName (request .getCollectionName ()).build ());
466- if (hasCollection ) {
467- // Check if timeout is exceeded
468- if (System .currentTimeMillis () - startTime > request .getTimeout ()) {
469- throw new MilvusClientException (ErrorCode .SERVER_ERROR , "drop collection timeout" );
470- }
471- // Wait for a certain period before checking again
472- try {
473- Thread .sleep (500 ); // Sleep for 0.5 second. Adjust this value as needed.
474- } catch (InterruptedException e ) {
475- Thread .currentThread ().interrupt ();
476- System .out .println ("Thread was interrupted, Failed to complete operation" );
477- return ; // or handle interruption appropriately
478- }
422+ // Check if timeout is exceeded
423+ if (System .currentTimeMillis () - startTime > timeoutMs ) {
424+ throw new MilvusClientException (ErrorCode .SERVER_ERROR , "Load collection timeout" );
425+ }
426+ // Wait for a certain period before checking again
427+ try {
428+ Thread .sleep (500 ); // Sleep for 0.5 second. Adjust this value as needed.
429+ } catch (InterruptedException e ) {
430+ Thread .currentThread ().interrupt ();
431+ System .out .println ("Thread was interrupted, Failed to complete operation" );
432+ return ; // or handle interruption appropriately
479433 }
480434 }
481435 }
0 commit comments