reschke commented on code in PR #2982: URL: https://github.com/apache/jackrabbit-oak/pull/2982#discussion_r3481555483
########## oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/AzureDataStoreWrapper.java: ########## @@ -0,0 +1,301 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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://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 org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage; + +import org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.v12.AzureDataStoreV12; +import org.apache.jackrabbit.oak.commons.PropertiesUtil; +import org.apache.jackrabbit.oak.plugins.blob.AbstractSharedCachingDataStore; +import org.apache.jackrabbit.oak.plugins.blob.datastore.AbstractDataStoreService; +import org.apache.jackrabbit.oak.plugins.blob.datastore.directaccess.*; +import org.apache.jackrabbit.oak.spi.blob.data.DataIdentifier; +import org.apache.jackrabbit.oak.spi.blob.data.DataRecord; +import org.apache.jackrabbit.oak.spi.blob.data.DataStore; +import org.apache.jackrabbit.oak.spi.blob.data.DataStoreException; +import org.apache.jackrabbit.oak.stats.StatisticsProvider; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.InputStream; +import java.net.URI; +import java.util.*; + + +/** + * OSGi component that selects between Azure SDK v8 ({@link AzureDataStore}) and v12 + * ({@link AzureDataStoreV12}) at activation time based on configuration, then registers the + * chosen implementation under the legacy v8 PID so consumers bound to that PID keep working. + * + * <p>Replaces the old dual-service architecture (AzureDataStoreService + AzureDataStoreServiceV12 + * + AzureSDKConditionGate) that caused deadlocks during OSGi service swap on FT toggle. + */ +@Component( + name = AzureDataStoreWrapper.NAME, + configurationPid = AzureDataStoreWrapper.NAME, + configurationPolicy = ConfigurationPolicy.REQUIRE +) +public class AzureDataStoreWrapper extends AbstractDataStoreService { + + private static final Logger log = LoggerFactory.getLogger(AzureDataStoreWrapper.class); + + public static final String NAME = "org.apache.jackrabbit.oak.plugins.blob.datastore.AzureDataStore"; + + // Same name for now; kept as separate constants so they can diverge if the sources need different keys later. + static final String ENV_VAR_V12_ENABLED = "blobstoreAzureV12Enabled"; + static final String OSGI_CONFIG_V12_ENABLED = "blobstoreAzureV12Enabled"; + static final String JVM_PROPERTY_V12_ENABLED = "blob.azure.v12.enabled"; + // Package-private so DelegatingDataStore (inner class) and same-package tests can reach it without reflection. + AbstractSharedCachingDataStore activeImpl; + @Reference + private StatisticsProvider statisticsProvider; + private ServiceRegistration<?> delegateReg; + + static ServiceRegistration<?> registerService(ComponentContext context, AbstractSharedCachingDataStore service) { + Dictionary<String, Object> delegateProps = new Hashtable<>(); + // Use the v8 PID so consumers bound to "org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureDataStore" + // still receive this service without needing a config change. + delegateProps.put(Constants.SERVICE_PID, AzureDataStore.class.getName()); + delegateProps.put("oak.datastore.description", new String[]{"type=AzureBlob"}); + return context.getBundleContext().registerService( + AbstractSharedCachingDataStore.class.getName(), service, delegateProps); + } + + /** + * Priority: JVM property (test/local override) > env var (fleet-wide container config) > OSGi config (normal production path). + * Higher-authority sources win so operators can override without touching OSGi config. + */ + static boolean getUseV12Value(Map<String, Object> config) { + if (System.getProperty(JVM_PROPERTY_V12_ENABLED) != null) { + boolean useV12 = Boolean.getBoolean(JVM_PROPERTY_V12_ENABLED); Review Comment: use SystemPropertyProvider -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
