rpuch commented on code in PR #4623: URL: https://github.com/apache/ignite-3/pull/4623#discussion_r1816088421
########## modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageCompactionTriggerConfiguration.java: ########## @@ -0,0 +1,130 @@ +/* + * 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.ignite.internal.metastorage.impl; + +import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture; + +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.ignite.internal.configuration.SystemDistributedConfiguration; +import org.apache.ignite.internal.configuration.SystemDistributedView; +import org.apache.ignite.internal.configuration.SystemPropertyView; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.jetbrains.annotations.Nullable; + +/** Configuration for metastorage compaction triggering based on distributed system properties. */ +public class MetaStorageCompactionTriggerConfiguration { + private static final IgniteLogger LOG = Loggers.forClass(MetaStorageCompactionTriggerConfiguration.class); + + /** + * System property that defines compaction start interval (in milliseconds). + * + * <p>Default value is {@link #INTERVAL_DEFAULT_VALUE}.</p> + */ + public static final String INTERVAL_SYSTEM_PROPERTY_NAME = "metastorageCompactionInterval"; + + /** + * System property that defines compaction data availability time (in milliseconds). + * + * <p>Default value is {@link #DATA_AVAILABILITY_TIME_DEFAULT_VALUE}.</p> + */ + public static final String DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME = "metastorageCompactionDataAvailabilityTime"; + + /** Default value for the {@link #INTERVAL_SYSTEM_PROPERTY_NAME}. */ + // TODO: IGNITE-23280 Make default 1 minute + public static final long INTERVAL_DEFAULT_VALUE = Long.MAX_VALUE; + + /** Default value for the {@link #DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME}. */ + // TODO: IGNITE-23280 Make default 1 hour Review Comment: When doing MG disaster recovery there is a scenario: 1. Old leader A (the only MG voting member) crashes and cannot start again 2. User repairs MG on remaining nodes 3. Later, old ex-leader from item 1 is migrated to the repaired cluster. To successfully join, A needs to check its Metastorage checksum against the new leader's checksums. If the default for MS data availability is just 1 hour and more than 1 hour passed between items 2 and 3, the new leader could have already compacted out the latest MS revision which A has, so A will not be able to join. Could this default be increased? ########## modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageCompactionTriggerConfiguration.java: ########## @@ -0,0 +1,130 @@ +/* + * 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.ignite.internal.metastorage.impl; + +import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture; + +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.ignite.internal.configuration.SystemDistributedConfiguration; +import org.apache.ignite.internal.configuration.SystemDistributedView; +import org.apache.ignite.internal.configuration.SystemPropertyView; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.jetbrains.annotations.Nullable; + +/** Configuration for metastorage compaction triggering based on distributed system properties. */ +public class MetaStorageCompactionTriggerConfiguration { + private static final IgniteLogger LOG = Loggers.forClass(MetaStorageCompactionTriggerConfiguration.class); + + /** + * System property that defines compaction start interval (in milliseconds). + * + * <p>Default value is {@link #INTERVAL_DEFAULT_VALUE}.</p> + */ + public static final String INTERVAL_SYSTEM_PROPERTY_NAME = "metastorageCompactionInterval"; Review Comment: Is this an interval between compaction initiations (or maybe checks to see whether a compaction is needed)? ########## modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageCompactionTriggerConfiguration.java: ########## @@ -0,0 +1,130 @@ +/* + * 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.ignite.internal.metastorage.impl; + +import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture; + +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.ignite.internal.configuration.SystemDistributedConfiguration; +import org.apache.ignite.internal.configuration.SystemDistributedView; +import org.apache.ignite.internal.configuration.SystemPropertyView; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.jetbrains.annotations.Nullable; + +/** Configuration for metastorage compaction triggering based on distributed system properties. */ +public class MetaStorageCompactionTriggerConfiguration { + private static final IgniteLogger LOG = Loggers.forClass(MetaStorageCompactionTriggerConfiguration.class); + + /** + * System property that defines compaction start interval (in milliseconds). + * + * <p>Default value is {@link #INTERVAL_DEFAULT_VALUE}.</p> + */ + public static final String INTERVAL_SYSTEM_PROPERTY_NAME = "metastorageCompactionInterval"; + + /** + * System property that defines compaction data availability time (in milliseconds). + * + * <p>Default value is {@link #DATA_AVAILABILITY_TIME_DEFAULT_VALUE}.</p> + */ + public static final String DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME = "metastorageCompactionDataAvailabilityTime"; + + /** Default value for the {@link #INTERVAL_SYSTEM_PROPERTY_NAME}. */ + // TODO: IGNITE-23280 Make default 1 minute + public static final long INTERVAL_DEFAULT_VALUE = Long.MAX_VALUE; + + /** Default value for the {@link #DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME}. */ + // TODO: IGNITE-23280 Make default 1 hour + public static final long DATA_AVAILABILITY_TIME_DEFAULT_VALUE = Long.MAX_VALUE; + + private final ReadWriteLock rwLock = new ReentrantReadWriteLock(); + + /** Guarded by {@link #rwLock}. */ + private long interval; + + /** Guarded by {@link #rwLock}. */ + private long dataAvailabilityTime; + + /** Constructor. */ + public MetaStorageCompactionTriggerConfiguration(SystemDistributedConfiguration systemDistributedConfiguration) { + updateSystemProperties(systemDistributedConfiguration.value()); + + systemDistributedConfiguration.listen(ctx -> { Review Comment: Is a race between the initial update and subscribing to events possible? ########## modules/metastorage/src/test/java/org/apache/ignite/internal/metastorage/impl/MetaStorageCompactionTriggerConfigurationTest.java: ########## @@ -0,0 +1,111 @@ +/* + * 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.ignite.internal.metastorage.impl; + +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.configuration.SystemDistributedConfiguration; +import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension; +import org.apache.ignite.internal.configuration.testframework.InjectConfiguration; +import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** For {@link MetaStorageCompactionTriggerConfiguration} testing. */ +@ExtendWith(ConfigurationExtension.class) +public class MetaStorageCompactionTriggerConfigurationTest extends BaseIgniteAbstractTest { + private static final String INTERVAL_SYSTEM_PROPERTY_NAME = "metastorageCompactionInterval"; + + private static final String DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME = "metastorageCompactionDataAvailabilityTime"; + + private static final long INTERVAL_DEFAULT_VALUE = Long.MAX_VALUE; + + private static final long DATA_AVAILABILITY_TIME_DEFAULT_VALUE = Long.MAX_VALUE; + + @Test + void testEmptySystemProperties(@InjectConfiguration SystemDistributedConfiguration systemConfig) { + var config = new MetaStorageCompactionTriggerConfiguration(systemConfig); + + assertEquals(INTERVAL_DEFAULT_VALUE, config.interval()); + assertEquals(DATA_AVAILABILITY_TIME_DEFAULT_VALUE, config.dataAvailabilityTime()); + } + + @Test + void testInvalidSystemPropertiesOnStart( + @InjectConfiguration("mock.properties = {" + + INTERVAL_SYSTEM_PROPERTY_NAME + ".propertyValue = foo, " + + DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME + ".propertyValue = bar" Review Comment: ```suggestion + INTERVAL_SYSTEM_PROPERTY_NAME + ".propertyValue = not-a-long, " + DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME + ".propertyValue = not-a-long" ``` ########## modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageCompactionTriggerConfiguration.java: ########## @@ -0,0 +1,130 @@ +/* + * 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.ignite.internal.metastorage.impl; + +import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture; + +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.ignite.internal.configuration.SystemDistributedConfiguration; +import org.apache.ignite.internal.configuration.SystemDistributedView; +import org.apache.ignite.internal.configuration.SystemPropertyView; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.jetbrains.annotations.Nullable; + +/** Configuration for metastorage compaction triggering based on distributed system properties. */ +public class MetaStorageCompactionTriggerConfiguration { + private static final IgniteLogger LOG = Loggers.forClass(MetaStorageCompactionTriggerConfiguration.class); + + /** + * System property that defines compaction start interval (in milliseconds). Review Comment: The term 'system property' is already taken by Java system properties. At least, when I started reading this class, I was confused. Can another term be devised? Like 'internal property'? ########## modules/metastorage/src/test/java/org/apache/ignite/internal/metastorage/impl/MetaStorageCompactionTriggerConfigurationTest.java: ########## @@ -0,0 +1,111 @@ +/* + * 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.ignite.internal.metastorage.impl; + +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.configuration.SystemDistributedConfiguration; +import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension; +import org.apache.ignite.internal.configuration.testframework.InjectConfiguration; +import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** For {@link MetaStorageCompactionTriggerConfiguration} testing. */ +@ExtendWith(ConfigurationExtension.class) +public class MetaStorageCompactionTriggerConfigurationTest extends BaseIgniteAbstractTest { + private static final String INTERVAL_SYSTEM_PROPERTY_NAME = "metastorageCompactionInterval"; + + private static final String DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME = "metastorageCompactionDataAvailabilityTime"; + + private static final long INTERVAL_DEFAULT_VALUE = Long.MAX_VALUE; + + private static final long DATA_AVAILABILITY_TIME_DEFAULT_VALUE = Long.MAX_VALUE; + + @Test + void testEmptySystemProperties(@InjectConfiguration SystemDistributedConfiguration systemConfig) { + var config = new MetaStorageCompactionTriggerConfiguration(systemConfig); + + assertEquals(INTERVAL_DEFAULT_VALUE, config.interval()); + assertEquals(DATA_AVAILABILITY_TIME_DEFAULT_VALUE, config.dataAvailabilityTime()); + } + + @Test + void testInvalidSystemPropertiesOnStart( + @InjectConfiguration("mock.properties = {" + + INTERVAL_SYSTEM_PROPERTY_NAME + ".propertyValue = foo, " + + DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME + ".propertyValue = bar" + + "}") + SystemDistributedConfiguration systemConfig + ) { + var config = new MetaStorageCompactionTriggerConfiguration(systemConfig); + + assertEquals(INTERVAL_DEFAULT_VALUE, config.interval()); + assertEquals(DATA_AVAILABILITY_TIME_DEFAULT_VALUE, config.dataAvailabilityTime()); + } + + @Test + void testValidSystemPropertiesOnStart( + @InjectConfiguration("mock.properties = {" + + INTERVAL_SYSTEM_PROPERTY_NAME + ".propertyValue = \"100\", " + + DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME + ".propertyValue = \"500\"" + + "}") + SystemDistributedConfiguration systemConfig + ) { + var config = new MetaStorageCompactionTriggerConfiguration(systemConfig); + + assertEquals(100, config.interval()); + assertEquals(500, config.dataAvailabilityTime()); + } + + @Test + void testInvalidSystemPropertiesOnChange(@InjectConfiguration SystemDistributedConfiguration systemConfig) { + var config = new MetaStorageCompactionTriggerConfiguration(systemConfig); + + changeSystemConfig(systemConfig, "foo", "bar"); Review Comment: ```suggestion changeSystemConfig(systemConfig, "not-a-long", "not-a-long"); ``` ########## modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageCompactionTriggerConfiguration.java: ########## @@ -0,0 +1,130 @@ +/* + * 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.ignite.internal.metastorage.impl; + +import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture; + +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.ignite.internal.configuration.SystemDistributedConfiguration; +import org.apache.ignite.internal.configuration.SystemDistributedView; +import org.apache.ignite.internal.configuration.SystemPropertyView; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.jetbrains.annotations.Nullable; + +/** Configuration for metastorage compaction triggering based on distributed system properties. */ +public class MetaStorageCompactionTriggerConfiguration { + private static final IgniteLogger LOG = Loggers.forClass(MetaStorageCompactionTriggerConfiguration.class); + + /** + * System property that defines compaction start interval (in milliseconds). + * + * <p>Default value is {@link #INTERVAL_DEFAULT_VALUE}.</p> + */ + public static final String INTERVAL_SYSTEM_PROPERTY_NAME = "metastorageCompactionInterval"; + + /** + * System property that defines compaction data availability time (in milliseconds). + * + * <p>Default value is {@link #DATA_AVAILABILITY_TIME_DEFAULT_VALUE}.</p> + */ + public static final String DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME = "metastorageCompactionDataAvailabilityTime"; + + /** Default value for the {@link #INTERVAL_SYSTEM_PROPERTY_NAME}. */ + // TODO: IGNITE-23280 Make default 1 minute + public static final long INTERVAL_DEFAULT_VALUE = Long.MAX_VALUE; + + /** Default value for the {@link #DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME}. */ + // TODO: IGNITE-23280 Make default 1 hour Review Comment: Or maybe use other 'checksum availabilityy time' which is significantly larger than the 'data availability time'? ########## modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/MetaStorageCompactionTriggerConfiguration.java: ########## @@ -0,0 +1,130 @@ +/* + * 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.ignite.internal.metastorage.impl; + +import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture; + +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.ignite.internal.configuration.SystemDistributedConfiguration; +import org.apache.ignite.internal.configuration.SystemDistributedView; +import org.apache.ignite.internal.configuration.SystemPropertyView; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.jetbrains.annotations.Nullable; + +/** Configuration for metastorage compaction triggering based on distributed system properties. */ +public class MetaStorageCompactionTriggerConfiguration { + private static final IgniteLogger LOG = Loggers.forClass(MetaStorageCompactionTriggerConfiguration.class); + + /** + * System property that defines compaction start interval (in milliseconds). + * + * <p>Default value is {@link #INTERVAL_DEFAULT_VALUE}.</p> + */ + public static final String INTERVAL_SYSTEM_PROPERTY_NAME = "metastorageCompactionInterval"; + + /** + * System property that defines compaction data availability time (in milliseconds). + * + * <p>Default value is {@link #DATA_AVAILABILITY_TIME_DEFAULT_VALUE}.</p> + */ + public static final String DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME = "metastorageCompactionDataAvailabilityTime"; + + /** Default value for the {@link #INTERVAL_SYSTEM_PROPERTY_NAME}. */ + // TODO: IGNITE-23280 Make default 1 minute + public static final long INTERVAL_DEFAULT_VALUE = Long.MAX_VALUE; + + /** Default value for the {@link #DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME}. */ + // TODO: IGNITE-23280 Make default 1 hour + public static final long DATA_AVAILABILITY_TIME_DEFAULT_VALUE = Long.MAX_VALUE; + + private final ReadWriteLock rwLock = new ReentrantReadWriteLock(); + + /** Guarded by {@link #rwLock}. */ + private long interval; + + /** Guarded by {@link #rwLock}. */ + private long dataAvailabilityTime; + + /** Constructor. */ + public MetaStorageCompactionTriggerConfiguration(SystemDistributedConfiguration systemDistributedConfiguration) { + updateSystemProperties(systemDistributedConfiguration.value()); + + systemDistributedConfiguration.listen(ctx -> { + updateSystemProperties(ctx.newValue()); + + return nullCompletedFuture(); + }); + } + + /** Returns compaction start interval (in milliseconds). */ + long interval() { + rwLock.readLock().lock(); + + try { + return interval; + } finally { + rwLock.readLock().unlock(); + } + } + + /** Data availability time (in milliseconds). */ + long dataAvailabilityTime() { + rwLock.readLock().lock(); + + try { + return dataAvailabilityTime; + } finally { + rwLock.readLock().unlock(); + } + } + + private void updateSystemProperties(SystemDistributedView view) { + rwLock.writeLock().lock(); + + try { + interval = longValue(view, INTERVAL_SYSTEM_PROPERTY_NAME, INTERVAL_DEFAULT_VALUE); + dataAvailabilityTime = longValue(view, DATA_AVAILABILITY_TIME_SYSTEM_PROPERTY_NAME, DATA_AVAILABILITY_TIME_DEFAULT_VALUE); + } finally { + rwLock.writeLock().unlock(); + } + } + + private static long longValue(SystemDistributedView systemDistributedView, String systemPropertyName, long defaultValue) { + return longValue(systemDistributedView.properties().get(systemPropertyName), systemPropertyName, defaultValue); + } + + private static long longValue(@Nullable SystemPropertyView systemPropertyView, String systemPropertyName, long defaultValue) { + if (systemPropertyView == null) { + return defaultValue; + } + + try { + return Long.parseLong(systemPropertyView.propertyValue()); + } catch (NumberFormatException e) { + LOG.warn( Review Comment: This looks dangerous. On the other hand, we cannot fail startup if there is something unparseable as this is a distributed config and we'll break the cluster. Do we have a common approach to such situations? -- 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]
