sijie commented on a change in pull request #873: Issue280: Add StateManager to 
manage Bookie's state, and use it to turn bookie into readonly when 
sortedLedgerStorage failed to flush data
URL: https://github.com/apache/bookkeeper/pull/873#discussion_r158923166
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStateManager.java
 ##########
 @@ -61,15 +67,47 @@
     private final String bookieId;
     private ShutdownHandler shutdownHandler;
     private RegistrationManager registrationManager;
+    // Expose Stats
+    private final StatsLogger statsLogger;
 
 
-    public BookieStateManager(ServerConfiguration conf, RegistrationManager 
registrationManager,
-                              LedgerDirsManager ledgerDirsManager) throws 
IOException {
+    public BookieStateManager(ServerConfiguration conf, StatsLogger 
statsLogger,
+           RegistrationManager registrationManager, LedgerDirsManager 
ledgerDirsManager) throws IOException {
         this.conf = conf;
+        this.statsLogger = statsLogger;
         this.registrationManager = registrationManager;
         this.ledgerDirsManager = ledgerDirsManager;
         // ZK ephemeral node for this Bookie.
         this.bookieId = getMyId();
+        // 1 : up, 0 : readonly, -1 : unregistered
+        statsLogger.registerGauge(SERVER_STATUS, new Gauge<Number>() {
+            @Override
+            public Number getDefaultValue() {
+                return 0;
+            }
+
+            @Override
+            public Number getSample() {
+                if (!rmRegistered.get()){
+                    return -1;
+                } else if (forceReadOnly.get() || 
bookieStatus.isInReadOnlyMode()) {
+                    return 0;
+                } else {
+                    return 1;
+                }
+            }
+        });
+    }
+
+    @VisibleForTesting
+    BookieStateManager(ServerConfiguration conf, RegistrationManager 
registrationManager) throws IOException {
+        this.conf = conf;
+        this.registrationManager = registrationManager;
+        this.statsLogger = null;
 
 Review comment:
   use NullStatsLogger.INSTANCE rather than plain `null`
   
   Also I think this constructor use this other constructor
   
   ```
   this(conf, NullStatsLogger.INSTANCE, registrationManager, new 
LedgerDirsManager(...));
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to