/** * Closes the index and bloomfilter, making the public state of this writer valid for consumption. */ public void close() { if (components.contains(Component.FILTER)) { String path = descriptor.filenameFor(Component.FILTER); try { // bloom filter FileOutputStream fos = new FileOutputStream(path); DataOutputStreamPlus stream = new DataOutputStreamPlus(new BufferedOutputStream(fos)); FilterFactory.serialize(bf, stream); stream.flush(); fos.getFD().sync(); stream.close(); } catch (IOException e) { throw new FSWriteError(e, path); } } // index long position = indexFile.getFilePointer(); indexFile.close(); // calls force FileUtils.truncate(indexFile.getPath(), position); }
@Override public void close() { if (buffer == null) return; // already closed super.close(); sstableMetadataCollector.addCompressionRatio(compressedSize, originalSize); try { metadataWriter.close(current, chunkCount); } catch (IOException e) { throw new FSWriteError(e, getPath()); } }
private static void writeMetadata(Descriptor desc, Map<MetadataType, MetadataComponent> components) { SequentialWriter out = SequentialWriter.open(new File(desc.filenameFor(Component.STATS))); try { desc.getMetadataSerializer().serialize(components, out.stream); } catch (IOException e) { throw new FSWriteError(e, out.getPath()); } finally { out.close(); } }
private Pair<Descriptor, StatsMetadata> close(FinishType type, long repairedAt) { switch (type) { case EARLY: case CLOSE: case NORMAL: iwriter.close(); dataFile.close(); if (type == FinishType.CLOSE) iwriter.bf.close(); } // write sstable statistics Map<MetadataType, MetadataComponent> metadataComponents ; metadataComponents = sstableMetadataCollector .finalizeMetadata(partitioner.getClass().getCanonicalName(), metadata.getBloomFilterFpChance(),repairedAt); // remove the 'tmp' marker from all components Descriptor descriptor = this.descriptor; if (type.isFinal) { dataFile.writeFullChecksum(descriptor); writeMetadata(descriptor, metadataComponents); // save the table of components SSTable.appendTOC(descriptor, components); descriptor = rename(descriptor, components); } return Pair.create(descriptor, (StatsMetadata) metadataComponents.get(MetadataType.STATS)); }