You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "vldpyatkov (via GitHub)" <gi...@apache.org> on 2024/02/02 11:55:05 UTC

Re: [PR] IGNITE-21247 Log enhancements for LeaseUpdater [ignite-3]

vldpyatkov commented on code in PR #3109:
URL: https://github.com/apache/ignite-3/pull/3109#discussion_r1475858283


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -286,6 +288,13 @@ public void run() {
                     if (active()) {
                         updateLeaseBatchInternal();
                     }
+                } catch (Throwable e) {
+                    LOG.error("Error occurred when updating the leases.", e);

Review Comment:
   Move it after the handling Error.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -1282,6 +1287,29 @@ private CompletableFuture<Void> createTableLocally(
         return createPartsFut.thenApply(ignore -> null);
     }
 
+    private static String assignmentListToString(List<Set<Assignment>> assignments) {

Review Comment:
   Java doc.



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -461,6 +492,99 @@ private boolean isLeaseOutdated(Lease lease) {
         }
     }
 
+    private static class LeaseUpdateStatistics {
+        static final int PRINT_ONCE_PER_ITERATIONS = 10;
+
+        /** This field should be accessed only from updater thread. */
+        private int statisticsLogCounter;
+
+        /** This field is iteration-local and should be accessed only from updater thread. */
+        private LeaseUpdateStatisticsParameters iteration = new LeaseUpdateStatisticsParameters(0, 0, 0);
+
+        private final LeaseUpdateStatisticsParameters total = new LeaseUpdateStatisticsParameters(0, 0, 0);
+
+        /**
+         * Should be called only from the updater thread.
+         */
+        private void onLeaseCreate() {
+            iteration.leasesCreated++;
+        }
+
+        /**
+         * Should be called only from the updater thread.
+         */
+        private void onLeasePublish() {
+            iteration.leasesPublished++;
+        }
+
+        /**
+         * Should be called only from the updater thread.
+         */
+        private void onLeaseProlong() {
+            iteration.leasesProlonged++;
+        }
+
+        /**
+         * Should be called only from the updater thread.
+         */
+        private LeaseUpdateStatisticsParameters leasesUpdatedInCurrentIteration() {
+            return new LeaseUpdateStatisticsParameters(iteration.leasesCreated, iteration.leasesPublished, iteration.leasesProlonged);
+        }
+
+        /**
+         * Should be called only from the updater thread.
+         */
+        private boolean shouldLogLeaseStatistics() {
+            boolean result = ++statisticsLogCounter > PRINT_ONCE_PER_ITERATIONS;
+
+            if (result) {
+                statisticsLogCounter = 0;
+            }
+
+            return result;
+        }
+
+        /**
+         * Should be called only from the updater thread.
+         */
+        private void onNewIteration() {
+            iteration = new LeaseUpdateStatisticsParameters(0, 0, 0);
+        }
+
+        /**
+         * Updates the total count of updated leases after the successful update.
+         *
+         * @param iterationParameters Leases updated in current iteration.
+         * @return Updated value of total updated leases.
+         */
+        private synchronized LeaseUpdateStatisticsParameters onSuccessfulIteration(LeaseUpdateStatisticsParameters iterationParameters) {
+            total.leasesCreated += iterationParameters.leasesCreated;
+            total.leasesPublished += iterationParameters.leasesPublished;
+            total.leasesProlonged += iterationParameters.leasesProlonged;
+
+            return total;
+        }
+    }
+
+    private static class LeaseUpdateStatisticsParameters {
+        long leasesCreated;
+        long leasesPublished;
+        long leasesProlonged;
+
+        public LeaseUpdateStatisticsParameters(long leasesCreated, long leasesPublished, long leasesProlonged) {
+            this.leasesCreated = leasesCreated;
+            this.leasesPublished = leasesPublished;
+            this.leasesProlonged = leasesProlonged;
+        }
+
+        @Override
+        public String toString() {
+            return "[leasesCreated=" + leasesCreated
+                    + ", leasesPublished=" + leasesPublished
+                    + ", leasesProlonged=" + leasesProlonged + ']';

Review Comment:
   S.toString is a better way to do this.



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -387,6 +403,15 @@ private void updateLeaseBatchInternal() {
                     return;
                 }
 
+                LeaseUpdateStatisticsParameters totalLeases = leaseUpdateStatistics.onSuccessfulIteration(leasesUpdatedInCurrentIteration);
+
+                if (shouldLogLeaseStatistics) {
+                    LOG.info("Leases updated (printed once per " + LeaseUpdateStatistics.PRINT_ONCE_PER_ITERATIONS + " iterations): ["
+                            + "currentIteration=" + leasesUpdatedInCurrentIteration
+                            + ", total=" + totalLeases
+                            + ", currentAssignmentsSize=" + currentAssignmentsSize + "]");
+                }

Review Comment:
   I'd rather insert this printinc logik into the lease statistic object.
   Also, this statistic should have functionality to disable it.



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/LeaseUpdater.java:
##########
@@ -387,6 +403,15 @@ private void updateLeaseBatchInternal() {
                     return;
                 }
 
+                LeaseUpdateStatisticsParameters totalLeases = leaseUpdateStatistics.onSuccessfulIteration(leasesUpdatedInCurrentIteration);
+
+                if (shouldLogLeaseStatistics) {
+                    LOG.info("Leases updated (printed once per " + LeaseUpdateStatistics.PRINT_ONCE_PER_ITERATIONS + " iterations): ["

Review Comment:
   Avoid concut strings in loggers because it has an effective parametrazed method.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org