@@ -80,15 +80,16 @@ type consenterImpl struct {
80
80
// Implements the multichain.Consenter interface. Called by multichain.newChainSupport(), which
81
81
// is itself called by multichain.NewManagerImpl() when ranging over the ledgerFactory's existingChains.
82
82
func (co * consenterImpl ) HandleChain (cs multichain.ConsenterSupport , metadata * cb.Metadata ) (multichain.Chain , error ) {
83
- return newChain (co , cs , getLastOffsetPersisted (metadata )), nil
83
+ return newChain (co , cs , getLastOffsetPersisted (metadata , cs . ChainID () )), nil
84
84
}
85
85
86
- func getLastOffsetPersisted (metadata * cb.Metadata ) int64 {
86
+ func getLastOffsetPersisted (metadata * cb.Metadata , chainID string ) int64 {
87
87
if metadata .Value != nil {
88
88
// Extract orderer-related metadata from the tip of the ledger first
89
89
kafkaMetadata := & ab.KafkaMetadata {}
90
90
if err := proto .Unmarshal (metadata .Value , kafkaMetadata ); err != nil {
91
- panic ("Ledger may be corrupted: cannot unmarshal orderer metadata in most recent block" )
91
+ logger .Panicf ("[channel: %s] Ledger may be corrupted:" +
92
+ "cannot unmarshal orderer metadata in most recent block" , chainID )
92
93
}
93
94
return kafkaMetadata .LastOffsetPersisted
94
95
}
@@ -104,7 +105,7 @@ func getLastOffsetPersisted(metadata *cb.Metadata) int64 {
104
105
// be satisfied by both the actual and the mock object and will allow
105
106
// us to retrieve these constructors.
106
107
func newChain (consenter testableConsenter , support multichain.ConsenterSupport , lastOffsetPersisted int64 ) * chainImpl {
107
- logger .Debug ( " Starting chain with last persisted offset:" , lastOffsetPersisted )
108
+ logger .Debugf ( "[channel: %s] Starting chain with last persisted offset: %d" , support . ChainID () , lastOffsetPersisted )
108
109
return & chainImpl {
109
110
consenter : consenter ,
110
111
support : support ,
@@ -163,18 +164,19 @@ type chainImpl struct {
163
164
func (ch * chainImpl ) Start () {
164
165
// 1. Post the CONNECT message to prevent panicking that occurs
165
166
// when seeking on a partition that hasn't been created yet.
166
- logger .Debug ( " Posting the CONNECT message..." )
167
+ logger .Debugf ( "[channel: %s] Posting the CONNECT message...", ch . support . ChainID () )
167
168
if err := ch .producer .Send (ch .partition , utils .MarshalOrPanic (newConnectMessage ())); err != nil {
168
- logger .Criticalf ("Couldn't post CONNECT message to %s : %s" , ch .partition , err )
169
+ logger .Criticalf ("[channel: %s] Cannot post CONNECT message: %s" , ch .support . ChainID () , err )
169
170
close (ch .exitChan )
170
171
ch .halted = true
171
172
return
172
173
}
174
+ logger .Debugf ("[channel: %s] CONNECT message posted successfully" , ch .support .ChainID ())
173
175
174
176
// 2. Set up the listener/consumer for this partition.
175
177
consumer , err := ch .consenter .consFunc ()(ch .support .SharedConfig ().KafkaBrokers (), ch .consenter .kafkaVersion (), ch .consenter .tlsConfig (), ch .partition , ch .lastOffsetPersisted + 1 )
176
178
if err != nil {
177
- logger .Criticalf ("Cannot retrieve required offset from Kafka cluster for chain %s : %s" , ch .partition , err )
179
+ logger .Criticalf ("[channel: %s] Cannot retrieve requested offset from Kafka cluster: %s" , ch .support . ChainID () , err )
178
180
close (ch .exitChan )
179
181
ch .halted = true
180
182
return
@@ -204,7 +206,9 @@ func (ch *chainImpl) Halt() {
204
206
// This construct is useful because it allows Halt() to be
205
207
// called multiple times w/o panicking. Recal that a receive
206
208
// from a closed channel returns (the zero value) immediately.
209
+ logger .Debugf ("[channel: %s] Halting of chain requested again" , ch .support .ChainID ())
207
210
default :
211
+ logger .Debugf ("[channel: %s] Halting of chain requested" , ch .support .ChainID ())
208
212
close (ch .exitChan )
209
213
}
210
214
}
@@ -217,11 +221,12 @@ func (ch *chainImpl) Enqueue(env *cb.Envelope) bool {
217
221
return false
218
222
}
219
223
220
- logger .Debug ( "Enqueueing: " , env )
224
+ logger .Debugf ( "[channel: %s] Enqueueing envelope... " , ch . support . ChainID () )
221
225
if err := ch .producer .Send (ch .partition , utils .MarshalOrPanic (newRegularMessage (utils .MarshalOrPanic (env )))); err != nil {
222
- logger .Errorf ("Couldn't post to %s : %s" , ch .partition , err )
226
+ logger .Errorf ("[channel: %s] cannot enqueue envelope : %s" , ch .support . ChainID () , err )
223
227
return false
224
228
}
229
+ logger .Debugf ("[channel: %s] Envelope enqueued successfully" , ch .support .ChainID ())
225
230
226
231
return ! ch .halted // If ch.halted has been set to true while sending, we should return false
227
232
}
@@ -242,49 +247,52 @@ func (ch *chainImpl) loop() {
242
247
case in := <- ch .consumer .Recv ():
243
248
if err := proto .Unmarshal (in .Value , msg ); err != nil {
244
249
// This shouldn't happen, it should be filtered at ingress
245
- logger .Critical ( " Unable to unmarshal consumed message:" , err )
250
+ logger .Criticalf ( "[channel: %s] Unable to unmarshal consumed message:", ch . support . ChainID () , err )
246
251
}
247
- logger .Debug ( "Received: " , msg )
252
+ logger .Debugf ( "[channel: %s] Successfully unmarshalled consumed message. Inspecting type... " , ch . support . ChainID () )
248
253
switch msg .Type .(type ) {
249
254
case * ab.KafkaMessage_Connect :
250
- logger .Debug ( " It's a connect message - ignoring" )
255
+ logger .Debugf ( "[channel: %s] It's a connect message - ignoring", ch . support . ChainID () )
251
256
continue
252
257
case * ab.KafkaMessage_TimeToCut :
253
258
ttcNumber = msg .GetTimeToCut ().BlockNumber
254
- logger .Debug ( " It's a time-to-cut message for block" , ttcNumber )
259
+ logger .Debugf ( "[channel: %s] It's a time-to-cut message for block %d" , ch . support . ChainID () , ttcNumber )
255
260
if ttcNumber == ch .lastCutBlock + 1 {
256
261
timer = nil
257
- logger .Debug ( " Nil'd the timer" )
262
+ logger .Debugf ( "[channel: %s] Nil'd the timer", ch . support . ChainID () )
258
263
batch , committers := ch .support .BlockCutter ().Cut ()
259
264
if len (batch ) == 0 {
260
- logger .Warningf ("Got right time-to-cut message (%d) but no pending requests - this might indicate a bug" , ch .lastCutBlock )
261
- logger .Infof ("Consenter for chain %s exiting" , ch .partition .Topic ())
265
+ logger .Warningf ("[channel: %s] Got right time-to-cut message (for block %d)," +
266
+ " no pending requests though; this might indicate a bug" , ch .support .ChainID (), ch .lastCutBlock )
267
+ logger .Infof ("[channel: %s] Consenter for channel exiting" , ch .support .ChainID ())
262
268
return
263
269
}
264
270
block := ch .support .CreateNextBlock (batch )
265
271
encodedLastOffsetPersisted = utils .MarshalOrPanic (& ab.KafkaMetadata {LastOffsetPersisted : in .Offset })
266
272
ch .support .WriteBlock (block , committers , encodedLastOffsetPersisted )
267
273
ch .lastCutBlock ++
268
- logger .Debug ("Proper time-to-cut received, just cut block" , ch .lastCutBlock )
274
+ logger .Debugf ("[channel: %s] Proper time-to-cut received, just cut block %d" ,
275
+ ch .support .ChainID (), ch .lastCutBlock )
269
276
continue
270
277
} else if ttcNumber > ch .lastCutBlock + 1 {
271
- logger .Warningf ("Got larger time-to-cut message (%d) than allowed (%d) - this might indicate a bug" , ttcNumber , ch .lastCutBlock + 1 )
272
- logger .Infof ("Consenter for chain %s exiting" , ch .partition .Topic ())
278
+ logger .Warningf ("[channel: %s] Got larger time-to-cut message (%d) than allowed (%d)" +
279
+ " - this might indicate a bug" , ch .support .ChainID (), ttcNumber , ch .lastCutBlock + 1 )
280
+ logger .Infof ("[channel: %s] Consenter for channel exiting" , ch .support .ChainID ())
273
281
return
274
282
}
275
- logger .Debug ( " Ignoring stale time-to-cut-message for" , ch .lastCutBlock )
283
+ logger .Debugf ( "[channel: %s] Ignoring stale time-to-cut-message for block %d" , ch . support . ChainID () , ch .lastCutBlock )
276
284
case * ab.KafkaMessage_Regular :
277
285
env := new (cb.Envelope )
278
286
if err := proto .Unmarshal (msg .GetRegular ().Payload , env ); err != nil {
279
287
// This shouldn't happen, it should be filtered at ingress
280
- logger .Critical ( " Unable to unmarshal consumed regular message:" , err )
288
+ logger .Criticalf ( "[channel: %s] Unable to unmarshal consumed regular message:", ch . support . ChainID () , err )
281
289
continue
282
290
}
283
291
batches , committers , ok := ch .support .BlockCutter ().Ordered (env )
284
- logger .Debugf ("Ordering results: batches: %v, ok: %v" , batches , ok )
292
+ logger .Debugf ("[channel: %s] Ordering results: batches: %v, ok: %v" , ch . support . ChainID () , batches , ok )
285
293
if ok && len (batches ) == 0 && timer == nil {
286
294
timer = time .After (ch .batchTimeout )
287
- logger .Debugf ("Just began %s batch timer" , ch .batchTimeout .String ())
295
+ logger .Debugf ("[channel: %s] Just began %s batch timer" , ch . support . ChainID () , ch .batchTimeout .String ())
288
296
continue
289
297
}
290
298
// If !ok, batches == nil, so this will be skipped
@@ -293,21 +301,21 @@ func (ch *chainImpl) loop() {
293
301
encodedLastOffsetPersisted = utils .MarshalOrPanic (& ab.KafkaMetadata {LastOffsetPersisted : in .Offset })
294
302
ch .support .WriteBlock (block , committers [i ], encodedLastOffsetPersisted )
295
303
ch .lastCutBlock ++
296
- logger .Debug ( " Batch filled, just cut block" , ch .lastCutBlock )
304
+ logger .Debugf ( "[channel: %s] Batch filled, just cut block %d" , ch . support . ChainID () , ch .lastCutBlock )
297
305
}
298
306
if len (batches ) > 0 {
299
307
timer = nil
300
308
}
301
309
}
302
310
case <- timer :
303
- logger .Debugf ("Time-to-cut block %d timer expired" , ch .lastCutBlock + 1 )
311
+ logger .Debugf ("[channel: %s] Time-to-cut block %d timer expired" , ch . support . ChainID () , ch .lastCutBlock + 1 )
304
312
timer = nil
305
313
if err := ch .producer .Send (ch .partition , utils .MarshalOrPanic (newTimeToCutMessage (ch .lastCutBlock + 1 ))); err != nil {
306
- logger .Errorf ("Couldn't post to %s : %s" , ch .partition , err )
314
+ logger .Errorf ("[channel: %s] Cannot post time-to-cut message : %s" , ch .support . ChainID () , err )
307
315
// Do not exit
308
316
}
309
317
case <- ch .exitChan : // When Halt() is called
310
- logger .Infof ("Consenter for chain %s exiting" , ch .partition . Topic ())
318
+ logger .Infof ("[channel: %s] Consenter for channel exiting" , ch .support . ChainID ())
311
319
return
312
320
}
313
321
}
0 commit comments