Skip to content

Commit 0c8bb67

Browse files
committed
Hide more stuff
1 parent cffdd8a commit 0c8bb67

3 files changed

Lines changed: 27 additions & 19 deletions

File tree

server/src/main/java/org/elasticsearch/cluster/coordination/ElasticsearchNodeCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import java.util.stream.Stream;
4949

5050
public abstract class ElasticsearchNodeCommand extends EnvironmentAwareCommand {
51-
protected static final Logger logger = LogManager.getLogger(ElasticsearchNodeCommand.class);
51+
private static final Logger logger = LogManager.getLogger(ElasticsearchNodeCommand.class);
5252
protected static final String DELIMITER = "------------------------------------------------------------------------\n";
5353
static final String STOP_WARNING_MSG =
5454
DELIMITER +
@@ -91,7 +91,7 @@ public static ClusterState clusterState(Environment environment, LucenePersisted
9191
public static Tuple<Long, ClusterState> loadTermAndClusterState(LucenePersistedStateFactory psf,
9292
Environment env) throws IOException {
9393
final LucenePersistedStateFactory.OnDiskState bestOnDiskState = psf.loadBestOnDiskState();
94-
if (bestOnDiskState == LucenePersistedStateFactory.NO_ON_DISK_STATE) {
94+
if (bestOnDiskState.empty()) {
9595
throw new ElasticsearchException(CS_MISSING_MSG);
9696
}
9797
return Tuple.tuple(bestOnDiskState.currentTerm, clusterState(env, bestOnDiskState));

server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,20 @@ public void start(Settings settings, TransportService transportService, ClusterS
8080

8181
if (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.isDataNode(settings)) {
8282
try {
83-
LucenePersistedStateFactory.OnDiskState onDiskState = lucenePersistedStateFactory.loadBestOnDiskState();
83+
final LucenePersistedStateFactory.OnDiskState onDiskState = lucenePersistedStateFactory.loadBestOnDiskState();
8484

85-
if (onDiskState == LucenePersistedStateFactory.NO_ON_DISK_STATE) {
85+
MetaData metaData = onDiskState.metaData;
86+
long lastAcceptedVersion = onDiskState.lastAcceptedVersion;
87+
long currentTerm = onDiskState.currentTerm;
88+
89+
if (onDiskState.empty() == false) {
8690
assert Version.CURRENT.major <= Version.V_7_0_0.major + 1 :
8791
"legacy metadata loader is not needed anymore from v9 onwards";
8892
final Tuple<Manifest, MetaData> legacyState = metaStateService.loadFullState();
8993
if (legacyState.v1().isEmpty() == false) {
90-
onDiskState = new LucenePersistedStateFactory.OnDiskState(lucenePersistedStateFactory.getNodeId(),
91-
null, legacyState.v1().getCurrentTerm(),
92-
legacyState.v1().getClusterStateVersion(), legacyState.v2());
94+
metaData = legacyState.v2();
95+
lastAcceptedVersion = legacyState.v1().getClusterStateVersion();
96+
currentTerm = legacyState.v1().getCurrentTerm();
9397
}
9498
}
9599

@@ -99,19 +103,19 @@ public void start(Settings settings, TransportService transportService, ClusterS
99103
try {
100104
final ClusterState clusterState = prepareInitialClusterState(transportService, clusterService,
101105
ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings))
102-
.version(onDiskState.lastAcceptedVersion)
103-
.metaData(upgradeMetaDataForNode(onDiskState.metaData, metaDataIndexUpgradeService, metaDataUpgrader))
106+
.version(lastAcceptedVersion)
107+
.metaData(upgradeMetaDataForNode(metaData, metaDataIndexUpgradeService, metaDataUpgrader))
104108
.build());
105109
lucenePersistedState = new LucenePersistedStateFactory.LucenePersistedState(
106-
persistenceWriter, onDiskState.currentTerm, clusterState);
110+
persistenceWriter, currentTerm, clusterState);
107111
// Write the whole state out to be sure it's fresh and using the latest format. Called during initialisation, so that
108112
// (1) throwing an IOException is enough to halt the node, and
109113
// (2) the index is currently empty since it was opened with IndexWriterConfig.OpenMode.CREATE
110114

111115
// In the common case it's actually sufficient to commit() the existing state and not do any indexing. For instance,
112116
// this is true if there's only one data path on this master node, and the commit we just loaded was already written out
113117
// by this version of Elasticsearch. TODO TBD should we avoid indexing when possible?
114-
persistenceWriter.writeFullStateAndCommit(onDiskState.currentTerm, clusterState);
118+
persistenceWriter.writeFullStateAndCommit(currentTerm, clusterState);
115119
metaStateService.deleteAll(); // delete legacy files
116120
success = true;
117121
} finally {

server/src/main/java/org/elasticsearch/gateway/LucenePersistedStateFactory.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,31 @@ Directory createDirectory(Path path) throws IOException {
185185
}
186186

187187
public static class OnDiskState {
188-
public final String nodeId;
189-
public final Path dataPath;
188+
private static final OnDiskState NO_ON_DISK_STATE = new OnDiskState(null, null, 0L, 0L, MetaData.EMPTY_META_DATA);
189+
190+
private final String nodeId;
191+
private final Path dataPath;
190192
public final long currentTerm;
191193
public final long lastAcceptedVersion;
192194
public final MetaData metaData;
193195

194-
public OnDiskState(String nodeId, Path dataPath, long currentTerm, long lastAcceptedVersion, MetaData metaData) {
196+
private OnDiskState(String nodeId, Path dataPath, long currentTerm, long lastAcceptedVersion, MetaData metaData) {
195197
this.nodeId = nodeId;
196198
this.dataPath = dataPath;
197199
this.currentTerm = currentTerm;
198200
this.lastAcceptedVersion = lastAcceptedVersion;
199201
this.metaData = metaData;
200202
}
201-
}
202203

203-
public static final OnDiskState NO_ON_DISK_STATE = new OnDiskState(null, null, 0L, 0L, MetaData.EMPTY_META_DATA);
204+
public boolean empty() {
205+
return this == NO_ON_DISK_STATE;
206+
}
207+
}
204208

205209
public OnDiskState loadBestOnDiskState() throws IOException {
206210
String committedClusterUuid = null;
207211
Path committedClusterUuidPath = null;
208-
OnDiskState bestOnDiskState = NO_ON_DISK_STATE;
212+
OnDiskState bestOnDiskState = OnDiskState.NO_ON_DISK_STATE;
209213
OnDiskState maxCurrentTermOnDiskState = bestOnDiskState;
210214

211215
// We use a write-all-read-one strategy: metadata is written to every data path when accepting it, which means it is mostly
@@ -240,7 +244,7 @@ public OnDiskState loadBestOnDiskState() throws IOException {
240244

241245
long acceptedTerm = onDiskState.metaData.coordinationMetaData().term();
242246
long maxAcceptedTerm = bestOnDiskState.metaData.coordinationMetaData().term();
243-
if (bestOnDiskState == NO_ON_DISK_STATE
247+
if (bestOnDiskState.empty()
244248
|| acceptedTerm > maxAcceptedTerm
245249
|| (acceptedTerm == maxAcceptedTerm
246250
&& (onDiskState.lastAcceptedVersion > bestOnDiskState.lastAcceptedVersion
@@ -489,7 +493,7 @@ public static class Writer implements Closeable {
489493
private final String nodeId;
490494
private final BigArrays bigArrays;
491495

492-
public Writer(List<MetaDataIndexWriter> metaDataIndexWriters, String nodeId, BigArrays bigArrays) {
496+
private Writer(List<MetaDataIndexWriter> metaDataIndexWriters, String nodeId, BigArrays bigArrays) {
493497
this.metaDataIndexWriters = metaDataIndexWriters;
494498
this.nodeId = nodeId;
495499
this.bigArrays = bigArrays;

0 commit comments

Comments
 (0)