3131 */
3232public class FSSuspensionCallbackImpl implements SuspensionHook {
3333
34+ public static String MODEL = "model" ;
35+ public static String INDEX = "index" ;
36+
3437 private AtomicInteger currentId = new AtomicInteger (0 );
3538
3639 private Map <String , Integer > labels = Collections .synchronizedMap (new TreeMap <>());
@@ -46,12 +49,18 @@ public void open(File path, String modelLabel, boolean create) throws FileNotFou
4649 this .path = path ;
4750 this .modelLabel = modelLabel ;
4851 if (create ) {
49- getFile ("model" ).deleteOnExit ();
50- getFile ("index" ).deleteOnExit ();
52+ File modelFile = getFile (MODEL );
53+ if (modelFile .exists ())
54+ modelFile .deleteOnExit ();
55+
56+ File indexFile = getFile (INDEX );
57+ if (indexFile .exists ())
58+ indexFile .deleteOnExit ();
59+
5160 } else {
5261 loadIndex ();
5362 }
54- dataStore = new RandomAccessFile (getFile ("model" ), "rw" );
63+ dataStore = new RandomAccessFile (getFile (MODEL ), "rw" );
5564 }
5665
5766 public void close () throws IOException {
@@ -115,7 +124,7 @@ public Iterable<Integer> getAllNodeIds() {
115124
116125 @ Override
117126 public void loadIndex () {
118- try (FileInputStream fis = new FileInputStream (getFile ("index" ));
127+ try (FileInputStream fis = new FileInputStream (getFile (INDEX ));
119128 ByteArrayInputStream bais = new ByteArrayInputStream (fis .readAllBytes ());
120129 DataInputStream dis = new DataInputStream (bais )) {
121130 readIndex (dis );
@@ -129,7 +138,7 @@ public void storeIndex() {
129138 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
130139
131140 try (DataOutputStream dos = new DataOutputStream (baos );
132- FileOutputStream fos = new FileOutputStream (getFile ("index" ))) {
141+ FileOutputStream fos = new FileOutputStream (getFile (INDEX ))) {
133142 writeIndex (dos );
134143 fos .write (baos .toByteArray ());
135144 } catch (IOException e ) {
0 commit comments