4646import org .apache .hadoop .ozone .protocolPB .OzoneManagerRequestHandler ;
4747import org .apache .hadoop .ozone .protocolPB .RequestHandler ;
4848import org .apache .hadoop .security .UserGroupInformation ;
49+ import org .apache .hadoop .util .Time ;
4950import org .apache .hadoop .util .concurrent .HadoopExecutors ;
5051import org .apache .ratis .proto .RaftProtos ;
5152import org .apache .ratis .proto .RaftProtos .StateMachineLogEntryProto ;
@@ -88,7 +89,6 @@ public class OzoneManagerStateMachine extends BaseStateMachine {
8889 new SimpleStateMachineStorage ();
8990 private final OzoneManager ozoneManager ;
9091 private RequestHandler handler ;
91- private RaftGroupId raftGroupId ;
9292 private volatile OzoneManagerDoubleBuffer ozoneManagerDoubleBuffer ;
9393 private final ExecutorService executorService ;
9494 private final ExecutorService installSnapshotExecutor ;
@@ -134,17 +134,18 @@ public void initialize(RaftServer server, RaftGroupId id,
134134 RaftStorage raftStorage ) throws IOException {
135135 getLifeCycle ().startAndTransition (() -> {
136136 super .initialize (server , id , raftStorage );
137- this .raftGroupId = id ;
138137 storage .init (raftStorage );
138+ LOG .info ("{}: initialize {} with {}" , getId (), id , getLastAppliedTermIndex ());
139139 });
140140 }
141141
142142 @ Override
143143 public synchronized void reinitialize () throws IOException {
144144 loadSnapshotInfoFromDB ();
145145 if (getLifeCycleState () == LifeCycle .State .PAUSED ) {
146- unpause (getLastAppliedTermIndex ().getIndex (),
147- getLastAppliedTermIndex ().getTerm ());
146+ final TermIndex lastApplied = getLastAppliedTermIndex ();
147+ unpause (lastApplied .getIndex (), lastApplied .getTerm ());
148+ LOG .info ("{}: reinitialize {} with {}" , getId (), getGroupId (), lastApplied );
148149 }
149150 }
150151
@@ -160,6 +161,7 @@ public void notifyLeaderChanged(RaftGroupMemberId groupMemberId,
160161 RaftPeerId newLeaderId ) {
161162 // Initialize OMHAMetrics
162163 ozoneManager .omHAMetricsInit (newLeaderId .toString ());
164+ LOG .info ("{}: leader changed to {}" , groupMemberId , newLeaderId );
163165 }
164166
165167 /** Notified by Ratis for non-StateMachine term-index update. */
@@ -263,7 +265,7 @@ public TransactionContext startTransaction(
263265 messageContent );
264266
265267 Preconditions .checkArgument (raftClientRequest .getRaftGroupId ().equals (
266- raftGroupId ));
268+ getGroupId () ));
267269 try {
268270 handler .validateRequest (omRequest );
269271 } catch (IOException ioe ) {
@@ -293,6 +295,10 @@ public TransactionContext preAppendTransaction(TransactionContext trx)
293295
294296 OzoneManagerPrepareState prepareState = ozoneManager .getPrepareState ();
295297
298+ if (LOG .isDebugEnabled ()) {
299+ LOG .debug ("{}: preAppendTransaction {}" , getId (), TermIndex .valueOf (trx .getLogEntry ()));
300+ }
301+
296302 if (cmdType == OzoneManagerProtocolProtos .Type .Prepare ) {
297303 // Must authenticate prepare requests here, since we must determine
298304 // whether or not to apply the prepare gate before proceeding with the
@@ -303,8 +309,7 @@ public TransactionContext preAppendTransaction(TransactionContext trx)
303309 if (ozoneManager .getAclsEnabled ()
304310 && !ozoneManager .isAdmin (userGroupInformation )) {
305311 String message = "Access denied for user " + userGroupInformation
306- + ". "
307- + "Superuser privilege is required to prepare ozone managers." ;
312+ + ". Superuser privilege is required to prepare upgrade/downgrade." ;
308313 OMException cause =
309314 new OMException (message , OMException .ResultCodes .ACCESS_DENIED );
310315 // Leader should not step down because of this failure.
@@ -341,6 +346,7 @@ public CompletableFuture<Message> applyTransaction(TransactionContext trx) {
341346 : OMRatisHelper .convertByteStringToOMRequest (
342347 trx .getStateMachineLogEntry ().getLogData ());
343348 final TermIndex termIndex = TermIndex .valueOf (trx .getLogEntry ());
349+ LOG .debug ("{}: applyTransaction {}" , getId (), termIndex );
344350 // In the current approach we have one single global thread executor.
345351 // with single thread. Right now this is being done for correctness, as
346352 // applyTransaction will be run on multiple OM's we want to execute the
@@ -427,12 +433,14 @@ public synchronized void pause() {
427433 */
428434 public synchronized void unpause (long newLastAppliedSnaphsotIndex ,
429435 long newLastAppliedSnapShotTermIndex ) {
430- LOG .info ("OzoneManagerStateMachine is un-pausing" );
431436 if (statePausedCount .decrementAndGet () == 0 ) {
432437 getLifeCycle ().startAndTransition (() -> {
433438 this .ozoneManagerDoubleBuffer = buildDoubleBufferForRatis ();
434439 this .setLastAppliedTermIndex (TermIndex .valueOf (
435440 newLastAppliedSnapShotTermIndex , newLastAppliedSnaphsotIndex ));
441+ LOG .info ("{}: OzoneManagerStateMachine un-pause completed. " +
442+ "newLastAppliedSnaphsotIndex: {}, newLastAppliedSnapShotTermIndex: {}" ,
443+ getId (), newLastAppliedSnaphsotIndex , newLastAppliedSnapShotTermIndex );
436444 });
437445 }
438446 }
@@ -482,15 +490,15 @@ private synchronized long takeSnapshotImpl() throws IOException {
482490 final TermIndex applied = getLastAppliedTermIndex ();
483491 final TermIndex notified = getLastNotifiedTermIndex ();
484492 final TermIndex snapshot = applied .compareTo (notified ) > 0 ? applied : notified ;
485- LOG .info (" applied = {}" , applied );
486- LOG .info (" skipped = {}" , lastSkippedIndex );
487- LOG .info ("notified = {}" , notified );
488- LOG .info ("snapshot = {}" , snapshot );
489493
494+ long startTime = Time .monotonicNow ();
490495 final TransactionInfo transactionInfo = TransactionInfo .valueOf (snapshot );
491496 ozoneManager .setTransactionInfo (transactionInfo );
492497 ozoneManager .getMetadataManager ().getTransactionInfoTable ().put (TRANSACTION_INFO_KEY , transactionInfo );
493498 ozoneManager .getMetadataManager ().getStore ().flushDB ();
499+ LOG .info ("{}: taking snapshot. applied = {}, skipped = {}, " +
500+ "notified = {}, current snapshot index = {}, took {} ms" ,
501+ getId (), applied , lastSkippedIndex , notified , snapshot , Time .monotonicNow () - startTime );
494502 return snapshot .getIndex ();
495503 }
496504
0 commit comments