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 explicit throw methods for getting index state and fields #762

Merged
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 @@ -41,7 +41,7 @@ public ServerCodec(IndexStateManager stateManager) {
public PostingsFormat getPostingsFormatForField(String field) {
IndexState state = stateManager.getCurrent();
try {
FieldDef fd = state.getField(field);
FieldDef fd = state.getFieldOrThrow(field);
if (fd instanceof IndexableFieldDef indexableFieldDef) {
PostingsFormat postingsFormat = indexableFieldDef.getPostingsFormat();
if (postingsFormat != null) {
Expand All @@ -64,7 +64,7 @@ public PostingsFormat getPostingsFormatForField(String field) {
public DocValuesFormat getDocValuesFormatForField(String field) {
IndexState state = stateManager.getCurrent();
try {
FieldDef fd = state.getField(field);
FieldDef fd = state.getFieldOrThrow(field);
if (fd instanceof IndexableFieldDef indexableFieldDef) {
DocValuesFormat docValuesFormat = indexableFieldDef.getDocValuesFormat();
if (docValuesFormat != null) {
Expand All @@ -85,7 +85,7 @@ public DocValuesFormat getDocValuesFormatForField(String field) {
public KnnVectorsFormat getKnnVectorsFormatForField(String field) {
IndexState state = stateManager.getCurrent();
try {
FieldDef fd = state.getField(field);
FieldDef fd = state.getFieldOrThrow(field);
if (fd instanceof VectorFieldDef vectorFieldDef) {
KnnVectorsFormat vectorsFormat = vectorFieldDef.getVectorsFormat();
if (vectorsFormat != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static Iterable<FacetResult> facetTopDocsSample(
private static FacetResult facetFromTopDocs(
TopDocs topDocs, Facet facet, IndexState indexState, IndexSearcher searcher)
throws IOException {
FieldDef fieldDef = indexState.getField(facet.getDim());
FieldDef fieldDef = indexState.getFieldOrThrow(facet.getDim());
if (!(fieldDef instanceof IndexableFieldDef)) {
throw new IllegalArgumentException(
"Sampling facet field must be indexable: " + facet.getDim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public StreamObserver<AddDocumentRequest> handle(

private int getAddDocumentsMaxBufferLen(String indexName) {
try {
return getGlobalState().getIndex(indexName).getAddDocumentsMaxBufferLen();
return getGlobalState().getIndexOrThrow(indexName).getAddDocumentsMaxBufferLen();
} catch (Exception e) {
String error =
String.format("Index %s does not exist, unable to add documents", indexName);
Expand Down Expand Up @@ -327,7 +327,7 @@ private static void parseOneField(
DocumentsContext documentsContext,
IndexState indexState)
throws AddDocumentHandlerException {
parseMultiValueField(indexState.getField(fieldName), value, documentsContext);
parseMultiValueField(indexState.getFieldOrThrow(fieldName), value, documentsContext);
}

/** Parse MultiValuedField for a single field, which is always a List<String>. */
Expand Down Expand Up @@ -401,7 +401,7 @@ public long runIndexingJob() throws Exception {
IdFieldDef idFieldDef;

try {
indexState = globalState.getIndex(this.indexName);
indexState = globalState.getIndexOrThrow(this.indexName);
shardState = indexState.getShard(0);
idFieldDef = indexState.getIdFieldDef().orElse(null);
for (AddDocumentRequest addDocumentRequest : addDocumentRequestList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void handle(
AddReplicaRequest addReplicaRequest, StreamObserver<AddReplicaResponse> responseObserver) {
try {
IndexStateManager indexStateManager =
getGlobalState().getIndexStateManager(addReplicaRequest.getIndexName());
getGlobalState().getIndexStateManagerOrThrow(addReplicaRequest.getIndexName());
checkIndexId(addReplicaRequest.getIndexId(), indexStateManager.getIndexId(), verifyIndexId);

IndexState indexState = indexStateManager.getCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void handle(
logger.info("Received backup warming queries request: {}", request);
String index = request.getIndex();
try {
IndexState indexState = getGlobalState().getIndex(index);
IndexState indexState = getGlobalState().getIndexOrThrow(index);
Warmer warmer = indexState.getWarmer();
if (warmer == null) {
logger.warn("Unable to backup warming queries as warmer not found for index: {}", index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void handle(CommitRequest commitRequest, StreamObserver<CommitResponse> r
() -> {
try {
IndexState indexState =
getGlobalState().getIndex(commitRequest.getIndexName());
getGlobalState().getIndexOrThrow(commitRequest.getIndexName());
long gen = indexState.commit();
CommitResponse reply =
CommitResponse.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public CopyFilesHandler(GlobalState globalState, boolean verifyIndexId) {
public void handle(CopyFiles request, StreamObserver<TransferStatus> responseObserver) {
try {
IndexStateManager indexStateManager =
getGlobalState().getIndexStateManager(request.getIndexName());
getGlobalState().getIndexStateManagerOrThrow(request.getIndexName());
checkIndexId(request.getIndexId(), indexStateManager.getIndexId(), verifyIndexId);

IndexState indexState = indexStateManager.getCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public void handle(
CreateSnapshotRequest createSnapshotRequest,
StreamObserver<CreateSnapshotResponse> responseObserver) {
try {
IndexState indexState = getGlobalState().getIndex(createSnapshotRequest.getIndexName());
IndexState indexState =
getGlobalState().getIndexOrThrow(createSnapshotRequest.getIndexName());
CreateSnapshotResponse reply = createSnapshot(indexState, createSnapshotRequest);
logger.info(String.format("CreateSnapshotHandler returned results %s", reply.toString()));
responseObserver.onNext(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public void handle(
StreamObserver<DeleteAllDocumentsResponse> responseObserver) {
logger.info("Received delete all documents request: {}", deleteAllDocumentsRequest);
try {
IndexState indexState = getGlobalState().getIndex(deleteAllDocumentsRequest.getIndexName());
IndexState indexState =
getGlobalState().getIndexOrThrow(deleteAllDocumentsRequest.getIndexName());
DeleteAllDocumentsResponse reply = handle(indexState);
logger.info("DeleteAllDocumentsHandler returned " + reply);
responseObserver.onNext(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void handle(
DeleteByQueryRequest deleteByQueryRequest,
StreamObserver<AddDocumentResponse> responseObserver) {
try {
IndexState indexState = getGlobalState().getIndex(deleteByQueryRequest.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(deleteByQueryRequest.getIndexName());
AddDocumentResponse reply = handle(indexState, deleteByQueryRequest);
logger.debug("DeleteDocumentsHandler returned " + reply.toString());
responseObserver.onNext(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public DeleteDocumentsHandler(GlobalState globalState) {
public void handle(
AddDocumentRequest addDocumentRequest, StreamObserver<AddDocumentResponse> responseObserver) {
try {
IndexState indexState = getGlobalState().getIndex(addDocumentRequest.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(addDocumentRequest.getIndexName());
AddDocumentResponse reply = handleInternal(indexState, addDocumentRequest);
logger.debug("DeleteDocumentsHandler returned {}", reply);
responseObserver.onNext(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void handle(
DeleteIndexRequest deleteIndexRequest, StreamObserver<DeleteIndexResponse> responseObserver) {
logger.info("Received delete index request: {}", deleteIndexRequest);
try {
IndexState indexState = getGlobalState().getIndex(deleteIndexRequest.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(deleteIndexRequest.getIndexName());
DeleteIndexResponse reply = handle(indexState);
logger.info("DeleteIndexHandler returned " + reply);
responseObserver.onNext(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void handle(
}

try {
IndexState indexState = getGlobalState().getIndex(forceMergeRequest.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(forceMergeRequest.getIndexName());
ShardState shardState = indexState.getShards().get(0);
logger.info("Beginning force merge deletes for index: {}", forceMergeRequest.getIndexName());
shardState.writer.forceMergeDeletes(forceMergeRequest.getDoWait());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void handle(
}

try {
IndexState indexState = getGlobalState().getIndex(forceMergeRequest.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(forceMergeRequest.getIndexName());
ShardState shardState = indexState.getShards().get(0);
logger.info("Beginning force merge for index: {}", forceMergeRequest.getIndexName());
shardState.writer.forceMerge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void handle(
try {
Set<Long> snapshotGens =
getGlobalState()
.getIndex(request.getIndexName())
.getIndexOrThrow(request.getIndexName())
.getShard(0)
.snapshotGenToVersion
.keySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public GetNodesInfoHandler(GlobalState globalState) {
public void handle(
GetNodesRequest getNodesRequest, StreamObserver<GetNodesResponse> responseObserver) {
try {
IndexState indexState = getGlobalState().getIndex(getNodesRequest.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(getNodesRequest.getIndexName());
GetNodesResponse reply = handle(indexState);
logger.debug("GetNodesInfoHandler returned GetNodeResponse of size " + reply.getNodesCount());
responseObserver.onNext(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public GetStateHandler(GlobalState globalState) {
@Override
public void handle(StateRequest request, StreamObserver<StateResponse> responseObserver) {
try {
IndexState indexState = getGlobalState().getIndex(request.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(request.getIndexName());
StateResponse reply = handle(indexState);
logger.debug("GetStateHandler returned " + reply);
responseObserver.onNext(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static IndicesResponse getIndicesResponse(GlobalState globalState) throw
Set<String> indexNames = globalState.getIndexNames();
IndicesResponse.Builder builder = IndicesResponse.newBuilder();
for (String indexName : indexNames) {
IndexState indexState = globalState.getIndex(indexName);
IndexState indexState = globalState.getIndexOrThrow(indexName);
if (indexState.isStarted()) {
StatsResponse statsResponse = StatsHandler.process(indexState);
builder.addIndicesResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void handle(
LiveSettingsRequest req, StreamObserver<LiveSettingsResponse> responseObserver) {
logger.info("Received live settings request: {}", req);
try {
IndexState indexState = getGlobalState().getIndex(req.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(req.getIndexName());
LiveSettingsResponse reply = handle(indexState, req);
logger.info("LiveSettingsHandler returned {}", reply.toString());
responseObserver.onNext(reply);
Expand Down Expand Up @@ -80,7 +80,7 @@ private LiveSettingsResponse handleAsLiveSettingsV2(
IndexStateManager indexStateManager;
try {
indexStateManager =
indexStateIn.getGlobalState().getIndexStateManager(indexStateIn.getName());
indexStateIn.getGlobalState().getIndexStateManagerOrThrow(indexStateIn.getName());
} catch (IOException e) {
throw new RuntimeException("Unable to get index state manager", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void handle(
logger.info("Received live settings V2 request: {}", req);
try {
IndexStateManager indexStateManager =
getGlobalState().getIndexStateManager(req.getIndexName());
getGlobalState().getIndexStateManagerOrThrow(req.getIndexName());
LiveSettingsV2Response reply = handle(indexStateManager, req);
logger.info("LiveSettingsV2Handler returned " + JsonFormat.printer().print(reply));
responseObserver.onNext(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public NewNRTPointHandler(GlobalState globalState, boolean verifyIndexId) {
public void handle(NewNRTPoint request, StreamObserver<TransferStatus> responseObserver) {
try {
IndexStateManager indexStateManager =
getGlobalState().getIndexStateManager(request.getIndexName());
getGlobalState().getIndexStateManagerOrThrow(request.getIndexName());
checkIndexId(request.getIndexId(), indexStateManager.getIndexId(), verifyIndexId);

IndexState indexState = indexStateManager.getCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public void handle(
try {
List<String> indicesNotStarted = new ArrayList<>();
for (String indexName : indexNames) {
// The ready endpoint should skip loading index state
IndexState indexState = getGlobalState().getIndex(indexName, true);
IndexState indexState = getGlobalState().getIndexOrThrow(indexName);
if (!indexState.isStarted()) {
indicesNotStarted.add(indexName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public RecvCopyStateHandler(GlobalState globalState, boolean verifyIndexId) {
public void handle(CopyStateRequest request, StreamObserver<CopyState> responseObserver) {
try {
IndexStateManager indexStateManager =
getGlobalState().getIndexStateManager(request.getIndexName());
getGlobalState().getIndexStateManagerOrThrow(request.getIndexName());
checkIndexId(request.getIndexId(), indexStateManager.getIndexId(), verifyIndexId);

IndexState indexState = indexStateManager.getCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public RecvRawFileHandler(GlobalState globalState, boolean verifyIndexId) {
public void handle(FileInfo fileInfoRequest, StreamObserver<RawFileChunk> responseObserver) {
try {
IndexStateManager indexStateManager =
getGlobalState().getIndexStateManager(fileInfoRequest.getIndexName());
getGlobalState().getIndexStateManagerOrThrow(fileInfoRequest.getIndexName());
checkIndexId(fileInfoRequest.getIndexId(), indexStateManager.getIndexId(), verifyIndexId);

IndexState indexState = indexStateManager.getCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void onNext(FileInfo fileInfoRequest) {
if (indexState == null) {
// Start transfer
IndexStateManager indexStateManager =
getGlobalState().getIndexStateManager(fileInfoRequest.getIndexName());
getGlobalState().getIndexStateManagerOrThrow(fileInfoRequest.getIndexName());
checkIndexId(
fileInfoRequest.getIndexId(), indexStateManager.getIndexId(), verifyIndexId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public RefreshHandler(GlobalState globalState) {
public void handle(
RefreshRequest refreshRequest, StreamObserver<RefreshResponse> responseObserver) {
try {
IndexState indexState = getGlobalState().getIndex(refreshRequest.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(refreshRequest.getIndexName());
final ShardState shardState = indexState.getShard(0);
long t0 = System.nanoTime();
shardState.maybeRefreshBlocking();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void handle(
logger.info("Received register fields request: {}", fieldDefRequest);
try {
IndexStateManager indexStateManager =
getGlobalState().getIndexStateManager(fieldDefRequest.getIndexName());
getGlobalState().getIndexStateManagerOrThrow(fieldDefRequest.getIndexName());
String updatedFields = indexStateManager.updateFields(fieldDefRequest.getFieldList());
FieldDefResponse reply = FieldDefResponse.newBuilder().setResponse(updatedFields).build();
logger.info("RegisterFieldsHandler registered fields " + reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void handle(
ReleaseSnapshotRequest releaseSnapshotRequest,
StreamObserver<ReleaseSnapshotResponse> responseObserver) {
try {
IndexState indexState = getGlobalState().getIndex(releaseSnapshotRequest.getIndexName());
IndexState indexState =
getGlobalState().getIndexOrThrow(releaseSnapshotRequest.getIndexName());
ReleaseSnapshotResponse reply = handle(indexState, releaseSnapshotRequest);
logger.info(String.format("CreateSnapshotHandler returned results %s", reply.toString()));
responseObserver.onNext(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ReplicaCurrentSearchingVersionHandler(GlobalState globalState) {
@Override
public void handle(IndexName indexNameRequest, StreamObserver<SearcherVersion> responseObserver) {
try {
IndexState indexState = getGlobalState().getIndex(indexNameRequest.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(indexNameRequest.getIndexName());
SearcherVersion reply = handle(indexState, indexNameRequest);
logger.info("ReplicaCurrentSearchingVersionHandler returned version " + reply.getVersion());
responseObserver.onNext(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void handle(SearchRequest searchRequest, StreamObserver<SearchResponse> r

public SearchResponse getSearchResponse(SearchRequest searchRequest)
throws IOException, SearchHandlerException {
IndexState indexState = getGlobalState().getIndex(searchRequest.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(searchRequest.getIndexName());
return handle(indexState, searchRequest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void handle(
SettingsRequest settingsRequest, StreamObserver<SettingsResponse> responseObserver) {
logger.info("Received settings request: {}", settingsRequest);
try {
IndexState indexState = getGlobalState().getIndex(settingsRequest.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(settingsRequest.getIndexName());
SettingsResponse reply = handle(indexState, settingsRequest);
logger.info("SettingsHandler returned " + reply);
responseObserver.onNext(reply);
Expand Down Expand Up @@ -85,7 +85,8 @@ private SettingsResponse handleAsSettingsV2(
IndexState indexState, SettingsRequest settingsRequest) throws SettingsHandlerException {
IndexStateManager indexStateManager;
try {
indexStateManager = indexState.getGlobalState().getIndexStateManager(indexState.getName());
indexStateManager =
indexState.getGlobalState().getIndexStateManagerOrThrow(indexState.getName());
} catch (IOException e) {
throw new SettingsHandlerException("Unable to get index state manager", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void handle(
logger.info("Received settings V2 request: {}", settingsRequest);
try {
IndexStateManager indexStateManager =
getGlobalState().getIndexStateManager(settingsRequest.getIndexName());
getGlobalState().getIndexStateManagerOrThrow(settingsRequest.getIndexName());
SettingsV2Response reply = handle(indexStateManager, settingsRequest);
logger.info("SettingsV2Handler returned: " + JsonFormat.printer().print(reply));
responseObserver.onNext(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public StatsHandler(GlobalState globalState) {
@Override
public void handle(StatsRequest statsRequest, StreamObserver<StatsResponse> responseObserver) {
try {
IndexState indexState = getGlobalState().getIndex(statsRequest.getIndexName());
IndexState indexState = getGlobalState().getIndexOrThrow(statsRequest.getIndexName());
indexState.verifyStarted();
StatsResponse reply = process(indexState);
logger.debug("StatsHandler retrieved stats for index: {} ", reply);
Expand Down
Loading
Loading