Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ID field to search protobuf #768

Merged
merged 3 commits into from
Feb 12, 2024
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
29 changes: 7 additions & 22 deletions kaldb/src/main/java/com/slack/kaldb/chunk/ReadOnlyChunkImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.slack.kaldb.chunk;

import static com.slack.kaldb.server.KaldbConfig.DEFAULT_ZK_TIMEOUT_SECS;

import com.google.common.annotations.VisibleForTesting;
import com.slack.kaldb.blobfs.BlobFs;
import com.slack.kaldb.logstore.search.LogIndexSearcher;
Expand Down Expand Up @@ -48,10 +50,6 @@
public class ReadOnlyChunkImpl<T> implements Chunk<T> {

private static final Logger LOG = LoggerFactory.getLogger(ReadOnlyChunkImpl.class);

@Deprecated // replace with sync methods, which use DEFAULT_ZK_TIMEOUT_SECS where possible
private static final int TIMEOUT_MS = 5000;

private ChunkInfo chunkInfo;
private LogIndexSearcher<T> logSearcher;
private SearchMetadata searchMetadata;
Expand Down Expand Up @@ -174,20 +172,14 @@ public static SearchMetadata registerSearchMetadata(
snapshotName, cacheSearchContext.hostname),
snapshotName,
cacheSearchContext.toUrl());
searchMetadataStore
.createAsync(metadata)
.toCompletableFuture()
.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
searchMetadataStore.createSync(metadata);
return metadata;
}

private void unregisterSearchMetadata()
throws ExecutionException, InterruptedException, TimeoutException {
if (this.searchMetadata != null) {
searchMetadataStore
.deleteAsync(searchMetadata)
.toCompletableFuture()
.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
searchMetadataStore.deleteSync(searchMetadata);
}
}

Expand Down Expand Up @@ -265,15 +257,8 @@ private void handleChunkAssignment(CacheSlotMetadata cacheSlotMetadata) {

private SnapshotMetadata getSnapshotMetadata(String replicaId)
throws ExecutionException, InterruptedException, TimeoutException {
ReplicaMetadata replicaMetadata =
replicaMetadataStore
.findAsync(replicaId)
.toCompletableFuture()
.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
return snapshotMetadataStore
.findAsync(replicaMetadata.snapshotId)
.toCompletableFuture()
.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
ReplicaMetadata replicaMetadata = replicaMetadataStore.findSync(replicaId);
return snapshotMetadataStore.findSync(replicaMetadata.snapshotId);
}

// We lock access when manipulating the chunk, as the close()
Expand Down Expand Up @@ -319,7 +304,7 @@ private boolean setChunkMetadataState(
try {
cacheSlotMetadataStore
.updateNonFreeCacheSlotState(cacheSlotMetadata, newState)
.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
.get(DEFAULT_ZK_TIMEOUT_SECS, TimeUnit.MILLISECONDS);
return true;
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOG.error("Error setting chunk metadata state", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ public static FieldType fromSchemaDefinitionProto(
return FieldType.BOOLEAN;
} else if (protoSchemaDefinition.getType().equals(KaldbSearch.FieldType.DOUBLE)) {
return FieldType.DOUBLE;
} else if (protoSchemaDefinition.getType().equals(KaldbSearch.FieldType.ID)) {
return FieldType.ID;
} else {
throw new IllegalArgumentException(
String.format("Field type %s is not a supported type", protoSchemaDefinition.getType()));
Expand All @@ -678,6 +680,8 @@ public static KaldbSearch.SchemaDefinition toSchemaDefinitionProto(FieldType fie
schemaBuilder.setType(KaldbSearch.FieldType.BOOLEAN);
} else if (fieldType.equals(FieldType.DOUBLE)) {
schemaBuilder.setType(KaldbSearch.FieldType.DOUBLE);
} else if (fieldType.equals(FieldType.ID)) {
schemaBuilder.setType(KaldbSearch.FieldType.ID);
} else {
throw new IllegalArgumentException(
String.format("Field type %s is not a supported type", fieldType));
Expand Down
1 change: 1 addition & 0 deletions kaldb/src/main/proto/kaldb_search.proto
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ enum FieldType {
FLOAT = 4;
BOOLEAN = 5;
DOUBLE = 6;
ID = 7;
}

message SchemaDefinition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,16 @@ public void shouldConvertSchemaDefinitionToFromProto() {
KaldbSearch.SchemaDefinition.newBuilder()
.setType(KaldbSearch.FieldType.INTEGER)
.build());

assertThat(
SearchResultUtils.fromSchemaDefinitionProto(
KaldbSearch.SchemaDefinition.newBuilder()
.setType(KaldbSearch.FieldType.ID)
.build()))
.isEqualTo(FieldType.ID);
assertThat(SearchResultUtils.toSchemaDefinitionProto(FieldType.ID))
.isEqualTo(
KaldbSearch.SchemaDefinition.newBuilder().setType(KaldbSearch.FieldType.ID).build());
}

@Test
Expand Down
Loading