Project

General

Profile

7323-JMX.patch

Radu Apetrii, 07/04/2023 05:08 AM

Download (8.8 KB)

View differences:

new/src/com/goldencode/p2j/jmx/FwdJMX.java 2023-07-04 08:51:39 +0000
27 27
**     OM  20230112 Added finer-granulation instrumentation for processing of dynamic queries. 
28 28
** 004 RAA 20230302 Removed OrmRedo and OrmNoUndoTrace.
29 29
** 005 GBB 20230512 Logging methods replaced by CentralLogger/ConversionStatus.
30
** 006 RAA 20230704 Added InsertUpdateValidateTotal and InsertUpdateValidateSuccess.
30 31
*/ 
31 32

  
32 33
/*
......
544 545
   public static enum Counter 
545 546
   implements OptionalCounter
546 547
   {
548
      /** How many Insert/Update statements that contain the VALIDATE keyword are there */
549
      InsertUpdateValidateTotal,
550
      /**
551
       * How many Insert/Update statements that contain the VALIDATE keyword have been executed successfully.
552
       */
553
      InsertUpdateValidateSuccess,
554
      /** How many inserts with VALIDATE were cured after failing the first time. */
555
      InsertValidateCured,
556
      
547 557
      /** Incomning network traffic */
548 558
      NetworkReads,
549 559
      /** Outgoing network traffic */
new/src/com/goldencode/p2j/persist/orm/Persister.java 2023-07-04 08:27:10 +0000
27 27
**                  more straight-forward.
28 28
**     RAA 20230623 Instead of appending "validate" to the insert SQL, insertValidateSql is now used.
29 29
**     RAA 20230704 Changed name of validateMode to allowDBUniqueCheck.
30
**     RAA 20230704 Added JMXs for counting how many Inserts/Updates with VALIDATE are executed.
30 31
*/
31 32

  
32 33
/*
......
88 89
import java.util.*;
89 90
import java.util.logging.*;
90 91
import com.goldencode.cache.*;
92
import com.goldencode.p2j.jmx.*;
91 93
import com.goldencode.p2j.persist.*;
92 94
import com.goldencode.p2j.persist.orm.types.*;
93 95
import com.goldencode.p2j.util.logging.*;
......
112 114
   /** Cache of FQL strings, with or without max results and start offsets, to queries. */
113 115
   private static ExpiryCache<UpdateInfo, UpdateInfo> updateCache = new LRUCache<>(4096);
114 116
   
117
   /** Counter for how many Inserts/Updates with VALIDATE are executed. */
118
   private static final SimpleCounter INSERT_UPDATE_VALIDATE_TOTAL = 
119
            SimpleCounter.getInstance(FwdJMX.Counter.InsertUpdateValidateTotal);
120
   
121
   /** Counter for how many Inserts/Updates with VALIDATE are successfully executed. */
122
   private static final SimpleCounter INSERT_UPDATE_VALIDATE_SUCCESS = 
123
            SimpleCounter.getInstance(FwdJMX.Counter.InsertUpdateValidateSuccess);
124
   
115 125
   /**
116 126
    * Constructor.
117 127
    * 
......
786 796
               LOG.log(Level.FINE, "FWD ORM: " + ps);
787 797
            }
788 798
            
799
            if (allowDBUniqueCheck)
800
            {
801
               INSERT_UPDATE_VALIDATE_TOTAL.update(1);
802
            }
803
            
789 804
            int[] result = new int[1];
790 805
            SQLStatementLogger.getLogger().log(session.getDatabase(), ps,
791 806
                                               () -> result[0] = ps.executeUpdate());
792 807
            updateCount += result[0];
793 808
            
809
            if (allowDBUniqueCheck)
810
            {
811
               INSERT_UPDATE_VALIDATE_SUCCESS.update(1);
812
            }
813
            
794 814
            if (updateCount == 0 && LOG.isLoggable(Level.WARNING))
795 815
            {
796 816
               LOG.log(Level.WARNING,
......
963 983
               }
964 984
               else
965 985
               {
986
                  boolean countValidateJMX = INSERT_UPDATE_VALIDATE_TOTAL.isEnabled()   &&
987
                                             INSERT_UPDATE_VALIDATE_SUCCESS.isEnabled() && 
988
                                             ps.toString().contains("validate");
989
                  
990
                  if (countValidateJMX)
991
                  {
992
                     INSERT_UPDATE_VALIDATE_TOTAL.update(1);
993
                  }
994
                           
966 995
                  // non-batch insert is executed inline here
967 996
                  SQLStatementLogger.getLogger().log(session.getDatabase(), ps, () -> ps.execute());
968 997
                  count++;
998
                  
999
                  if (countValidateJMX)
1000
                  {
1001
                     INSERT_UPDATE_VALIDATE_SUCCESS.update(1);
1002
                  }
969 1003
               }
970 1004
            }
971 1005
            
......
973 1007
            // executes the batches (since the scope of the batch is larger than a single DMO)
974 1008
            if (batch && !bulk)
975 1009
            {
1010
               boolean countValidateJMX = INSERT_UPDATE_VALIDATE_TOTAL.isEnabled()   &&
1011
                                          INSERT_UPDATE_VALIDATE_SUCCESS.isEnabled() && 
1012
                                          ps.toString().contains("validate");
1013
               
1014
               if (countValidateJMX)
1015
               {
1016
                  INSERT_UPDATE_VALIDATE_TOTAL.update(1);
1017
               }
1018
                        
976 1019
               int[] result = new int[1];
977 1020
               SQLStatementLogger.getLogger().log(session.getDatabase(), ps,
978 1021
                                                  () -> result[0] = executeBatch(ps));
979 1022
               count += result[0];
1023
               
1024
               if (countValidateJMX)
1025
               {
1026
                  INSERT_UPDATE_VALIDATE_SUCCESS.update(1);
1027
               }
980 1028
            }
981 1029
            
982 1030
            // [i] was only advanced through first element in the extent series; need to push
new/src/com/goldencode/p2j/persist/orm/Validation.java 2023-07-04 09:07:52 +0000
38 38
** 003 RAA 20230601 Added support for VALIDATE keyword.
39 39
**     RAA 20230619 Split flush function into two for more straight-forward use when dealing with VALIDATE.
40 40
**     RAA 20230704 Changed name of validateMode to allowDBUniqueCheck.
41
**     RAA 20230704 Added JMXs for counting how many Inserts/Updates with VALIDATE are cured.
41 42
*/
42 43

  
43 44
/*
......
99 100
import java.sql.*;
100 101
import java.util.*;
101 102
import com.goldencode.p2j.directory.*;
103
import com.goldencode.p2j.jmx.*;
102 104
import com.goldencode.p2j.persist.*;
103 105
import com.goldencode.p2j.persist.dialect.*;
104 106
import com.goldencode.p2j.persist.orm.types.*;
......
155 157
   /** Flag indicating the record was flushed to the database (either newly inserted or updated) */
156 158
   private boolean flushed = false;
157 159
   
160
   /** Counter for how many Inserts/Updates with VALIDATE are executed. */
161
   private static final SimpleCounter INSERT_VALIDATE_CURED = 
162
            SimpleCounter.getInstance(FwdJMX.Counter.InsertValidateCured);
163
   
158 164
   /**
159 165
    * The maximum permitted size for all combined fields of an index. By default this
160 166
    * is equal to Progress version 10.x limit of 1971 bytes.
......
442 448
         if ((multiplex != null || !flush) && !allowDBUniqueCheck)
443 449
         {
444 450
            // validate by executing unique index queries
445
            validateUniqueByQuery(check);
451
            validateUniqueByQuery(check, false);
446 452
         }
447 453
         
448 454
         if (willFlush)
......
644 650
            {
645 651
               // if the right index is found, this method will not return normally, instead it will
646 652
               // throw a specific exception
647
               validateUniqueByQuery(null);
653
               validateUniqueByQuery(null, allowDBUniqueCheck);
648 654
               break;
649 655
            }
650 656
            
......
1061 1067
    * @param   check
1062 1068
    *          A bit set whose set bits represent the positions of the unique indices in the DMO's array
1063 1069
    *          of unique indices to be checked. If {@code null}, check all the unique indices.
1070
    * @param   allowDBUniqueCheck
1071
    *          Flag that marks whether the database is capable of doing the index validation itself, meaning
1072
    *          that server-side validation can be skipped.
1064 1073
    * 
1065 1074
    * @throws  ValidationException
1066 1075
    *          when the method detects a collision of current DMO with another record stored in the database.
1067 1076
    * @throws  PersistenceException
1068 1077
    *          if an error occurred while accessing the database.
1069 1078
    */
1070
   private void validateUniqueByQuery(BitSet check)
1079
   private void validateUniqueByQuery(BitSet check, boolean allowDBUniqueCheck)
1071 1080
   throws PersistenceException,
1072 1081
          ValidationException
1073 1082
   {
......
1136 1145
            {
1137 1146
               throw new ValidationException(getFailUniqueIndexMessage(uIndex, bufferName, dmo), 132);
1138 1147
            }
1148
            else if (allowDBUniqueCheck)
1149
            {
1150
               INSERT_VALIDATE_CURED.update(1);
1151
            }
1139 1152
            
1140 1153
            // if we exit the loop normally, all violations are cured by in-memory changes (which may yet
1141 1154
            // have to be validated and flushed themselves)