29
29
import org .apache .lucene .store .IndexInput ;
30
30
import org .apache .lucene .store .OutputStreamIndexOutput ;
31
31
import org .apache .lucene .store .SimpleFSDirectory ;
32
+ import org .elasticsearch .common .logging .Loggers ;
32
33
import org .elasticsearch .core .internal .io .IOUtils ;
33
34
import org .elasticsearch .ExceptionsHelper ;
34
35
import org .elasticsearch .common .bytes .BytesArray ;
@@ -76,6 +77,7 @@ public abstract class MetaDataStateFormat<T> {
76
77
private final String prefix ;
77
78
private final Pattern stateFilePattern ;
78
79
80
+ private static final Logger logger = Loggers .getLogger (MetaDataStateFormat .class );
79
81
80
82
/**
81
83
* Creates a new {@link MetaDataStateFormat} instance
@@ -134,6 +136,7 @@ public void close() throws IOException {
134
136
IOUtils .fsync (tmpStatePath , false ); // fsync the state file
135
137
Files .move (tmpStatePath , finalStatePath , StandardCopyOption .ATOMIC_MOVE );
136
138
IOUtils .fsync (stateLocation , true );
139
+ logger .trace ("written state to {}" , finalStatePath );
137
140
for (int i = 1 ; i < locations .length ; i ++) {
138
141
stateLocation = locations [i ].resolve (STATE_DIR_NAME );
139
142
Files .createDirectories (stateLocation );
@@ -145,12 +148,15 @@ public void close() throws IOException {
145
148
// we are on the same FileSystem / Partition here we can do an atomic move
146
149
Files .move (tmpPath , finalPath , StandardCopyOption .ATOMIC_MOVE );
147
150
IOUtils .fsync (stateLocation , true );
151
+ logger .trace ("copied state to {}" , finalPath );
148
152
} finally {
149
153
Files .deleteIfExists (tmpPath );
154
+ logger .trace ("cleaned up {}" , tmpPath );
150
155
}
151
156
}
152
157
} finally {
153
158
Files .deleteIfExists (tmpStatePath );
159
+ logger .trace ("cleaned up {}" , tmpStatePath );
154
160
}
155
161
cleanupOldFiles (prefix , fileName , locations );
156
162
}
@@ -211,20 +217,19 @@ protected Directory newDirectory(Path dir) throws IOException {
211
217
}
212
218
213
219
private void cleanupOldFiles (final String prefix , final String currentStateFile , Path [] locations ) throws IOException {
214
- final DirectoryStream .Filter <Path > filter = new DirectoryStream .Filter <Path >() {
215
- @ Override
216
- public boolean accept (Path entry ) throws IOException {
217
- final String entryFileName = entry .getFileName ().toString ();
218
- return Files .isRegularFile (entry )
219
- && entryFileName .startsWith (prefix ) // only state files
220
- && currentStateFile .equals (entryFileName ) == false ; // keep the current state file around
221
- }
220
+ final DirectoryStream .Filter <Path > filter = entry -> {
221
+ final String entryFileName = entry .getFileName ().toString ();
222
+ return Files .isRegularFile (entry )
223
+ && entryFileName .startsWith (prefix ) // only state files
224
+ && currentStateFile .equals (entryFileName ) == false ; // keep the current state file around
222
225
};
223
226
// now clean up the old files
224
227
for (Path dataLocation : locations ) {
228
+ logger .trace ("cleanupOldFiles: cleaning up {}" , dataLocation );
225
229
try (DirectoryStream <Path > stream = Files .newDirectoryStream (dataLocation .resolve (STATE_DIR_NAME ), filter )) {
226
230
for (Path stateFile : stream ) {
227
231
Files .deleteIfExists (stateFile );
232
+ logger .trace ("cleanupOldFiles: cleaned up {}" , stateFile );
228
233
}
229
234
}
230
235
}
0 commit comments