public class SegmentFile extends Object implements Lifecycle<SegmentFile.SegmentFileOptions>
magic bytes first log index reserved [0x20 0x20] [... 8 bytes...] [8 bytes] [record, record, ...]Every record format is:Magic bytes data length data [0x57, 0x8A] [4 bytes] [bytes]
| 限定符和类型 | 类和说明 |
|---|---|
static class |
SegmentFile.SegmentFileOptions
Segment file options.
|
static class |
SegmentFile.SegmentHeader
Segment file header.
|
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
HEADER_SIZE |
static byte[] |
RECORD_MAGIC_BYTES
Magic bytes for data buffer.
|
static int |
RECORD_MAGIC_BYTES_SIZE |
| 构造器和说明 |
|---|
SegmentFile(int size,
String path,
ThreadPoolExecutor writeExecutor) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
clear(int startPos,
boolean sync)
Clear data in [startPos, startPos+64).
|
boolean |
contains(long logIndex)
Returns true when the segment file contains the log index.
|
void |
destroy()
Destroy the file.
|
int |
getWrotePos() |
void |
hintLoad() |
void |
hintUnload() |
boolean |
init(SegmentFile.SegmentFileOptions opts)
Initialize the service.
|
boolean |
isFull() |
boolean |
isSwappedOut() |
boolean |
reachesFileEndBy(long waitToWroteBytes) |
byte[] |
read(long logIndex,
int pos)
Read data from the position.
|
void |
setLastLogIndex(long lastLogIndex) |
void |
shutdown()
Dispose the resources for service.
|
void |
swapOut() |
void |
sync(boolean sync)
Forces any changes made to this segment file's content to be written to the
storage device containing the mapped file.
|
String |
toString() |
void |
truncateSuffix(int wrotePos,
long logIndex,
boolean sync)
Truncate data from wrotePos(inclusive) to the file end and set lastLogIndex=logIndex.
|
int |
write(long logIndex,
byte[] data,
RocksDBLogStorage.WriteContext ctx)
Write the data and return it's wrote position.
|
public static final int HEADER_SIZE
public static final byte[] RECORD_MAGIC_BYTES
public static final int RECORD_MAGIC_BYTES_SIZE
public SegmentFile(int size,
String path,
ThreadPoolExecutor writeExecutor)
@OnlyForTest public int getWrotePos()
public boolean isSwappedOut()
public void setLastLogIndex(long lastLogIndex)
public void hintLoad()
public void hintUnload()
public void swapOut()
public void truncateSuffix(int wrotePos,
long logIndex,
boolean sync)
wrotePos - the wrote position(inclusive)logIndex - the log indexsync - whether to call fsyncpublic boolean contains(long logIndex)
logIndex - the log indexpublic void clear(int startPos,
boolean sync)
startPos - the start position(inclusive)public boolean init(SegmentFile.SegmentFileOptions opts)
Lifecycleinit 在接口中 Lifecycle<SegmentFile.SegmentFileOptions>public boolean reachesFileEndBy(long waitToWroteBytes)
public boolean isFull()
public int write(long logIndex,
byte[] data,
RocksDBLogStorage.WriteContext ctx)
logIndex - the log indexdata - data to writepublic byte[] read(long logIndex,
int pos)
throws IOException
logIndex - the log indexpos - the position to readIOExceptionpublic void sync(boolean sync)
throws IOException
IOExceptionpublic void destroy()
public void shutdown()
Lifecycleshutdown 在接口中 Lifecycle<SegmentFile.SegmentFileOptions>Copyright © 2021. All rights reserved.