diff options
author | Tor Brede Vekterli <vekterli@oath.com> | 2018-12-05 16:00:30 +0100 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@oath.com> | 2018-12-05 16:04:48 +0100 |
commit | d29450ded189ee78657b0ae8778ae879df7a3b5f (patch) | |
tree | dc39c8ab36f2b3df5733e443dad0d7f10bcf27d3 /vespaclient-container-plugin | |
parent | 200663867930d081a49644c42f6090a926a327c3 (diff) |
Add and use cross-cluster bucket space config
Adds a new config `AllClustersBucketSpacesConfig` which includes all
document type to bucket space mappings across all configured content
clusters. Inject this config into `RestApi` to ensure all changes
to the mapping is observed. This also removes the remaining per-request
config fetching during Document V1 visit ops.
Diffstat (limited to 'vespaclient-container-plugin')
3 files changed, 14 insertions, 17 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java index 65e7191e164..2b12c7cd78c 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java @@ -50,7 +50,7 @@ public class OperationHandlerImpl implements OperationHandler { } public interface BucketSpaceResolver { - Optional<String> clusterBucketSpaceFromDocumentType(String clusterConfigId, String docType); + Optional<String> clusterBucketSpaceFromDocumentType(String clusterId, String docType); } public static class BucketSpaceRoute { @@ -91,20 +91,6 @@ public class OperationHandlerImpl implements OperationHandler { private final ConcurrentResourcePool<SyncSession> syncSessions; - private static ClusterEnumerator defaultClusterEnumerator() { - return () -> new ClusterList("client").getStorageClusters(); - } - - private static BucketSpaceResolver defaultBucketResolver() { - return (clusterConfigId, docType) -> Optional.ofNullable(BucketSpaceEnumerator - .fromConfig(clusterConfigId).getDoctypeToSpaceMapping() - .get(docType)); - } - - public OperationHandlerImpl(DocumentAccess documentAccess, ClusterEnumerator clusterEnumerator, MetricReceiver metricReceiver) { - this(documentAccess, clusterEnumerator, defaultBucketResolver(), metricReceiver); - } - public OperationHandlerImpl(DocumentAccess documentAccess, ClusterEnumerator clusterEnumerator, BucketSpaceResolver bucketSpaceResolver, MetricReceiver metricReceiver) { this.documentAccess = documentAccess; @@ -335,7 +321,7 @@ public class OperationHandlerImpl implements OperationHandler { String targetBucketSpace; if (!restUri.isRootOnly()) { String docType = restUri.getDocumentType(); - Optional<String> resolvedSpace = bucketSpaceResolver.clusterBucketSpaceFromDocumentType(clusterDef.getConfigId(), docType); + Optional<String> resolvedSpace = bucketSpaceResolver.clusterBucketSpaceFromDocumentType(clusterDef.getName(), docType); if (!resolvedSpace.isPresent()) { throw new RestApiException(Response.createErrorResponse(400, String.format( "Document type '%s' in cluster '%s' is not mapped to a known bucket space", docType, clusterDef.getName()), diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java index f088db31c23..baf7dcb0f68 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java @@ -30,6 +30,7 @@ import com.yahoo.documentapi.messagebus.loadtypes.LoadTypeSet; import com.yahoo.metrics.simple.MetricReceiver; import com.yahoo.text.Text; import com.yahoo.vespa.config.content.LoadTypeConfig; +import com.yahoo.vespa.config.content.core.AllClustersBucketSpacesConfig; import com.yahoo.vespaclient.ClusterDef; import com.yahoo.vespaclient.ClusterList; import com.yahoo.vespaxmlparser.VespaXMLFeedReader; @@ -75,6 +76,7 @@ public class RestApi extends LoggingRequestHandler { @Inject public RestApi(LoggingRequestHandler.Context parentCtx, DocumentmanagerConfig documentManagerConfig, LoadTypeConfig loadTypeConfig, ThreadpoolConfig threadpoolConfig, + AllClustersBucketSpacesConfig bucketSpacesConfig, ClusterListConfig clusterListConfig, MetricReceiver metricReceiver) { super(parentCtx); @@ -83,6 +85,7 @@ public class RestApi extends LoggingRequestHandler { this.operationHandler = new OperationHandlerImpl( new MessageBusDocumentAccess(params), fixedClusterEnumeratorFromConfig(clusterListConfig), + fixedBucketSpaceResolverFromConfig(bucketSpacesConfig), metricReceiver); this.singleDocumentParser = new SingleDocumentParser(new DocumentTypeManager(documentManagerConfig)); // 40% of the threads can be blocked before we deny requests. @@ -120,6 +123,14 @@ public class RestApi extends LoggingRequestHandler { return () -> clusters; } + private static OperationHandlerImpl.BucketSpaceResolver fixedBucketSpaceResolverFromConfig( + AllClustersBucketSpacesConfig bucketSpacesConfig) { + return (clusterId, docType) -> + Optional.ofNullable(bucketSpacesConfig.cluster(clusterId)) + .map(cluster -> cluster.documentType(docType)) + .map(type -> type.bucketSpace()); + } + private static Optional<String> requestProperty(String parameter, HttpRequest request) { final String property = request.getProperty(parameter); if (property != null && ! property.isEmpty()) { diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java index 4c04070cec4..30f039c31fb 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java @@ -132,7 +132,7 @@ public class OperationHandlerImplTest { }); when(documentAccess.createSyncSession(any(SyncParameters.class))).thenReturn(mockSyncSession); OperationHandlerImpl.ClusterEnumerator clusterEnumerator = () -> Arrays.asList(new ClusterDef("foo", "configId")); - OperationHandlerImpl.BucketSpaceResolver bucketSpaceResolver = (configId, docType) -> Optional.ofNullable(bucketSpaces.get(docType)); + OperationHandlerImpl.BucketSpaceResolver bucketSpaceResolver = (clusterId, docType) -> Optional.ofNullable(bucketSpaces.get(docType)); return new OperationHandlerImpl(documentAccess, clusterEnumerator, bucketSpaceResolver, MetricReceiver.nullImplementation); } } |