Top Description Fields Constructors Methods
org.apache.derby.impl.store.replication.buffer

pack-priv Class LogBufferElement

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.sanity.SanityManager

ReplicationLogBuffer consists of n LogBufferElements, each of which can store a number of log records in a single byte[].

The format of each log record in the LogBufferElement is the same as is written to log file in LogAccessFile:
(int) total_length (data[].length + optionaldata[].length)
(long) instant
(byte[]) data+optionaldata
(int) total_length

In addition to adding a chunk of log records to the byte[], the greatestInstant variable is updated for every append so that getLastInstant can be used to get the highest log instant in this LogBufferElement.

Field Summary

Modifier and TypeField and Description
private final byte[]
private long
private int
private boolean

Constructor Summary

AccessConstructor and Description
protected
LogBufferElement(int bufferSize)

Method Summary

Modifier and TypeMethod and Description
private int

Returns:

new position
appendBytes
(byte[]
where the bytes are copied from
b
,
int
offset in b to start copying from
offset
,
int
the position in this LogBufferElement to start copying to
pos
,
int
number of bytes to copy from b, starting from offset
length
)

Append a byte[] to this LogBufferElement.

protected void
appendLog(long
the instant of the log record that was added last to this chunk of log
greatestInstant
,
byte[]
the chunk of log records
log
,
int
offset in log to start copy from
logOffset
,
int
number of bytes to copy, starting from logOffset
logLength
)

Append a chunk of log records to this LogBufferElement.

protected int

Returns:

Number of unused bytes in this LogBufferElement
freeSize
()

protected byte[]

Returns:

A byte[] representation of the log records appended to this LogBufferElement
getData
()

protected long

Returns:

The highest log instant appended to this LogBufferElement
getLastInstant
()

protected void
init()

Resets all variables to default values.

protected boolean

Returns:

true if this LogBufferElement should be reused, i.e. added to freeBuffers after being consumed.
isRecyclable
()

protected void
setRecyclable(boolean r)

protected int

Returns:

Number of used bytes in this LogBufferElement
size
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferdataback to summary
private final byte[] bufferdata
greatestInstantback to summary
private long greatestInstant
positionback to summary
private int position
recycleMeback to summary
private boolean recycleMe

Constructor Detail

LogBufferElementback to summary
protected LogBufferElement(int bufferSize)

Method Detail

appendBytesback to summary
private int appendBytes(byte[] b, int offset, int pos, int length)

Append a byte[] to this LogBufferElement.

Parameters
b:byte[]

where the bytes are copied from

offset:int

offset in b to start copying from

pos:int

the position in this LogBufferElement to start copying to

length:int

number of bytes to copy from b, starting from offset

Returns:int

new position

appendLogback to summary
protected void appendLog(long greatestInstant, byte[] log, int logOffset, int logLength)

Append a chunk of log records to this LogBufferElement.

Parameters
greatestInstant:long

the instant of the log record that was added last to this chunk of log

log:byte[]

the chunk of log records

logOffset:int

offset in log to start copy from

logLength:int

number of bytes to copy, starting from logOffset

freeSizeback to summary
protected int freeSize()
Returns:int

Number of unused bytes in this LogBufferElement

getDataback to summary
protected byte[] getData()
Returns:byte[]

A byte[] representation of the log records appended to this LogBufferElement

getLastInstantback to summary
protected long getLastInstant()
Returns:long

The highest log instant appended to this LogBufferElement

initback to summary
protected void init()

Resets all variables to default values. Should be called before a LogBufferElement is reused.

isRecyclableback to summary
protected boolean isRecyclable()
Returns:boolean

true if this LogBufferElement should be reused, i.e. added to freeBuffers after being consumed.

setRecyclableback to summary
protected void setRecyclable(boolean r)
sizeback to summary
protected int size()
Returns:int

Number of used bytes in this LogBufferElement