RestorableTsFileIOWriter extends TsFileIOWriter { long getTruncatedSize() { return truncatedSize; } RestorableTsFileIOWriter(File file); static RestorableTsFileIOWriter getWriterForAppendingDataOnCompletedTsFile(File file); Map<Path, MeasurementSchema> getKnownSchema(); List<ChunkMetadata> getVisibleMetadataList(String deviceId, String measurementId,
      TSDataType dataType); Map<String, Map<String, List<ChunkMetadata>>> getMetadatasForQuery(); void makeMetadataVisible(); boolean hasCrashed(); void addSchema(Path path, MeasurementSchema schema);  }
@Test public void testOnlyHeadMagic() throws Exception { File file = fsFactory.getFile(FILE_NAME); TsFileWriter writer = new TsFileWriter(file); writer.getIOWriter().close(); RestorableTsFileIOWriter rWriter = new RestorableTsFileIOWriter(file); writer = new TsFileWriter(rWriter); writer.close(); assertEquals(TSFileConfig.MAGIC_STRING.getBytes().length + TSFileConfig.VERSION_NUMBER .getBytes().length, rWriter.getTruncatedSize()); rWriter = new RestorableTsFileIOWriter(file); assertEquals(TsFileCheckStatus.COMPLETE_FILE, rWriter.getTruncatedSize()); assertFalse(rWriter.canWrite()); rWriter.close(); assertTrue(file.delete()); }
@Test public void testOnlyFirstMask() throws Exception { File file = fsFactory.getFile(FILE_NAME); TsFileWriter writer = new TsFileWriter(file); writer.getIOWriter().out.write(new byte[]{MetaMarker.CHUNK_HEADER}); writer.getIOWriter().close(); RestorableTsFileIOWriter rWriter = new RestorableTsFileIOWriter(file); writer = new TsFileWriter(rWriter); writer.close(); assertEquals(TsFileIOWriter.magicStringBytes.length + TsFileIOWriter.versionNumberBytes.length, rWriter.getTruncatedSize()); assertTrue(file.delete()); }
@Test public void testOnlyOneIncompleteChunkHeader() throws Exception { File file = fsFactory.getFile(FILE_NAME); TsFileGeneratorForTest.writeFileWithOneIncompleteChunkHeader(file); RestorableTsFileIOWriter rWriter = new RestorableTsFileIOWriter(file); TsFileWriter writer = new TsFileWriter(rWriter); writer.close(); assertEquals(TsFileIOWriter.magicStringBytes.length + TsFileIOWriter.versionNumberBytes.length, rWriter.getTruncatedSize()); assertTrue(file.delete()); }
@Test public void testOnlyOneChunkHeader() throws Exception { File file = new File(FILE_NAME); TsFileWriter writer = new TsFileWriter(file); writer.getIOWriter() .startFlushChunk(new MeasurementSchema("s1", TSDataType.FLOAT, TSEncoding.PLAIN), CompressionType.SNAPPY, TSDataType.FLOAT, TSEncoding.PLAIN, new FloatStatistics(), 100, 10); writer.getIOWriter().close(); RestorableTsFileIOWriter rWriter = new RestorableTsFileIOWriter(file); writer = new TsFileWriter(rWriter); writer.close(); assertEquals(TsFileIOWriter.magicStringBytes.length + TsFileIOWriter.versionNumberBytes.length, rWriter.getTruncatedSize()); assertTrue(file.delete()); }
@Test public void testOnlyOneChunkHeaderAndSomePage() throws Exception { File file = fsFactory.getFile(FILE_NAME); TsFileWriter writer = new TsFileWriter(file); writer.registerTimeseries(new Path("d1", "s1"), new MeasurementSchema("s1", TSDataType.FLOAT, TSEncoding.RLE)); writer.registerTimeseries(new Path("d1", "s2"), new MeasurementSchema("s2", TSDataType.FLOAT, TSEncoding.RLE)); writer.write(new TSRecord(1, "d1").addTuple(new FloatDataPoint("s1", 5)) .addTuple(new FloatDataPoint("s2", 4))); writer.write(new TSRecord(2, "d1").addTuple(new FloatDataPoint("s1", 5)) .addTuple(new FloatDataPoint("s2", 4))); writer.flushAllChunkGroups(); writer.writeVersion(0); long pos = writer.getIOWriter().getPos(); writer.getIOWriter().out.truncate(pos - 1); writer.getIOWriter().close(); RestorableTsFileIOWriter rWriter = new RestorableTsFileIOWriter(file); writer = new TsFileWriter(rWriter); writer.close(); assertEquals(pos - 1 - Long.BYTES, rWriter.getTruncatedSize()); assertTrue(file.delete()); }
@Test public void testOnlyOneChunkGroupAndOneMask() throws Exception { File file = fsFactory.getFile(FILE_NAME); TsFileWriter writer = new TsFileWriter(file); writer.registerTimeseries(new Path("d1", "s1"), new MeasurementSchema("s1", TSDataType.FLOAT, TSEncoding.RLE)); writer.registerTimeseries(new Path("d1", "s2"), new MeasurementSchema("s2", TSDataType.FLOAT, TSEncoding.RLE)); writer.write(new TSRecord(1, "d1").addTuple(new FloatDataPoint("s1", 5)) .addTuple(new FloatDataPoint("s2", 4))); writer.write(new TSRecord(2, "d1").addTuple(new FloatDataPoint("s1", 5)) .addTuple(new FloatDataPoint("s2", 4))); writer.flushAllChunkGroups(); writer.getIOWriter().writeChunkMaskForTest(); writer.getIOWriter().close(); RestorableTsFileIOWriter rWriter = new RestorableTsFileIOWriter(file); writer = new TsFileWriter(rWriter); writer.close(); assertNotEquals(TsFileIOWriter.magicStringBytes.length, rWriter.getTruncatedSize()); TsFileSequenceReader reader = new TsFileSequenceReader(FILE_NAME); List<ChunkMetadata> chunkMetadataList = reader.getChunkMetadataList(new Path("d1", "s1")); assertNotNull(chunkMetadataList); chunkMetadataList = reader.getChunkMetadataList(new Path("d1", "s2")); assertNotNull(chunkMetadataList); reader.close(); assertTrue(file.delete()); }