Class RestorableTsFileIOWriter
- java.lang.Object
-
- org.apache.iotdb.tsfile.write.writer.TsFileIOWriter
-
- org.apache.iotdb.tsfile.write.writer.RestorableTsFileIOWriter
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class RestorableTsFileIOWriter extends TsFileIOWriter
This writer is for opening and recover a TsFile(1) If the TsFile is closed normally, hasCrashed()=false and canWrite()=false
(2) Otherwise, the writer generates metadata for already flushed Chunks and truncate crashed data. The hasCrashed()=true and canWrite()=true
Notice!!! If you want to query this file through the generated metadata, remember to call the makeMetadataVisible()
-
-
Field Summary
-
Fields inherited from class org.apache.iotdb.tsfile.write.writer.TsFileIOWriter
canWrite, CHUNK_METADATA_TEMP_FILE_SUFFIX, chunkGroupMetadataList, chunkMetadataList, chunkMetadataTempFile, config, currentChunkMetadata, currentChunkMetadataSize, enableMemoryControl, endPosInCMTForDevice, file, hasChunkMetadataInDisk, MAGIC_STRING_BYTES, maxMetadataSize, out, pathCount, tempOutput, VERSION_NUMBER_BYTE
-
-
Constructor Summary
Constructors Constructor Description RestorableTsFileIOWriter(java.io.File file)RestorableTsFileIOWriter(java.io.File file, boolean truncate)RestorableTsFileIOWriter(java.io.File file, long maxMetadataSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSchema(Path path, IMeasurementSchema schema)java.util.Map<Path,IMeasurementSchema>getKnownSchema()longgetMaxPlanIndex()java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.List<ChunkMetadata>>>getMetadatasForQuery()longgetMinPlanIndex()java.util.List<ChunkMetadata>getVisibleMetadataList(java.lang.String deviceId, java.lang.String measurementId, TSDataType dataType)For query.static RestorableTsFileIOWritergetWriterForAppendingDataOnCompletedTsFile(java.io.File file)Given a TsFile, generate a writable RestorableTsFileIOWriter.booleanhasCrashed()Whether this TsFile is crashed.voidmakeMetadataVisible()add all appendChunkMetadatas into memory.-
Methods inherited from class org.apache.iotdb.tsfile.write.writer.TsFileIOWriter
canWrite, checkMetadataSizeAndMayFlush, close, endChunkGroup, endCurrentChunk, endFile, filterChunks, flush, getChunkGroupMetadataList, getChunkMetadataListOfCurrentDeviceInMemory, getCurrentChunkGroupDeviceId, getDeviceChunkMetadataMap, getDeviceTimeseriesMetadataMap, getFile, getIOWriterOut, getPos, isWritingChunkGroup, mark, reset, setFile, setMaxPlanIndex, setMinPlanIndex, sortAndFlushChunkMetadata, startChunkGroup, startFile, startFlushChunk, truncate, writeBytesToStream, writeChunk, writeChunk, writeEmptyValueChunk, writePlanIndices
-
-
-
-
Constructor Detail
-
RestorableTsFileIOWriter
public RestorableTsFileIOWriter(java.io.File file) throws java.io.IOException- Parameters:
file- a given tsfile path you want to (continue to) write- Throws:
java.io.IOException- if write failed, or the file is broken but autoRepair==false.
-
RestorableTsFileIOWriter
public RestorableTsFileIOWriter(java.io.File file, long maxMetadataSize) throws java.io.IOException- Parameters:
file- a given tsfile path you want to (continue to) write- Throws:
java.io.IOException- if write failed, or the file is broken but autoRepair==false.
-
RestorableTsFileIOWriter
public RestorableTsFileIOWriter(java.io.File file, boolean truncate) throws java.io.IOException- Throws:
java.io.IOException
-
-
Method Detail
-
getWriterForAppendingDataOnCompletedTsFile
public static RestorableTsFileIOWriter getWriterForAppendingDataOnCompletedTsFile(java.io.File file) throws java.io.IOException
Given a TsFile, generate a writable RestorableTsFileIOWriter. That is, for a complete TsFile, the function erases all FileMetadata and supports writing new data; For a incomplete TsFile, the function supports writing new data directly. However, it is more efficient using the construction function of RestorableTsFileIOWriter, if the tsfile is incomplete.- Parameters:
file- a TsFile- Returns:
- a writable RestorableTsFileIOWriter
- Throws:
java.io.IOException
-
getKnownSchema
public java.util.Map<Path,IMeasurementSchema> getKnownSchema()
-
getVisibleMetadataList
public java.util.List<ChunkMetadata> getVisibleMetadataList(java.lang.String deviceId, java.lang.String measurementId, TSDataType dataType)
For query.get chunks' metadata from memory.
- Parameters:
deviceId- the device idmeasurementId- the measurement iddataType- the value type- Returns:
- chunks' metadata
-
getMetadatasForQuery
public java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.List<ChunkMetadata>>> getMetadatasForQuery()
-
makeMetadataVisible
public void makeMetadataVisible()
add all appendChunkMetadatas into memory. After calling this method, other classes can read these metadata.
-
hasCrashed
public boolean hasCrashed()
Whether this TsFile is crashed.- Returns:
- false when this TsFile is complete
-
addSchema
public void addSchema(Path path, IMeasurementSchema schema)
-
getMinPlanIndex
public long getMinPlanIndex()
- Overrides:
getMinPlanIndexin classTsFileIOWriter
-
getMaxPlanIndex
public long getMaxPlanIndex()
- Overrides:
getMaxPlanIndexin classTsFileIOWriter
-
-