Skip to content

Commit fd401d3

Browse files
author
Harsh Kothari
committed
Code review minor fixes related formatting and naming convention
1 parent 8c034b4 commit fd401d3

File tree

5 files changed

+45
-58
lines changed

5 files changed

+45
-58
lines changed

server/src/main/java/org/opensearch/autoforcemerge/AutoForceMergeManager.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public class AutoForceMergeManager extends AbstractLifecycleComponent {
5454
private final JvmService jvmService;
5555
private final IndicesService indicesService;
5656
private final ClusterService clusterService;
57-
private AsyncForceMergeTask task;
58-
private ConfigurationValidator configurationValidator;
59-
private NodeValidator nodeValidator;
60-
private ShardValidator shardValidator;
57+
private final AsyncForceMergeTask task;
58+
private final ConfigurationValidator configurationValidator;
59+
private final NodeValidator nodeValidator;
60+
private final ShardValidator shardValidator;
6161
private final ForceMergeManagerSettings forceMergeManagerSettings;
6262
private final AtomicBoolean initialCheckDone = new AtomicBoolean(false);
6363

@@ -92,20 +92,18 @@ protected void doClose() {
9292
}
9393

9494
private void triggerForceMerge() {
95-
if (!forceMergeManagerSettings.isAutoForceMergeFeatureEnabled()) {
96-
logger.info("Cluster configuration shows auto force merge feature is disabled. Closing task.");
95+
if (forceMergeManagerSettings.isAutoForceMergeFeatureEnabled() == false) {
96+
logger.debug("Cluster configuration shows auto force merge feature is disabled. Closing task.");
9797
return;
9898
}
99-
if (!configurationValidator.hasWarmNodes()) {
99+
if (configurationValidator.hasWarmNodes() == false) {
100100
logger.debug("No warm nodes found. Skipping Auto Force merge.");
101101
return;
102102
}
103-
104-
if (!(nodeValidator.validate().isAllowed())) {
103+
if (nodeValidator.validate().isAllowed() == false) {
105104
logger.debug("Node capacity constraints are not allowing to trigger auto ForceMerge");
106105
return;
107106
}
108-
109107
List<IndexShard> shards = new ArrayList<>();
110108
for (IndexService indexService : indicesService) {
111109
for (IndexShard shard : indexService) {
@@ -116,28 +114,23 @@ private void triggerForceMerge() {
116114
}
117115
}
118116
}
119-
120117
List<IndexShard> sortedShards = getSortedShardsByTranslogAge(shards);
121118
int iteration = nodeValidator.getMaxConcurrentForceMerges();
122119
for (IndexShard shard : sortedShards) {
123-
if (!nodeValidator.validate().isAllowed()) {
120+
if (iteration == 0 || nodeValidator.validate().isAllowed() == false) {
124121
logger.debug("Node conditions no longer suitable for force merge");
125122
break;
126123
}
127-
if (iteration == 0) {
128-
break;
129-
}
130124
iteration--;
131125
CompletableFuture.runAsync(() -> {
132126
try {
133127
shard.forceMerge(new ForceMergeRequest()
134128
.maxNumSegments(forceMergeManagerSettings.getSegmentCountThreshold()));
135-
logger.info("Merging is completed successfully for the shard {}", shard.shardId());
129+
logger.debug("Merging is completed successfully for the shard {}", shard.shardId());
136130
} catch (IOException e) {
137131
logger.error("Error during force merge for shard {}", shard.shardId(), e);
138132
}
139133
}, threadPool.executor(ThreadPool.Names.FORCE_MERGE));
140-
141134
logger.debug("Successfully triggered force merge for shard {}", shard.shardId());
142135
try {
143136
Thread.sleep(forceMergeManagerSettings.getForcemergeDelay().getMillis());
@@ -159,13 +152,13 @@ private List<IndexShard> getSortedShardsByTranslogAge(List<IndexShard> shards) {
159152
private class ShardAgeComparator implements Comparator<IndexShard> {
160153
@Override
161154
public int compare(IndexShard s1, IndexShard s2) {
162-
long age1 = getTranslogAge(s1);
163-
long age2 = getTranslogAge(s2);
155+
long age1 = getEarliestLastModifiedAge(s1);
156+
long age2 = getEarliestLastModifiedAge(s2);
164157
return Long.compare(age1, age2);
165158
}
166159
}
167160

168-
private long getTranslogAge(IndexShard shard) {
161+
private long getEarliestLastModifiedAge(IndexShard shard) {
169162
CommonStatsFlags flags = new CommonStatsFlags(CommonStatsFlags.Flag.Translog);
170163
CommonStats stats = new CommonStats(indicesService.getIndicesQueryCache(), shard, flags);
171164
return stats.getTranslog() != null ? stats.getTranslog().getEarliestLastModifiedAge() : 0;
@@ -194,16 +187,16 @@ protected class ConfigurationValidator implements ValidationStrategy {
194187
*/
195188
@Override
196189
public ValidationResult validate() {
197-
if (!forceMergeManagerSettings.isAutoForceMergeFeatureEnabled()) {
190+
if (forceMergeManagerSettings.isAutoForceMergeFeatureEnabled() == false) {
198191
logger.debug("Cluster configuration shows auto force merge feature is disabled. Closing task.");
199192
return new ValidationResult(false);
200193
}
201194
initializeIfNeeded();
202-
if (!isRemoteStoreEnabled) {
195+
if (isRemoteStoreEnabled == false) {
203196
logger.debug("Cluster configuration is not meeting the criteria. Closing task.");
204197
return new ValidationResult(false);
205198
}
206-
if (!isOnlyDataNode) {
199+
if (isOnlyDataNode == false) {
207200
logger.debug("Node configuration doesn't meet requirements. Closing task.");
208201
task.close();
209202
return new ValidationResult(false);
@@ -220,7 +213,7 @@ public ValidationResult validate() {
220213
* Thread-safe through atomic operation on initialCheckDone.
221214
*/
222215
private void initializeIfNeeded() {
223-
if (!initialCheckDone.get()) {
216+
if (initialCheckDone.get() == false) {
224217
DiscoveryNode localNode = clusterService.localNode();
225218
isOnlyDataNode = localNode.isDataNode() && !localNode.isWarmNode();
226219
isRemoteStoreEnabled = isRemoteStorageEnabled();
@@ -239,7 +232,7 @@ private boolean isRemoteStorageEnabled() {
239232
* Checks if cluster has warm nodes.
240233
*/
241234
private boolean hasWarmNodes() {
242-
if (hasWarmNodes) return true;
235+
if (hasWarmNodes == true) return true;
243236
ClusterState clusterState = clusterService.state();
244237
return hasWarmNodes = clusterState.getNodes().getNodes()
245238
.values()
@@ -270,8 +263,8 @@ public ValidationResult validate() {
270263
logger.debug("JVM memory usage too high: {}%", jvmUsedPercent);
271264
return new ValidationResult(false);
272265
}
273-
if (!areForceMergeThreadsAvailable()) {
274-
logger.info("No force merge threads available");
266+
if (areForceMergeThreadsAvailable() == false) {
267+
logger.debug("No force merge threads available");
275268
return new ValidationResult(false);
276269
}
277270
return new ValidationResult(true);
@@ -309,8 +302,8 @@ public ValidationResult validate(IndexShard shard) {
309302
logger.debug("No shard found.");
310303
return new ValidationResult(false);
311304
}
312-
if (!isIndexWarmCandidate(shard)) {
313-
logger.info("Shard {} doesn't belong to a warm candidate index", shard.shardId());
305+
if (isIndexWarmCandidate(shard) == false) {
306+
logger.debug("Shard {} doesn't belong to a warm candidate index", shard.shardId());
314307
return new ValidationResult(false);
315308
}
316309
CommonStats stats = new CommonStats(indicesService.getIndicesQueryCache(), shard, flags);
@@ -331,6 +324,10 @@ private boolean isIndexWarmCandidate(IndexShard shard) {
331324
IndexSettings indexSettings = shard.indexSettings();
332325
return indexSettings.getScopedSettings().get(IndexSettings.INDEX_IS_WARM_CANDIDATE_INDEX);
333326
}
327+
328+
private boolean isRelocating(IndexShard shard){
329+
return false;
330+
}
334331
}
335332

336333
/**
@@ -396,7 +393,7 @@ protected boolean mustReschedule() {
396393
*/
397394
@Override
398395
protected void runInternal() {
399-
if (!initialCheckDone.get() && !(configurationValidator.validate().isAllowed())) {
396+
if (initialCheckDone.get() == false && configurationValidator.validate().isAllowed() == false) {
400397
return;
401398
}
402399
triggerForceMerge();

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,11 @@ public Settings getValue(Settings current, Settings previous) {
244244
public void apply(Settings value, Settings current, Settings previous) {
245245
for (String key : value.keySet()) {
246246
assert loggerPredicate.test(key);
247-
String component = key.substring("logger." .length());
248-
if ("level" .equals(component)) {
247+
String component = key.substring("logger.".length());
248+
if ("level".equals(component)) {
249249
continue;
250250
}
251-
if ("_root" .equals(component)) {
251+
if ("_root".equals(component)) {
252252
final String rootLevel = value.get(key);
253253
if (rootLevel == null) {
254254
Loggers.setLevel(LogManager.getRootLogger(), Loggers.LOG_DEFAULT_LEVEL_SETTING.get(settings));

server/src/main/java/org/opensearch/index/IndexSettings.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ public boolean isDerivedFieldAllowed() {
978978
* while index level settings will overwrite node settings.
979979
*
980980
* @param indexMetadata the index metadata this settings object is associated with
981-
* @param nodeSettings the nodes settings this index is allocated on.
981+
* @param nodeSettings the nodes settings this index is allocated on.
982982
*/
983983
public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSettings) {
984984
this(indexMetadata, nodeSettings, IndexScopedSettings.DEFAULT_SCOPED_SETTINGS);
@@ -989,7 +989,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
989989
* while index level settings will overwrite node settings.
990990
*
991991
* @param indexMetadata the index metadata this settings object is associated with
992-
* @param nodeSettings the nodes settings this index is allocated on.
992+
* @param nodeSettings the nodes settings this index is allocated on.
993993
*/
994994
public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSettings, IndexScopedSettings indexScopedSettings) {
995995
scopedSettings = indexScopedSettings.copy(nodeSettings, indexMetadata);
@@ -1325,7 +1325,6 @@ public String customDataPath() {
13251325

13261326
/**
13271327
* Returns the version the index was created on.
1328-
*
13291328
* @see IndexMetadata#indexCreated(Settings)
13301329
*/
13311330
public Version getIndexVersionCreated() {
@@ -1366,7 +1365,7 @@ public boolean isCompositeIndex() {
13661365

13671366
/**
13681367
* Returns true if segment replication is enabled on the index.
1369-
* <p>
1368+
*
13701369
* Every shard on a remote node would also have SegRep enabled even without
13711370
* proper index setting during the migration.
13721371
*/
@@ -1529,7 +1528,6 @@ public void setTranslogSyncInterval(TimeValue translogSyncInterval) {
15291528
/**
15301529
* Returns the translog sync/upload buffer interval when remote translog store is enabled and index setting
15311530
* {@code index.translog.durability} is set as {@code request}.
1532-
*
15331531
* @return the buffer interval.
15341532
*/
15351533
public TimeValue getRemoteTranslogUploadBufferInterval() {

server/src/main/java/org/opensearch/node/Node.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ public class Node implements Closeable {
367367
* Note that this does not control whether the node stores actual indices (see
368368
* {@link #NODE_DATA_SETTING}). However, if this is false, {@link #NODE_DATA_SETTING}
369369
* and {@link #NODE_MASTER_SETTING} must also be false.
370+
*
370371
*/
371372
public static final Setting<Boolean> NODE_LOCAL_STORAGE_SETTING = Setting.boolSetting(
372373
"node.local_storage",
@@ -382,7 +383,7 @@ public class Node implements Closeable {
382383
&& (Character.isWhitespace(value.charAt(0)) || Character.isWhitespace(value.charAt(value.length() - 1)))) {
383384
throw new IllegalArgumentException(key + " cannot have leading or trailing whitespace " + "[" + value + "]");
384385
}
385-
if (value.length() > 0 && "node.attr.server_name" .equals(key)) {
386+
if (value.length() > 0 && "node.attr.server_name".equals(key)) {
386387
try {
387388
new SNIHostName(value);
388389
} catch (IllegalArgumentException e) {
@@ -895,8 +896,8 @@ protected Node(
895896
directoryFactories.putAll(builtInDirectoryFactories);
896897

897898
final Map<String, IndexStorePlugin.RecoveryStateFactory> recoveryStateFactories = pluginsService.filterPlugins(
898-
IndexStorePlugin.class
899-
)
899+
IndexStorePlugin.class
900+
)
900901
.stream()
901902
.map(IndexStorePlugin::getRecoveryStateFactories)
902903
.flatMap(m -> m.entrySet().stream())
@@ -1445,9 +1446,9 @@ protected Node(
14451446

14461447
final Optional<TaskManagerClient> taskManagerClientOptional = FeatureFlags.isEnabled(BACKGROUND_TASK_EXECUTION_EXPERIMENTAL)
14471448
? pluginsService.filterPlugins(TaskManagerClientPlugin.class)
1448-
.stream()
1449-
.map(plugin -> plugin.getTaskManagerClient(client, clusterService, threadPool))
1450-
.findFirst()
1449+
.stream()
1450+
.map(plugin -> plugin.getTaskManagerClient(client, clusterService, threadPool))
1451+
.findFirst()
14511452
: Optional.empty();
14521453

14531454
final PersistentTasksExecutorRegistry registry = new PersistentTasksExecutorRegistry(tasksExecutors);
@@ -2026,12 +2027,9 @@ protected void validateNodeBeforeAcceptingRequests(
20262027
final BootstrapContext context,
20272028
final BoundTransportAddress boundTransportAddress,
20282029
List<BootstrapCheck> bootstrapChecks
2029-
) throws NodeValidationException {
2030-
}
2030+
) throws NodeValidationException {}
20312031

2032-
/**
2033-
* Writes a file to the logs dir containing the ports for the given transport type
2034-
*/
2032+
/** Writes a file to the logs dir containing the ports for the given transport type */
20352033
private void writePortsFile(String type, BoundTransportAddress boundAddress) {
20362034
Path tmpPortsFile = environment.logsDir().resolve(type + ".ports.tmp");
20372035
try (BufferedWriter writer = Files.newBufferedWriter(tmpPortsFile, StandardCharsets.UTF_8)) {
@@ -2059,7 +2057,6 @@ protected PluginsService getPluginsService() {
20592057

20602058
/**
20612059
* Creates a new {@link CircuitBreakerService} based on the settings provided.
2062-
*
20632060
* @see #BREAKER_TYPE_KEY
20642061
*/
20652062
public static CircuitBreakerService createCircuitBreakerService(
@@ -2135,7 +2132,6 @@ protected ScriptService newScriptService(Settings settings, Map<String, ScriptEn
21352132

21362133
/**
21372134
* Get Custom Name Resolvers list based on a Discovery Plugins list
2138-
*
21392135
* @param discoveryPlugins Discovery plugins list
21402136
*/
21412137
private List<NetworkService.CustomNameResolver> getCustomNameResolvers(List<DiscoveryPlugin> discoveryPlugins) {
@@ -2149,9 +2145,7 @@ private List<NetworkService.CustomNameResolver> getCustomNameResolvers(List<Disc
21492145
return customNameResolvers;
21502146
}
21512147

2152-
/**
2153-
* Constructs a ClusterInfoService which may be mocked for tests.
2154-
*/
2148+
/** Constructs a ClusterInfoService which may be mocked for tests. */
21552149
protected ClusterInfoService newClusterInfoService(
21562150
Settings settings,
21572151
ClusterService clusterService,
@@ -2166,9 +2160,7 @@ protected ClusterInfoService newClusterInfoService(
21662160
return service;
21672161
}
21682162

2169-
/**
2170-
* Constructs a {@link org.opensearch.http.HttpServerTransport} which may be mocked for tests.
2171-
*/
2163+
/** Constructs a {@link org.opensearch.http.HttpServerTransport} which may be mocked for tests. */
21722164
protected HttpServerTransport newHttpTransport(NetworkModule networkModule) {
21732165
return networkModule.getHttpServerTransportSupplier().get();
21742166
}

test/framework/src/main/java/org/opensearch/remotestore/RemoteStoreBaseIntegTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ protected Settings remoteStoreRepoSettings() {
183183
}
184184

185185
protected void setFailRate(String repoName, int value) throws ExecutionException, InterruptedException {
186-
GetRepositoriesRequest gr = new GetRepositoriesRequest(new String[]{repoName});
186+
GetRepositoriesRequest gr = new GetRepositoriesRequest(new String[] { repoName });
187187
GetRepositoriesResponse res = client().admin().cluster().getRepositories(gr).get();
188188
RepositoryMetadata rmd = res.repositories().get(0);
189189
Settings.Builder settings = Settings.builder()

0 commit comments

Comments
 (0)