示例#1
0
 public void writeChecksums() throws IOException {
   String checksumName = CHECKSUMS_PREFIX + System.currentTimeMillis();
   ImmutableMap<String, StoreFileMetaData> files = list();
   synchronized (mutex) {
     Map<String, String> checksums = new HashMap<String, String>();
     for (StoreFileMetaData metaData : files.values()) {
       if (metaData.checksum() != null) {
         checksums.put(metaData.name(), metaData.checksum());
       }
     }
     IndexOutput output = directory.createOutput(checksumName, IOContext.DEFAULT, true);
     output.writeInt(0); // version
     output.writeStringStringMap(checksums);
     output.close();
   }
   for (StoreFileMetaData metaData : files.values()) {
     if (metaData.name().startsWith(CHECKSUMS_PREFIX) && !checksumName.equals(metaData.name())) {
       try {
         directory.deleteFileChecksum(metaData.name());
       } catch (Exception e) {
         // ignore
       }
     }
   }
 }
示例#2
0
 /** Deletes the content of a shard store. Be careful calling this!. */
 public void deleteContent() throws IOException {
   ensureOpen();
   String[] files = directory.listAll();
   IOException lastException = null;
   for (String file : files) {
     if (isChecksum(file)) {
       try {
         directory.deleteFileChecksum(file);
       } catch (IOException e) {
         lastException = e;
       }
     } else {
       try {
         directory.deleteFile(file);
       } catch (NoSuchFileException | FileNotFoundException e) {
         // ignore
       } catch (IOException e) {
         lastException = e;
       }
     }
   }
   if (lastException != null) {
     throw lastException;
   }
 }