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

Introduce shortcuts to frequently used index settings #1232

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat(core): Introduce interface for frequently used index settings
- Add PagingSettingsProvider
- Implement interface in IndexConfiguration
- Implement as delegate in RepositoryConfiguration and ServiceProvider
  • Loading branch information
apeteri committed Oct 17, 2023
commit 579f40e55fcf569b9b969fba92c37ef137f22fc1
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.b2international.snowowl.core.config.RepositoryConfiguration;
import com.b2international.snowowl.core.config.SnowOwlConfiguration;
import com.b2international.snowowl.core.domain.DelegatingContext;
import com.b2international.snowowl.core.domain.PagingSettingsProvider;
import com.b2international.snowowl.core.events.Request;
import com.b2international.snowowl.core.jobs.JobRequests;
import com.b2international.snowowl.core.jobs.RemoteJob;
Expand All @@ -37,7 +39,7 @@
/**
* @since 4.5
*/
public interface ServiceProvider {
public interface ServiceProvider extends PagingSettingsProvider {

/**
* @return the application-level configuration object.
Expand Down Expand Up @@ -139,7 +141,26 @@ default boolean isJobRunning(String jobKey, Predicate<Map<String, Object>> param
.filter(parametersPredicate)
.isPresent();
}

private PagingSettingsProvider pagingSettings() {
return service(RepositoryConfiguration.class);
}

@Override
default int getPageSize() {
return pagingSettings().getPageSize();
}

@Override
default int getTermPartitionSize() {
return pagingSettings().getTermPartitionSize();
}

@Override
default int getCommitLimit() {
return pagingSettings().getCommitLimit();
}

/**
* Empty {@link ServiceProvider} implementation that throws {@link UnsupportedOperationException}s when trying to provide services. Useful when
* testing {@link Request} implementations.
Expand All @@ -157,5 +178,4 @@ public <T> Provider<T> provider(Class<T> type) {
throw new UnsupportedOperationException("Empty service provider can't provide services. Requested: " + type);
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hibernate.validator.constraints.NotEmpty;

import com.b2international.index.IndexClientFactory;
import com.b2international.snowowl.core.domain.PagingSettingsProvider;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
Expand All @@ -35,7 +36,7 @@
/**
* @since 5.0
*/
public class IndexConfiguration {
public class IndexConfiguration implements PagingSettingsProvider {

public static final int DEFAULT_CLUSTER_HEALTH_TIMEOUT = 300_000; // Snow Owl defaults to 5m cluster health timeout
public static final int DEFAULT_RESULT_WINDOW = 100_099; // Snow Owl defaults to slightly more than 100k max result window
Expand Down Expand Up @@ -294,16 +295,19 @@ public void configure(Builder<String, Object> settings) {
}

@JsonIgnore
@Override
public int getPageSize() {
return Math.min(IndexClientFactory.MAX_PAGE_SIZE, getResultWindow());
}

@JsonIgnore
@Override
public int getTermPartitionSize() {
return Math.min(getMaxTermsCount(), getResultWindow());
}

@JsonIgnore
@Override
public int getCommitLimit() {
return Math.min(getCommitWatermarkLow(), getResultWindow());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import org.hibernate.validator.constraints.NotEmpty;

import com.b2international.snowowl.core.domain.PagingSettingsProvider;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.net.HostAndPort;

Expand All @@ -31,7 +33,7 @@
*
* @since 3.4
*/
public class RepositoryConfiguration {
public class RepositoryConfiguration implements PagingSettingsProvider {

@NotEmpty
private String host = "0.0.0.0";
Expand Down Expand Up @@ -170,4 +172,22 @@ public String getDeploymentId() {
public void setDeploymentId(String deploymentId) {
this.deploymentId = deploymentId;
}

@JsonIgnore
@Override
public int getPageSize() {
return indexConfiguration.getPageSize();
}

@JsonIgnore
@Override
public int getTermPartitionSize() {
return indexConfiguration.getTermPartitionSize();
}

@JsonIgnore
@Override
public int getCommitLimit() {
return indexConfiguration.getCommitLimit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2023 B2i Healthcare Pte Ltd, http:https://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.b2international.snowowl.core.domain;

/**
* @since 9.0
*/
public interface PagingSettingsProvider {

/**
* @return the recommended page/batch size for streaming queries
*/
public int getPageSize();

/**
* @return the recommended (maximum) number of terms that should appear in a single "terms" query
*/
public int getTermPartitionSize();

/**
* @return the recommended number of changes in a single commit (soft limit)
*/
public int getCommitLimit();
}