Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,11 @@ public GetPersistentSegmentInfoResp getPersistentSegmentInfo(MilvusServiceGrpc.M
.segmentID(info.getSegmentID())
.collectionID(info.getCollectionID())
.partitionID(info.getPartitionID())
.collectionName(collectionName)
.numOfRows(info.getNumRows())
.state(info.getState().name())
.level(info.getLevel().name())
.storageVersion(info.getStorageVersion())
.isSorted(info.getIsSorted())
.build());
});
Expand Down Expand Up @@ -413,6 +415,7 @@ public GetQuerySegmentInfoResp getQuerySegmentInfo(MilvusServiceGrpc.MilvusServi
.state(info.getState().name())
.level(info.getLevel().name())
.nodeIDs(info.getNodeIdsList())
.storageVersion(info.getStorageVersion())
.isSorted(info.getIsSorted())
.build());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@ public static class PersistentSegmentInfo {
private Long segmentID;
private Long collectionID;
private Long partitionID;
private String collectionName;
private Long numOfRows;
private String state;
private String level;
private Long storageVersion;
private Boolean isSorted;

private PersistentSegmentInfo(PersistentSegmentInfoBuilder builder) {
this.segmentID = builder.segmentID;
this.collectionID = builder.collectionID;
this.partitionID = builder.partitionID;
this.collectionName = builder.collectionName;
this.numOfRows = builder.numOfRows;
this.state = builder.state;
this.level = builder.level;
this.storageVersion = builder.storageVersion;
this.isSorted = builder.isSorted;
}

Expand Down Expand Up @@ -70,6 +74,14 @@ public void setPartitionID(Long partitionID) {
this.partitionID = partitionID;
}

public String getCollectionName() {
return collectionName;
}

public void setCollectionName(String collectionName) {
this.collectionName = collectionName;
}

public Long getNumOfRows() {
return numOfRows;
}
Expand All @@ -94,6 +106,14 @@ public void setLevel(String level) {
this.level = level;
}

public Long getStorageVersion() {
return storageVersion;
}

public void setStorageVersion(Long storageVersion) {
this.storageVersion = storageVersion;
}

public Boolean getIsSorted() {
return isSorted;
}
Expand All @@ -108,9 +128,11 @@ public String toString() {
"segmentID=" + segmentID +
", collectionID=" + collectionID +
", partitionID=" + partitionID +
", collectionName='" + collectionName + '\'' +
", numOfRows=" + numOfRows +
", state='" + state + '\'' +
", level='" + level + '\'' +
", storageVersion=" + storageVersion +
", isSorted=" + isSorted +
'}';
}
Expand All @@ -119,9 +141,11 @@ public static class PersistentSegmentInfoBuilder {
private Long segmentID;
private Long collectionID;
private Long partitionID;
private String collectionName;
private Long numOfRows;
private String state;
private String level;
private Long storageVersion;
private Boolean isSorted;

public PersistentSegmentInfoBuilder segmentID(Long segmentID) {
Expand All @@ -139,6 +163,11 @@ public PersistentSegmentInfoBuilder partitionID(Long partitionID) {
return this;
}

public PersistentSegmentInfoBuilder collectionName(String collectionName) {
this.collectionName = collectionName;
return this;
}

public PersistentSegmentInfoBuilder numOfRows(Long numOfRows) {
this.numOfRows = numOfRows;
return this;
Expand All @@ -154,6 +183,11 @@ public PersistentSegmentInfoBuilder level(String level) {
return this;
}

public PersistentSegmentInfoBuilder storageVersion(Long storageVersion) {
this.storageVersion = storageVersion;
return this;
}

public PersistentSegmentInfoBuilder isSorted(Boolean isSorted) {
this.isSorted = isSorted;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static class QuerySegmentInfo {
private String state;
private String level;
private List<Long> nodeIDs;
private Long storageVersion;
private Boolean isSorted;

private QuerySegmentInfo(QuerySegmentInfoBuilder builder) {
Expand All @@ -47,6 +48,7 @@ private QuerySegmentInfo(QuerySegmentInfoBuilder builder) {
this.state = builder.state;
this.level = builder.level;
this.nodeIDs = builder.nodeIDs;
this.storageVersion = builder.storageVersion;
this.isSorted = builder.isSorted;
}

Expand Down Expand Up @@ -134,6 +136,14 @@ public void setNodeIDs(List<Long> nodeIDs) {
this.nodeIDs = nodeIDs;
}

public Long getStorageVersion() {
return storageVersion;
}

public void setStorageVersion(Long storageVersion) {
this.storageVersion = storageVersion;
}

public Boolean getIsSorted() {
return isSorted;
}
Expand All @@ -155,6 +165,7 @@ public String toString() {
", state='" + state + '\'' +
", level='" + level + '\'' +
", nodeIDs=" + nodeIDs +
", storageVersion=" + storageVersion +
", isSorted=" + isSorted +
'}';
}
Expand All @@ -170,6 +181,7 @@ public static class QuerySegmentInfoBuilder {
private String state;
private String level;
private List<Long> nodeIDs = new ArrayList<>();
private Long storageVersion;
private Boolean isSorted;

public QuerySegmentInfoBuilder segmentID(Long segmentID) {
Expand Down Expand Up @@ -222,6 +234,11 @@ public QuerySegmentInfoBuilder nodeIDs(List<Long> nodeIDs) {
return this;
}

public QuerySegmentInfoBuilder storageVersion(Long storageVersion) {
this.storageVersion = storageVersion;
return this;
}

public QuerySegmentInfoBuilder isSorted(Boolean isSorted) {
this.isSorted = isSorted;
return this;
Expand Down
30 changes: 30 additions & 0 deletions sdk-core/src/test/java/io/milvus/v2/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,36 @@ public void setUp() {

// utility api
when(blockingStub.flush(any())).thenReturn(FlushResponse.newBuilder().setStatus(successStatus).build());
when(blockingStub.getPersistentSegmentInfo(any())).thenReturn(GetPersistentSegmentInfoResponse.newBuilder()
.setStatus(successStatus)
.addInfos(PersistentSegmentInfo.newBuilder()
.setSegmentID(1L)
.setCollectionID(2L)
.setPartitionID(3L)
.setNumRows(4L)
.setState(SegmentState.Flushed)
.setLevel(SegmentLevel.L1)
.setStorageVersion(5L)
.setIsSorted(true)
.build())
.build());
when(blockingStub.getQuerySegmentInfo(any())).thenReturn(GetQuerySegmentInfoResponse.newBuilder()
.setStatus(successStatus)
.addInfos(QuerySegmentInfo.newBuilder()
.setSegmentID(6L)
.setCollectionID(7L)
.setPartitionID(8L)
.setMemSize(9L)
.setNumRows(10L)
.setIndexName("test_index")
.setIndexID(11L)
.setState(SegmentState.Sealed)
.setLevel(SegmentLevel.L1)
.addNodeIds(12L)
.setStorageVersion(13L)
.setIsSorted(true)
.build())
.build());
when(blockingStub.createAlias(any())).thenReturn(successStatus);
when(blockingStub.dropAlias(any())).thenReturn(successStatus);
when(blockingStub.alterAlias(any())).thenReturn(successStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,25 +369,35 @@ void testFloatVectors() {
.build());

// master branch, getPersistentSegmentInfo cannot ensure the segment is returned after flush()
while (true) {
// get persistent segment info
GetPersistentSegmentInfoResp pSegInfo = client.getPersistentSegmentInfo(GetPersistentSegmentInfoReq.builder()
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(30);
GetPersistentSegmentInfoResp pSegInfo = null;
while (System.currentTimeMillis() < deadline) {
pSegInfo = client.getPersistentSegmentInfo(GetPersistentSegmentInfoReq.builder()
.collectionName(randomCollectionName)
.build());
if (pSegInfo.getSegmentInfos().size() == 0) {
continue;
if (!pSegInfo.getSegmentInfos().isEmpty()) {
break;
}
try {
TimeUnit.MILLISECONDS.sleep(200);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Assertions.fail("Interrupted while waiting for persistent segment info in collection: " + randomCollectionName);
}
Assertions.assertEquals(1, pSegInfo.getSegmentInfos().size());
GetPersistentSegmentInfoResp.PersistentSegmentInfo pInfo = pSegInfo.getSegmentInfos().get(0);
Assertions.assertTrue(pInfo.getSegmentID() > 0L);
Assertions.assertTrue(pInfo.getCollectionID() > 0L);
Assertions.assertTrue(pInfo.getPartitionID() > 0L);
Assertions.assertEquals(count, pInfo.getNumOfRows());
Assertions.assertEquals("Flushed", pInfo.getState());
Assertions.assertEquals("L1", pInfo.getLevel());
// Assertions.assertFalse(pInfo.getIsSorted());
break;
}
Assertions.assertNotNull(pSegInfo, "Timed out waiting for persistent segment info response");
Assertions.assertFalse(pSegInfo.getSegmentInfos().isEmpty(), "Timed out waiting for persistent segment info in collection: " + randomCollectionName);
Assertions.assertEquals(1, pSegInfo.getSegmentInfos().size());
GetPersistentSegmentInfoResp.PersistentSegmentInfo pInfo = pSegInfo.getSegmentInfos().get(0);
Assertions.assertTrue(pInfo.getSegmentID() > 0L);
Assertions.assertTrue(pInfo.getCollectionID() > 0L);
Assertions.assertTrue(pInfo.getPartitionID() > 0L);
Assertions.assertEquals(count, pInfo.getNumOfRows());
Assertions.assertEquals(randomCollectionName, pInfo.getCollectionName());
Assertions.assertEquals("Flushed", pInfo.getState());
Assertions.assertEquals("L1", pInfo.getLevel());
Assertions.assertNotNull(pInfo.getStorageVersion());
// Assertions.assertFalse(pInfo.getIsSorted());

// compact
CompactResp compactResp = client.compact(CompactReq.builder()
Expand Down Expand Up @@ -432,6 +442,7 @@ void testFloatVectors() {
Assertions.assertEquals("L1", qInfo.getLevel());
Assertions.assertEquals(1, qInfo.getNodeIDs().size());
Assertions.assertTrue(qInfo.getNodeIDs().get(0) > 0L);
Assertions.assertNotNull(qInfo.getStorageVersion());
Assertions.assertTrue(qInfo.getIsSorted());

// create partition, upsert one row to the partition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private static void randomCallMethod(Field field, Method method, Object callInst
String obj = randomStr.generate(10);
randomValues.put(field.getName(), obj);
} else if (fieldType == Long.class || fieldType.getName().equals("long")) {
Long obj = (long) random.nextInt(RANDOM_BOUND);
Long obj = (long) random.nextInt(RANDOM_BOUND) + 1;
randomValues.put(field.getName(), obj);
} else if (fieldType == Integer.class || fieldType.getName().equals("int")) {
Integer obj = random.nextInt(RANDOM_BOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
import io.milvus.v2.BaseTest;
import io.milvus.v2.service.utility.request.*;
import io.milvus.v2.service.utility.response.DescribeAliasResp;
import io.milvus.v2.service.utility.response.GetPersistentSegmentInfoResp;
import io.milvus.v2.service.utility.response.GetQuerySegmentInfoResp;
import io.milvus.v2.service.utility.response.ListAliasResp;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class UtilityTest extends BaseTest {
Logger logger = LoggerFactory.getLogger(UtilityTest.class);

Expand Down Expand Up @@ -71,4 +76,46 @@ void listAliases() {
.build();
ListAliasResp statusR = client_v2.listAliases(req);
}
}

@Test
void testGetPersistentSegmentInfo() {
GetPersistentSegmentInfoResp resp = client_v2.getPersistentSegmentInfo(GetPersistentSegmentInfoReq.builder()
.collectionName("test")
.build());

assertEquals(1, resp.getSegmentInfos().size());
GetPersistentSegmentInfoResp.PersistentSegmentInfo info = resp.getSegmentInfos().get(0);
assertEquals(1L, info.getSegmentID());
assertEquals(2L, info.getCollectionID());
assertEquals(3L, info.getPartitionID());
assertEquals("test", info.getCollectionName());
assertEquals(4L, info.getNumOfRows());
assertEquals("Flushed", info.getState());
assertEquals("L1", info.getLevel());
assertEquals(5L, info.getStorageVersion());
assertTrue(info.getIsSorted());
}

@Test
void testGetQuerySegmentInfo() {
GetQuerySegmentInfoResp resp = client_v2.getQuerySegmentInfo(GetQuerySegmentInfoReq.builder()
.collectionName("test")
.build());

assertEquals(1, resp.getSegmentInfos().size());
GetQuerySegmentInfoResp.QuerySegmentInfo info = resp.getSegmentInfos().get(0);
assertEquals(6L, info.getSegmentID());
assertEquals(7L, info.getCollectionID());
assertEquals(8L, info.getPartitionID());
assertEquals(9L, info.getMemSize());
assertEquals(10L, info.getNumOfRows());
assertEquals("test_index", info.getIndexName());
assertEquals(11L, info.getIndexID());
assertEquals("Sealed", info.getState());
assertEquals("L1", info.getLevel());
assertEquals(1, info.getNodeIDs().size());
assertEquals(12L, info.getNodeIDs().get(0));
assertEquals(13L, info.getStorageVersion());
assertTrue(info.getIsSorted());
}
}
Loading