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 } } } }
/** 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; } }
private void closeInternal() { synchronized (mutex) { // if we close the dir we need to make sure nobody writes checksums try { directory.closeInternal(); // don't call close here we throw an exception there! } catch (IOException e) { logger.debug("failed to close directory", e); } } }
/** Creates a raw output, no checksum is computed, and no compression if enabled. */ public IndexOutput createOutputRaw(String name) throws IOException { return directory.createOutput(name, IOContext.DEFAULT, true); }
public void close() throws IOException { directory.close(); }
public void fullDelete() throws IOException { deleteContent(); for (Directory delegate : directory.delegates()) { directoryService.fullDelete(delegate); } }