@InterfaceAudience.Private public class RotateFile extends Object
Modifier and Type | Field and Description |
---|---|
private org.apache.hadoop.fs.Path[] |
files |
private org.apache.hadoop.fs.FileSystem |
fs |
private static org.slf4j.Logger |
LOG |
private long |
maxFileSize |
private int |
nextFile |
private long |
prevTimestamp |
Constructor and Description |
---|
RotateFile(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path dir,
String name,
long maxFileSize)
Constructs a new RotateFile object with the given parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
delete()
Deletes the two files used for rotating data.
|
byte[] |
read()
Reads the content of the rotate file by selecting the winner file based on the timestamp of the
data inside the files.
|
private org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RotateFileData |
read(org.apache.hadoop.fs.Path path) |
private int |
select(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RotateFileData[] datas) |
void |
write(byte[] data)
Writes the given data to the next file in the rotation, with a timestamp calculated based on
the previous timestamp and the current time to make sure it is greater than the previous
timestamp.
|
(package private) static void |
write(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path file,
long timestamp,
byte[] data) |
private static final org.slf4j.Logger LOG
private final org.apache.hadoop.fs.FileSystem fs
private final long maxFileSize
private final org.apache.hadoop.fs.Path[] files
private long prevTimestamp
private int nextFile
public RotateFile(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, String name, long maxFileSize)
fs
- the file system to use.dir
- the directory where the files will be created.name
- the base name for the files.maxFileSize
- the maximum size of each file.private org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RotateFileData read(org.apache.hadoop.fs.Path path) throws IOException
IOException
private int select(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RotateFileData[] datas)
public byte[] read() throws IOException
IOException
- if an error occurs while reading the files.static void write(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path file, long timestamp, byte[] data) throws IOException
IOException
public void write(byte[] data) throws IOException
RotateFile
instance, you need to call read()
first to initialize the nextFile index, before calling this method.data
- the data to be written to the fileIOException
- if an I/O error occurs while writing the data to the filepublic void delete() throws IOException
IOException
- if there is an error deleting either fileCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.