@ -137,7 +137,8 @@ class ProducerStateManagerTest {
val appendInfo = stateManager . prepareUpdate ( producerId , isFromClient = false )
val appendInfo = stateManager . prepareUpdate ( producerId , isFromClient = false )
// Sequence number wrap around
// Sequence number wrap around
appendInfo . append ( epoch , Int . MaxValue - 10 , 9 , time . milliseconds ( ) , 2000L , 2020L , isTransactional = false )
appendInfo . append ( epoch , Int . MaxValue - 10 , 9 , time . milliseconds ( ) ,
LogOffsetMetadata ( 2000L ) , 2020L , isTransactional = false )
assertEquals ( None , stateManager . lastEntry ( producerId ) )
assertEquals ( None , stateManager . lastEntry ( producerId ) )
stateManager . update ( appendInfo )
stateManager . update ( appendInfo )
assertTrue ( stateManager . lastEntry ( producerId ) . isDefined )
assertTrue ( stateManager . lastEntry ( producerId ) . isDefined )
@ -209,14 +210,14 @@ class ProducerStateManagerTest {
val offset = 992342L
val offset = 992342L
val seq = 0
val seq = 0
val producerAppendInfo = new ProducerAppendInfo ( partition , producerId , ProducerStateEntry . empty ( producerId ) , ValidationType . Full )
val producerAppendInfo = new ProducerAppendInfo ( partition , producerId , ProducerStateEntry . empty ( producerId ) , ValidationType . Full )
producerAppendInfo . append ( producerEpoch , seq , seq , time . milliseconds ( ) , offset , offset , isTransactional = true )
val log OffsetMetadata = LogOffsetMetadata ( messageOffset = offset , segmentBaseOffset = 990000L ,
val first OffsetMetadata = LogOffsetMetadata ( messageOffset = offset , segmentBaseOffset = 990000L ,
relativePositionInSegment = 234224 )
relativePositionInSegment = 234224 )
producerAppendInfo . maybeCacheTxnFirstOffsetMetadata ( logOffsetMetadata )
producerAppendInfo . append ( producerEpoch , seq , seq , time . milliseconds ( ) ,
firstOffsetMetadata , offset , isTransactional = true )
stateManager . update ( producerAppendInfo )
stateManager . update ( producerAppendInfo )
assertEquals ( Some ( log OffsetMetadata) , stateManager . firstUnstableOffset )
assertEquals ( Some ( first OffsetMetadata) , stateManager . firstUnstableOffset )
}
}
@Test
@Test
@ -232,10 +233,10 @@ class ProducerStateManagerTest {
ProducerStateEntry . empty ( producerId ) ,
ProducerStateEntry . empty ( producerId ) ,
ValidationType . Full
ValidationType . Full
)
)
producerAppendInfo . append ( producerEpoch , 0 , 0 , time . milliseconds ( ) , startOffset , startOffset , isTransactional = true )
val firstOffsetMetadata = LogOffsetMetadata ( messageOffset = startOffset , segmentBaseOffset = segmentBaseOffset ,
val logOffsetMetadata = LogOffsetMetadata ( messageOffset = startOffset , segmentBaseOffset = segmentBaseOffset ,
relativePositionInSegment = 50 * relativeOffset )
relativePositionInSegment = 50 * relativeOffset )
producerAppendInfo . maybeCacheTxnFirstOffsetMetadata ( logOffsetMetadata )
producerAppendInfo . append ( producerEpoch , 0 , 0 , time . milliseconds ( ) ,
firstOffsetMetadata , startOffset , isTransactional = true )
stateManager . update ( producerAppendInfo )
stateManager . update ( producerAppendInfo )
}
}
@ -273,36 +274,20 @@ class ProducerStateManagerTest {
assertEquals ( None , stateManager . firstUnstableOffset )
assertEquals ( None , stateManager . firstUnstableOffset )
}
}
@Test
def testNonMatchingTxnFirstOffsetMetadataNotCached ( ) : Unit = {
val producerEpoch = 0. toShort
val offset = 992342L
val seq = 0
val producerAppendInfo = new ProducerAppendInfo ( partition , producerId , ProducerStateEntry . empty ( producerId ) , ValidationType . Full )
producerAppendInfo . append ( producerEpoch , seq , seq , time . milliseconds ( ) , offset , offset , isTransactional = true )
// use some other offset to simulate a follower append where the log offset metadata won 't typically
// match any of the transaction first offsets
val logOffsetMetadata = LogOffsetMetadata ( messageOffset = offset - 23429 , segmentBaseOffset = 990000L ,
relativePositionInSegment = 234224 )
producerAppendInfo . maybeCacheTxnFirstOffsetMetadata ( logOffsetMetadata )
stateManager . update ( producerAppendInfo )
assertEquals ( Some ( LogOffsetMetadata ( offset ) ) , stateManager . firstUnstableOffset )
}
@Test
@Test
def testPrepareUpdateDoesNotMutate ( ) : Unit = {
def testPrepareUpdateDoesNotMutate ( ) : Unit = {
val producerEpoch = 0. toShort
val producerEpoch = 0. toShort
val appendInfo = stateManager . prepareUpdate ( producerId , isFromClient = true )
val appendInfo = stateManager . prepareUpdate ( producerId , isFromClient = true )
appendInfo . append ( producerEpoch , 0 , 5 , time . milliseconds ( ) , 15L , 20L , isTransactional = false )
appendInfo . append ( producerEpoch , 0 , 5 , time . milliseconds ( ) ,
LogOffsetMetadata ( 15L ) , 20L , isTransactional = false )
assertEquals ( None , stateManager . lastEntry ( producerId ) )
assertEquals ( None , stateManager . lastEntry ( producerId ) )
stateManager . update ( appendInfo )
stateManager . update ( appendInfo )
assertTrue ( stateManager . lastEntry ( producerId ) . isDefined )
assertTrue ( stateManager . lastEntry ( producerId ) . isDefined )
val nextAppendInfo = stateManager . prepareUpdate ( producerId , isFromClient = true )
val nextAppendInfo = stateManager . prepareUpdate ( producerId , isFromClient = true )
nextAppendInfo . append ( producerEpoch , 6 , 10 , time . milliseconds ( ) , 26L , 30L , isTransactional = false )
nextAppendInfo . append ( producerEpoch , 6 , 10 , time . milliseconds ( ) ,
LogOffsetMetadata ( 26L ) , 30L , isTransactional = false )
assertTrue ( stateManager . lastEntry ( producerId ) . isDefined )
assertTrue ( stateManager . lastEntry ( producerId ) . isDefined )
var lastEntry = stateManager . lastEntry ( producerId ) . get
var lastEntry = stateManager . lastEntry ( producerId ) . get
@ -325,7 +310,8 @@ class ProducerStateManagerTest {
append ( stateManager , producerId , producerEpoch , 0 , offset )
append ( stateManager , producerId , producerEpoch , 0 , offset )
val appendInfo = stateManager . prepareUpdate ( producerId , isFromClient = true )
val appendInfo = stateManager . prepareUpdate ( producerId , isFromClient = true )
appendInfo . append ( producerEpoch , 1 , 5 , time . milliseconds ( ) , 16L , 20L , isTransactional = true )
appendInfo . append ( producerEpoch , 1 , 5 , time . milliseconds ( ) ,
LogOffsetMetadata ( 16L ) , 20L , isTransactional = true )
var lastEntry = appendInfo . toEntry
var lastEntry = appendInfo . toEntry
assertEquals ( producerEpoch , lastEntry . producerEpoch )
assertEquals ( producerEpoch , lastEntry . producerEpoch )
assertEquals ( 1 , lastEntry . firstSeq )
assertEquals ( 1 , lastEntry . firstSeq )
@ -335,7 +321,8 @@ class ProducerStateManagerTest {
assertEquals ( Some ( 16L ) , lastEntry . currentTxnFirstOffset )
assertEquals ( Some ( 16L ) , lastEntry . currentTxnFirstOffset )
assertEquals ( List ( new TxnMetadata ( producerId , 16L ) ) , appendInfo . startedTransactions )
assertEquals ( List ( new TxnMetadata ( producerId , 16L ) ) , appendInfo . startedTransactions )
appendInfo . append ( producerEpoch , 6 , 10 , time . milliseconds ( ) , 26L , 30L , isTransactional = true )
appendInfo . append ( producerEpoch , 6 , 10 , time . milliseconds ( ) ,
LogOffsetMetadata ( 26L ) , 30L , isTransactional = true )
lastEntry = appendInfo . toEntry
lastEntry = appendInfo . toEntry
assertEquals ( producerEpoch , lastEntry . producerEpoch )
assertEquals ( producerEpoch , lastEntry . producerEpoch )
assertEquals ( 1 , lastEntry . firstSeq )
assertEquals ( 1 , lastEntry . firstSeq )
@ -892,7 +879,8 @@ class ProducerStateManagerTest {
isTransactional : Boolean = false ,
isTransactional : Boolean = false ,
isFromClient : Boolean = true ) : Unit = {
isFromClient : Boolean = true ) : Unit = {
val producerAppendInfo = stateManager . prepareUpdate ( producerId , isFromClient )
val producerAppendInfo = stateManager . prepareUpdate ( producerId , isFromClient )
producerAppendInfo . append ( producerEpoch , seq , seq , timestamp , offset , offset , isTransactional )
producerAppendInfo . append ( producerEpoch , seq , seq , timestamp ,
LogOffsetMetadata ( offset ) , offset , isTransactional )
stateManager . update ( producerAppendInfo )
stateManager . update ( producerAppendInfo )
stateManager . updateMapEndOffset ( offset + 1 )
stateManager . updateMapEndOffset ( offset + 1 )
}
}
@ -904,7 +892,7 @@ class ProducerStateManagerTest {
batch : RecordBatch ,
batch : RecordBatch ,
isFromClient : Boolean ) : Unit = {
isFromClient : Boolean ) : Unit = {
val producerAppendInfo = stateManager . prepareUpdate ( producerId , isFromClient )
val producerAppendInfo = stateManager . prepareUpdate ( producerId , isFromClient )
producerAppendInfo . append ( batch )
producerAppendInfo . append ( batch , firstOffsetMetadataOpt = None )
stateManager . update ( producerAppendInfo )
stateManager . update ( producerAppendInfo )
stateManager . updateMapEndOffset ( offset + 1 )
stateManager . updateMapEndOffset ( offset + 1 )
}
}